@graphql-codegen/visitor-plugin-common 7.0.0-alpha-20251125123407-8babe46fb9b33e9f9a377cd50c9580282e7981d3 → 7.0.0-alpha-20251224115303-e89fc4c4d8e4b40f40bea6315bd68b4573109f50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/base-documents-visitor.js +8 -0
- package/cjs/base-types-visitor.js +23 -39
- package/cjs/graphql-type-utils.js +15 -0
- package/cjs/imports.js +54 -0
- package/cjs/index.js +1 -0
- package/cjs/selection-set-processor/pre-resolve-types.js +9 -5
- package/cjs/selection-set-to-object.js +11 -4
- package/esm/base-documents-visitor.js +8 -0
- package/esm/base-types-visitor.js +23 -39
- package/esm/graphql-type-utils.js +11 -0
- package/esm/imports.js +52 -0
- package/esm/index.js +1 -0
- package/esm/selection-set-processor/pre-resolve-types.js +11 -7
- package/esm/selection-set-to-object.js +11 -4
- package/package.json +1 -1
- package/typings/base-documents-visitor.d.cts +49 -1
- package/typings/base-documents-visitor.d.ts +49 -1
- package/typings/base-types-visitor.d.cts +0 -2
- package/typings/base-types-visitor.d.ts +0 -2
- package/typings/convert-schema-enum-to-declaration-block-string.d.cts +1 -2
- package/typings/convert-schema-enum-to-declaration-block-string.d.ts +1 -2
- package/typings/graphql-type-utils.d.cts +2 -0
- package/typings/graphql-type-utils.d.ts +2 -0
- package/typings/imports.d.cts +11 -0
- package/typings/imports.d.ts +11 -0
- package/typings/index.d.cts +1 -0
- package/typings/index.d.ts +1 -0
- package/typings/selection-set-processor/base.d.cts +5 -3
- package/typings/selection-set-processor/base.d.ts +5 -3
- package/typings/selection-set-to-object.d.cts +4 -4
- package/typings/selection-set-to-object.d.ts +4 -4
|
@@ -41,6 +41,8 @@ class BaseDocumentsVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
41
41
|
operationResultSuffix: (0, utils_js_1.getConfigValue)(rawConfig.operationResultSuffix, ''),
|
|
42
42
|
scalars: (0, utils_js_1.buildScalarsFromConfig)(_schema, rawConfig, defaultScalars),
|
|
43
43
|
customDirectives: (0, utils_js_1.getConfigValue)(rawConfig.customDirectives, { apolloUnmask: false }),
|
|
44
|
+
generatesOperationTypes: (0, utils_js_1.getConfigValue)(rawConfig.generatesOperationTypes, true),
|
|
45
|
+
importSchemaTypesFrom: (0, utils_js_1.getConfigValue)(rawConfig.importSchemaTypesFrom, ''),
|
|
44
46
|
...(additionalConfig || {}),
|
|
45
47
|
});
|
|
46
48
|
this._schema = _schema;
|
|
@@ -81,6 +83,9 @@ class BaseDocumentsVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
81
83
|
});
|
|
82
84
|
}
|
|
83
85
|
FragmentDefinition(node) {
|
|
86
|
+
if (!this.config.generatesOperationTypes) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
84
89
|
const fragmentRootType = this._schema.getType(node.typeCondition.name.value);
|
|
85
90
|
const selectionSet = this._selectionSetToObject.createNext(fragmentRootType, node.selectionSet);
|
|
86
91
|
const fragmentSuffix = this.getFragmentSuffix(node);
|
|
@@ -106,6 +111,9 @@ class BaseDocumentsVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
106
111
|
return variablesBlock;
|
|
107
112
|
}
|
|
108
113
|
OperationDefinition(node) {
|
|
114
|
+
if (!this.config.generatesOperationTypes) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
109
117
|
const name = this.handleAnonymousOperation(node);
|
|
110
118
|
const operationRootType = getRootType(node.operation, this._schema);
|
|
111
119
|
if (!operationRootType) {
|
|
@@ -10,6 +10,7 @@ const scalars_js_1 = require("./scalars.js");
|
|
|
10
10
|
const utils_js_1 = require("./utils.js");
|
|
11
11
|
const variables_to_object_js_1 = require("./variables-to-object.js");
|
|
12
12
|
const convert_schema_enum_to_declaration_block_string_js_1 = require("./convert-schema-enum-to-declaration-block-string.js");
|
|
13
|
+
const imports_js_1 = require("./imports.js");
|
|
13
14
|
class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
14
15
|
_schema;
|
|
15
16
|
_argumentsTransformer;
|
|
@@ -58,10 +59,20 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
58
59
|
return Object.keys(this.config.scalars).reduce((res, enumName) => {
|
|
59
60
|
const mappedValue = this.config.scalars[enumName];
|
|
60
61
|
if (mappedValue.input.isExternal) {
|
|
61
|
-
res.push(
|
|
62
|
+
res.push((0, imports_js_1.buildTypeImport)({
|
|
63
|
+
identifier: mappedValue.input.import,
|
|
64
|
+
source: mappedValue.input.source,
|
|
65
|
+
asDefault: mappedValue.input.default,
|
|
66
|
+
useTypeImports: this.config.useTypeImports,
|
|
67
|
+
}));
|
|
62
68
|
}
|
|
63
69
|
if (mappedValue.output.isExternal) {
|
|
64
|
-
res.push(
|
|
70
|
+
res.push((0, imports_js_1.buildTypeImport)({
|
|
71
|
+
identifier: mappedValue.output.import,
|
|
72
|
+
source: mappedValue.output.source,
|
|
73
|
+
asDefault: mappedValue.output.default,
|
|
74
|
+
useTypeImports: this.config.useTypeImports,
|
|
75
|
+
}));
|
|
65
76
|
}
|
|
66
77
|
return res;
|
|
67
78
|
}, []);
|
|
@@ -71,7 +82,12 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
71
82
|
.map(directive => {
|
|
72
83
|
const mappedValue = this.config.directiveArgumentAndInputFieldMappings[directive];
|
|
73
84
|
if (mappedValue.isExternal) {
|
|
74
|
-
return
|
|
85
|
+
return (0, imports_js_1.buildTypeImport)({
|
|
86
|
+
identifier: mappedValue.import,
|
|
87
|
+
source: mappedValue.source,
|
|
88
|
+
asDefault: mappedValue.default,
|
|
89
|
+
useTypeImports: this.config.useTypeImports,
|
|
90
|
+
});
|
|
75
91
|
}
|
|
76
92
|
return null;
|
|
77
93
|
})
|
|
@@ -252,43 +268,11 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
252
268
|
// We empty this because we handle scalars in a different way, see constructor.
|
|
253
269
|
return '';
|
|
254
270
|
}
|
|
255
|
-
_buildTypeImport(identifier, source, asDefault = false) {
|
|
256
|
-
const { useTypeImports } = this.config;
|
|
257
|
-
if (asDefault) {
|
|
258
|
-
if (useTypeImports) {
|
|
259
|
-
return `import type { default as ${identifier} } from '${source}';`;
|
|
260
|
-
}
|
|
261
|
-
return `import ${identifier} from '${source}';`;
|
|
262
|
-
}
|
|
263
|
-
return `import${useTypeImports ? ' type' : ''} { ${identifier} } from '${source}';`;
|
|
264
|
-
}
|
|
265
|
-
handleEnumValueMapper(typeIdentifier, importIdentifier, sourceIdentifier, sourceFile) {
|
|
266
|
-
if (importIdentifier !== sourceIdentifier) {
|
|
267
|
-
// use namespace import to dereference nested enum
|
|
268
|
-
// { enumValues: { MyEnum: './my-file#NS.NestedEnum' } }
|
|
269
|
-
return [
|
|
270
|
-
this._buildTypeImport(importIdentifier || sourceIdentifier, sourceFile),
|
|
271
|
-
`import ${typeIdentifier} = ${sourceIdentifier};`,
|
|
272
|
-
];
|
|
273
|
-
}
|
|
274
|
-
if (sourceIdentifier !== typeIdentifier) {
|
|
275
|
-
return [this._buildTypeImport(`${sourceIdentifier} as ${typeIdentifier}`, sourceFile)];
|
|
276
|
-
}
|
|
277
|
-
return [this._buildTypeImport(importIdentifier || sourceIdentifier, sourceFile)];
|
|
278
|
-
}
|
|
279
271
|
getEnumsImports() {
|
|
280
|
-
return
|
|
281
|
-
.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (mappedValue.isDefault) {
|
|
285
|
-
return [this._buildTypeImport(mappedValue.typeIdentifier, mappedValue.sourceFile, true)];
|
|
286
|
-
}
|
|
287
|
-
return this.handleEnumValueMapper(mappedValue.typeIdentifier, mappedValue.importIdentifier, mappedValue.sourceIdentifier, mappedValue.sourceFile);
|
|
288
|
-
}
|
|
289
|
-
return [];
|
|
290
|
-
})
|
|
291
|
-
.filter(Boolean);
|
|
272
|
+
return (0, imports_js_1.getEnumsImports)({
|
|
273
|
+
enumValues: this.config.enumValues,
|
|
274
|
+
useTypeImports: this.config.useTypeImports,
|
|
275
|
+
});
|
|
292
276
|
}
|
|
293
277
|
EnumTypeDefinition(node) {
|
|
294
278
|
const enumName = node.name.value;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNativeNamedType = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const isNativeNamedType = (namedType) => {
|
|
6
|
+
// "Native" NamedType in this context means the following:
|
|
7
|
+
// 1. introspection types i.e. with `__` prefixes
|
|
8
|
+
// 2. base scalars e.g. Boolean, Int, etc.
|
|
9
|
+
// 3. Other natives (mostly base scalars) which was not defined in the schema i.e. no `astNode`
|
|
10
|
+
if ((0, graphql_1.isSpecifiedScalarType)(namedType) || (0, graphql_1.isIntrospectionType)(namedType) || !namedType.astNode) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
};
|
|
15
|
+
exports.isNativeNamedType = isNativeNamedType;
|
package/cjs/imports.js
CHANGED
|
@@ -6,6 +6,8 @@ exports.resolveRelativeImport = resolveRelativeImport;
|
|
|
6
6
|
exports.resolveImportSource = resolveImportSource;
|
|
7
7
|
exports.clearExtension = clearExtension;
|
|
8
8
|
exports.fixLocalFilePath = fixLocalFilePath;
|
|
9
|
+
exports.getEnumsImports = getEnumsImports;
|
|
10
|
+
exports.buildTypeImport = buildTypeImport;
|
|
9
11
|
const tslib_1 = require("tslib");
|
|
10
12
|
const path_1 = require("path");
|
|
11
13
|
const parse_filepath_1 = tslib_1.__importDefault(require("parse-filepath"));
|
|
@@ -65,3 +67,55 @@ function clearExtension(path) {
|
|
|
65
67
|
function fixLocalFilePath(path) {
|
|
66
68
|
return path.startsWith('..') ? path : `./${path}`;
|
|
67
69
|
}
|
|
70
|
+
function getEnumsImports({ enumValues, useTypeImports, }) {
|
|
71
|
+
function handleEnumValueMapper({ typeIdentifier, importIdentifier, sourceIdentifier, sourceFile, useTypeImports, }) {
|
|
72
|
+
if (importIdentifier !== sourceIdentifier) {
|
|
73
|
+
// use namespace import to dereference nested enum
|
|
74
|
+
// { enumValues: { MyEnum: './my-file#NS.NestedEnum' } }
|
|
75
|
+
return [
|
|
76
|
+
buildTypeImport({ identifier: importIdentifier || sourceIdentifier, source: sourceFile, useTypeImports }),
|
|
77
|
+
`import ${typeIdentifier} = ${sourceIdentifier};`,
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
if (sourceIdentifier !== typeIdentifier) {
|
|
81
|
+
return [
|
|
82
|
+
buildTypeImport({ identifier: `${sourceIdentifier} as ${typeIdentifier}`, source: sourceFile, useTypeImports }),
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
return [buildTypeImport({ identifier: importIdentifier || sourceIdentifier, source: sourceFile, useTypeImports })];
|
|
86
|
+
}
|
|
87
|
+
return Object.keys(enumValues)
|
|
88
|
+
.flatMap(enumName => {
|
|
89
|
+
const mappedValue = enumValues[enumName];
|
|
90
|
+
if (mappedValue.sourceFile) {
|
|
91
|
+
if (mappedValue.isDefault) {
|
|
92
|
+
return [
|
|
93
|
+
buildTypeImport({
|
|
94
|
+
identifier: mappedValue.typeIdentifier,
|
|
95
|
+
source: mappedValue.sourceFile,
|
|
96
|
+
asDefault: true,
|
|
97
|
+
useTypeImports,
|
|
98
|
+
}),
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
return handleEnumValueMapper({
|
|
102
|
+
typeIdentifier: mappedValue.typeIdentifier,
|
|
103
|
+
importIdentifier: mappedValue.importIdentifier,
|
|
104
|
+
sourceIdentifier: mappedValue.sourceIdentifier,
|
|
105
|
+
sourceFile: mappedValue.sourceFile,
|
|
106
|
+
useTypeImports,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return [];
|
|
110
|
+
})
|
|
111
|
+
.filter(Boolean);
|
|
112
|
+
}
|
|
113
|
+
function buildTypeImport({ identifier, source, useTypeImports, asDefault = false, }) {
|
|
114
|
+
if (asDefault) {
|
|
115
|
+
if (useTypeImports) {
|
|
116
|
+
return `import type { default as ${identifier} } from '${source}';`;
|
|
117
|
+
}
|
|
118
|
+
return `import ${identifier} from '${source}';`;
|
|
119
|
+
}
|
|
120
|
+
return `import${useTypeImports ? ' type' : ''} { ${identifier} } from '${source}';`;
|
|
121
|
+
}
|
package/cjs/index.js
CHANGED
|
@@ -21,3 +21,4 @@ tslib_1.__exportStar(require("./types.js"), exports);
|
|
|
21
21
|
tslib_1.__exportStar(require("./utils.js"), exports);
|
|
22
22
|
tslib_1.__exportStar(require("./variables-to-object.js"), exports);
|
|
23
23
|
tslib_1.__exportStar(require("./convert-schema-enum-to-declaration-block-string.js"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./graphql-type-utils.js"), exports);
|
|
@@ -21,9 +21,10 @@ class PreResolveTypesProcessor extends base_js_1.BaseSelectionSetProcessor {
|
|
|
21
21
|
const fieldObj = schemaType.getFields()[field.fieldName];
|
|
22
22
|
const baseType = (0, plugin_helpers_1.getBaseType)(fieldObj.type);
|
|
23
23
|
let typeToUse = baseType.name;
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const name = this.config.formatNamedField({
|
|
25
|
+
name: field.fieldName,
|
|
26
|
+
isOptional: field.isConditional || unsetTypes,
|
|
27
|
+
});
|
|
27
28
|
if (unsetTypes) {
|
|
28
29
|
return {
|
|
29
30
|
name,
|
|
@@ -54,7 +55,7 @@ class PreResolveTypesProcessor extends base_js_1.BaseSelectionSetProcessor {
|
|
|
54
55
|
}
|
|
55
56
|
return fields.map(aliasedField => {
|
|
56
57
|
if (aliasedField.fieldName === '__typename') {
|
|
57
|
-
const name = this.config.formatNamedField(aliasedField.alias
|
|
58
|
+
const name = this.config.formatNamedField({ name: aliasedField.alias });
|
|
58
59
|
return {
|
|
59
60
|
name,
|
|
60
61
|
type: `'${schemaType.name}'`,
|
|
@@ -71,7 +72,10 @@ class PreResolveTypesProcessor extends base_js_1.BaseSelectionSetProcessor {
|
|
|
71
72
|
useTypesSuffix: this.config.enumSuffix,
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
|
-
const name = this.config.formatNamedField(
|
|
75
|
+
const name = this.config.formatNamedField({
|
|
76
|
+
name: aliasedField.alias,
|
|
77
|
+
isOptional: aliasedField.isConditional || unsetTypes,
|
|
78
|
+
});
|
|
75
79
|
if (unsetTypes) {
|
|
76
80
|
return {
|
|
77
81
|
type: 'never',
|
|
@@ -266,6 +266,7 @@ class SelectionSetToObject {
|
|
|
266
266
|
mustAddEmptyObject = true;
|
|
267
267
|
}
|
|
268
268
|
for (const incrementalNode of incrementalNodes) {
|
|
269
|
+
// 1. fragment masking
|
|
269
270
|
if (this._config.inlineFragmentTypes === 'mask' && 'fragmentName' in incrementalNode) {
|
|
270
271
|
const { fields: incrementalFields, dependentTypes: incrementalDependentTypes } = this.buildSelectionSet(schemaType, [incrementalNode], { unsetTypes: true, parentFieldName: parentName });
|
|
271
272
|
const incrementalSet = this.selectionSetStringFromFields(incrementalFields);
|
|
@@ -273,6 +274,7 @@ class SelectionSetToObject {
|
|
|
273
274
|
dependentTypes.push(...incrementalDependentTypes);
|
|
274
275
|
continue;
|
|
275
276
|
}
|
|
277
|
+
// 2. @defer
|
|
276
278
|
const { fields: initialFields, dependentTypes: initialDependentTypes } = this.buildSelectionSet(schemaType, [incrementalNode], { parentFieldName: parentName });
|
|
277
279
|
const { fields: subsequentFields, dependentTypes: subsequentDependentTypes } = this.buildSelectionSet(schemaType, [incrementalNode], { unsetTypes: true, parentFieldName: parentName });
|
|
278
280
|
const initialSet = this.selectionSetStringFromFields(initialFields);
|
|
@@ -466,12 +468,17 @@ class SelectionSetToObject {
|
|
|
466
468
|
const selectionSetObjects = selectionSet.transformSelectionSet(options.parentFieldName ? `${options.parentFieldName}_${fieldName}` : fieldName);
|
|
467
469
|
linkFieldsInterfaces.push(...selectionSetObjects.dependentTypes);
|
|
468
470
|
const isConditional = (0, utils_js_1.hasConditionalDirectives)(field) || inlineFragmentConditional;
|
|
469
|
-
const isOptional = options.unsetTypes;
|
|
470
471
|
linkFields.push({
|
|
471
472
|
alias: field.alias
|
|
472
|
-
? this._processor.config.formatNamedField(
|
|
473
|
+
? this._processor.config.formatNamedField({
|
|
474
|
+
name: field.alias.value,
|
|
475
|
+
isOptional: isConditional || options.unsetTypes,
|
|
476
|
+
})
|
|
473
477
|
: undefined,
|
|
474
|
-
name: this._processor.config.formatNamedField(
|
|
478
|
+
name: this._processor.config.formatNamedField({
|
|
479
|
+
name: field.name.value,
|
|
480
|
+
isOptional: isConditional || options.unsetTypes,
|
|
481
|
+
}),
|
|
475
482
|
type: realSelectedFieldType.name,
|
|
476
483
|
selectionSet: this._processor.config.wrapTypeWithModifiers(selectionSetObjects.mergedTypeString.split(`\n`).join(`\n `), selectedFieldType),
|
|
477
484
|
});
|
|
@@ -524,7 +531,7 @@ class SelectionSetToObject {
|
|
|
524
531
|
if (nonOptionalTypename || addTypename || queriedForTypename) {
|
|
525
532
|
const optionalTypename = !queriedForTypename && !nonOptionalTypename;
|
|
526
533
|
return {
|
|
527
|
-
name:
|
|
534
|
+
name: this._processor.config.formatNamedField({ name: '__typename', isOptional: optionalTypename }),
|
|
528
535
|
type: `'${type.name}'`,
|
|
529
536
|
};
|
|
530
537
|
}
|
|
@@ -37,6 +37,8 @@ export class BaseDocumentsVisitor extends BaseVisitor {
|
|
|
37
37
|
operationResultSuffix: getConfigValue(rawConfig.operationResultSuffix, ''),
|
|
38
38
|
scalars: buildScalarsFromConfig(_schema, rawConfig, defaultScalars),
|
|
39
39
|
customDirectives: getConfigValue(rawConfig.customDirectives, { apolloUnmask: false }),
|
|
40
|
+
generatesOperationTypes: getConfigValue(rawConfig.generatesOperationTypes, true),
|
|
41
|
+
importSchemaTypesFrom: getConfigValue(rawConfig.importSchemaTypesFrom, ''),
|
|
40
42
|
...(additionalConfig || {}),
|
|
41
43
|
});
|
|
42
44
|
this._schema = _schema;
|
|
@@ -77,6 +79,9 @@ export class BaseDocumentsVisitor extends BaseVisitor {
|
|
|
77
79
|
});
|
|
78
80
|
}
|
|
79
81
|
FragmentDefinition(node) {
|
|
82
|
+
if (!this.config.generatesOperationTypes) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
80
85
|
const fragmentRootType = this._schema.getType(node.typeCondition.name.value);
|
|
81
86
|
const selectionSet = this._selectionSetToObject.createNext(fragmentRootType, node.selectionSet);
|
|
82
87
|
const fragmentSuffix = this.getFragmentSuffix(node);
|
|
@@ -102,6 +107,9 @@ export class BaseDocumentsVisitor extends BaseVisitor {
|
|
|
102
107
|
return variablesBlock;
|
|
103
108
|
}
|
|
104
109
|
OperationDefinition(node) {
|
|
110
|
+
if (!this.config.generatesOperationTypes) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
105
113
|
const name = this.handleAnonymousOperation(node);
|
|
106
114
|
const operationRootType = getRootType(node.operation, this._schema);
|
|
107
115
|
if (!operationRootType) {
|
|
@@ -7,6 +7,7 @@ import { DEFAULT_SCALARS } from './scalars.js';
|
|
|
7
7
|
import { buildScalarsFromConfig, DeclarationBlock, getConfigValue, indent, isOneOfInputObjectType, transformComment, getNodeComment, wrapWithSingleQuotes, } from './utils.js';
|
|
8
8
|
import { OperationVariablesToObject } from './variables-to-object.js';
|
|
9
9
|
import { buildEnumValuesBlock } from './convert-schema-enum-to-declaration-block-string.js';
|
|
10
|
+
import { buildTypeImport, getEnumsImports } from './imports.js';
|
|
10
11
|
export class BaseTypesVisitor extends BaseVisitor {
|
|
11
12
|
_schema;
|
|
12
13
|
_argumentsTransformer;
|
|
@@ -55,10 +56,20 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
55
56
|
return Object.keys(this.config.scalars).reduce((res, enumName) => {
|
|
56
57
|
const mappedValue = this.config.scalars[enumName];
|
|
57
58
|
if (mappedValue.input.isExternal) {
|
|
58
|
-
res.push(
|
|
59
|
+
res.push(buildTypeImport({
|
|
60
|
+
identifier: mappedValue.input.import,
|
|
61
|
+
source: mappedValue.input.source,
|
|
62
|
+
asDefault: mappedValue.input.default,
|
|
63
|
+
useTypeImports: this.config.useTypeImports,
|
|
64
|
+
}));
|
|
59
65
|
}
|
|
60
66
|
if (mappedValue.output.isExternal) {
|
|
61
|
-
res.push(
|
|
67
|
+
res.push(buildTypeImport({
|
|
68
|
+
identifier: mappedValue.output.import,
|
|
69
|
+
source: mappedValue.output.source,
|
|
70
|
+
asDefault: mappedValue.output.default,
|
|
71
|
+
useTypeImports: this.config.useTypeImports,
|
|
72
|
+
}));
|
|
62
73
|
}
|
|
63
74
|
return res;
|
|
64
75
|
}, []);
|
|
@@ -68,7 +79,12 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
68
79
|
.map(directive => {
|
|
69
80
|
const mappedValue = this.config.directiveArgumentAndInputFieldMappings[directive];
|
|
70
81
|
if (mappedValue.isExternal) {
|
|
71
|
-
return
|
|
82
|
+
return buildTypeImport({
|
|
83
|
+
identifier: mappedValue.import,
|
|
84
|
+
source: mappedValue.source,
|
|
85
|
+
asDefault: mappedValue.default,
|
|
86
|
+
useTypeImports: this.config.useTypeImports,
|
|
87
|
+
});
|
|
72
88
|
}
|
|
73
89
|
return null;
|
|
74
90
|
})
|
|
@@ -249,43 +265,11 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
249
265
|
// We empty this because we handle scalars in a different way, see constructor.
|
|
250
266
|
return '';
|
|
251
267
|
}
|
|
252
|
-
_buildTypeImport(identifier, source, asDefault = false) {
|
|
253
|
-
const { useTypeImports } = this.config;
|
|
254
|
-
if (asDefault) {
|
|
255
|
-
if (useTypeImports) {
|
|
256
|
-
return `import type { default as ${identifier} } from '${source}';`;
|
|
257
|
-
}
|
|
258
|
-
return `import ${identifier} from '${source}';`;
|
|
259
|
-
}
|
|
260
|
-
return `import${useTypeImports ? ' type' : ''} { ${identifier} } from '${source}';`;
|
|
261
|
-
}
|
|
262
|
-
handleEnumValueMapper(typeIdentifier, importIdentifier, sourceIdentifier, sourceFile) {
|
|
263
|
-
if (importIdentifier !== sourceIdentifier) {
|
|
264
|
-
// use namespace import to dereference nested enum
|
|
265
|
-
// { enumValues: { MyEnum: './my-file#NS.NestedEnum' } }
|
|
266
|
-
return [
|
|
267
|
-
this._buildTypeImport(importIdentifier || sourceIdentifier, sourceFile),
|
|
268
|
-
`import ${typeIdentifier} = ${sourceIdentifier};`,
|
|
269
|
-
];
|
|
270
|
-
}
|
|
271
|
-
if (sourceIdentifier !== typeIdentifier) {
|
|
272
|
-
return [this._buildTypeImport(`${sourceIdentifier} as ${typeIdentifier}`, sourceFile)];
|
|
273
|
-
}
|
|
274
|
-
return [this._buildTypeImport(importIdentifier || sourceIdentifier, sourceFile)];
|
|
275
|
-
}
|
|
276
268
|
getEnumsImports() {
|
|
277
|
-
return
|
|
278
|
-
.
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (mappedValue.isDefault) {
|
|
282
|
-
return [this._buildTypeImport(mappedValue.typeIdentifier, mappedValue.sourceFile, true)];
|
|
283
|
-
}
|
|
284
|
-
return this.handleEnumValueMapper(mappedValue.typeIdentifier, mappedValue.importIdentifier, mappedValue.sourceIdentifier, mappedValue.sourceFile);
|
|
285
|
-
}
|
|
286
|
-
return [];
|
|
287
|
-
})
|
|
288
|
-
.filter(Boolean);
|
|
269
|
+
return getEnumsImports({
|
|
270
|
+
enumValues: this.config.enumValues,
|
|
271
|
+
useTypeImports: this.config.useTypeImports,
|
|
272
|
+
});
|
|
289
273
|
}
|
|
290
274
|
EnumTypeDefinition(node) {
|
|
291
275
|
const enumName = node.name.value;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isIntrospectionType, isSpecifiedScalarType } from 'graphql';
|
|
2
|
+
export const isNativeNamedType = (namedType) => {
|
|
3
|
+
// "Native" NamedType in this context means the following:
|
|
4
|
+
// 1. introspection types i.e. with `__` prefixes
|
|
5
|
+
// 2. base scalars e.g. Boolean, Int, etc.
|
|
6
|
+
// 3. Other natives (mostly base scalars) which was not defined in the schema i.e. no `astNode`
|
|
7
|
+
if (isSpecifiedScalarType(namedType) || isIntrospectionType(namedType) || !namedType.astNode) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
};
|
package/esm/imports.js
CHANGED
|
@@ -56,3 +56,55 @@ export function clearExtension(path) {
|
|
|
56
56
|
export function fixLocalFilePath(path) {
|
|
57
57
|
return path.startsWith('..') ? path : `./${path}`;
|
|
58
58
|
}
|
|
59
|
+
export function getEnumsImports({ enumValues, useTypeImports, }) {
|
|
60
|
+
function handleEnumValueMapper({ typeIdentifier, importIdentifier, sourceIdentifier, sourceFile, useTypeImports, }) {
|
|
61
|
+
if (importIdentifier !== sourceIdentifier) {
|
|
62
|
+
// use namespace import to dereference nested enum
|
|
63
|
+
// { enumValues: { MyEnum: './my-file#NS.NestedEnum' } }
|
|
64
|
+
return [
|
|
65
|
+
buildTypeImport({ identifier: importIdentifier || sourceIdentifier, source: sourceFile, useTypeImports }),
|
|
66
|
+
`import ${typeIdentifier} = ${sourceIdentifier};`,
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
if (sourceIdentifier !== typeIdentifier) {
|
|
70
|
+
return [
|
|
71
|
+
buildTypeImport({ identifier: `${sourceIdentifier} as ${typeIdentifier}`, source: sourceFile, useTypeImports }),
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
return [buildTypeImport({ identifier: importIdentifier || sourceIdentifier, source: sourceFile, useTypeImports })];
|
|
75
|
+
}
|
|
76
|
+
return Object.keys(enumValues)
|
|
77
|
+
.flatMap(enumName => {
|
|
78
|
+
const mappedValue = enumValues[enumName];
|
|
79
|
+
if (mappedValue.sourceFile) {
|
|
80
|
+
if (mappedValue.isDefault) {
|
|
81
|
+
return [
|
|
82
|
+
buildTypeImport({
|
|
83
|
+
identifier: mappedValue.typeIdentifier,
|
|
84
|
+
source: mappedValue.sourceFile,
|
|
85
|
+
asDefault: true,
|
|
86
|
+
useTypeImports,
|
|
87
|
+
}),
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
return handleEnumValueMapper({
|
|
91
|
+
typeIdentifier: mappedValue.typeIdentifier,
|
|
92
|
+
importIdentifier: mappedValue.importIdentifier,
|
|
93
|
+
sourceIdentifier: mappedValue.sourceIdentifier,
|
|
94
|
+
sourceFile: mappedValue.sourceFile,
|
|
95
|
+
useTypeImports,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return [];
|
|
99
|
+
})
|
|
100
|
+
.filter(Boolean);
|
|
101
|
+
}
|
|
102
|
+
export function buildTypeImport({ identifier, source, useTypeImports, asDefault = false, }) {
|
|
103
|
+
if (asDefault) {
|
|
104
|
+
if (useTypeImports) {
|
|
105
|
+
return `import type { default as ${identifier} } from '${source}';`;
|
|
106
|
+
}
|
|
107
|
+
return `import ${identifier} from '${source}';`;
|
|
108
|
+
}
|
|
109
|
+
return `import${useTypeImports ? ' type' : ''} { ${identifier} } from '${source}';`;
|
|
110
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getBaseType
|
|
2
|
-
import { isEnumType
|
|
1
|
+
import { getBaseType } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { isEnumType } from 'graphql';
|
|
3
3
|
import { BaseSelectionSetProcessor, } from './base.js';
|
|
4
4
|
export class PreResolveTypesProcessor extends BaseSelectionSetProcessor {
|
|
5
5
|
transformTypenameField(type, name) {
|
|
@@ -18,9 +18,10 @@ export class PreResolveTypesProcessor extends BaseSelectionSetProcessor {
|
|
|
18
18
|
const fieldObj = schemaType.getFields()[field.fieldName];
|
|
19
19
|
const baseType = getBaseType(fieldObj.type);
|
|
20
20
|
let typeToUse = baseType.name;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const name = this.config.formatNamedField({
|
|
22
|
+
name: field.fieldName,
|
|
23
|
+
isOptional: field.isConditional || unsetTypes,
|
|
24
|
+
});
|
|
24
25
|
if (unsetTypes) {
|
|
25
26
|
return {
|
|
26
27
|
name,
|
|
@@ -51,7 +52,7 @@ export class PreResolveTypesProcessor extends BaseSelectionSetProcessor {
|
|
|
51
52
|
}
|
|
52
53
|
return fields.map(aliasedField => {
|
|
53
54
|
if (aliasedField.fieldName === '__typename') {
|
|
54
|
-
const name = this.config.formatNamedField(aliasedField.alias
|
|
55
|
+
const name = this.config.formatNamedField({ name: aliasedField.alias });
|
|
55
56
|
return {
|
|
56
57
|
name,
|
|
57
58
|
type: `'${schemaType.name}'`,
|
|
@@ -68,7 +69,10 @@ export class PreResolveTypesProcessor extends BaseSelectionSetProcessor {
|
|
|
68
69
|
useTypesSuffix: this.config.enumSuffix,
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
|
-
const name = this.config.formatNamedField(
|
|
72
|
+
const name = this.config.formatNamedField({
|
|
73
|
+
name: aliasedField.alias,
|
|
74
|
+
isOptional: aliasedField.isConditional || unsetTypes,
|
|
75
|
+
});
|
|
72
76
|
if (unsetTypes) {
|
|
73
77
|
return {
|
|
74
78
|
type: 'never',
|
|
@@ -262,6 +262,7 @@ export class SelectionSetToObject {
|
|
|
262
262
|
mustAddEmptyObject = true;
|
|
263
263
|
}
|
|
264
264
|
for (const incrementalNode of incrementalNodes) {
|
|
265
|
+
// 1. fragment masking
|
|
265
266
|
if (this._config.inlineFragmentTypes === 'mask' && 'fragmentName' in incrementalNode) {
|
|
266
267
|
const { fields: incrementalFields, dependentTypes: incrementalDependentTypes } = this.buildSelectionSet(schemaType, [incrementalNode], { unsetTypes: true, parentFieldName: parentName });
|
|
267
268
|
const incrementalSet = this.selectionSetStringFromFields(incrementalFields);
|
|
@@ -269,6 +270,7 @@ export class SelectionSetToObject {
|
|
|
269
270
|
dependentTypes.push(...incrementalDependentTypes);
|
|
270
271
|
continue;
|
|
271
272
|
}
|
|
273
|
+
// 2. @defer
|
|
272
274
|
const { fields: initialFields, dependentTypes: initialDependentTypes } = this.buildSelectionSet(schemaType, [incrementalNode], { parentFieldName: parentName });
|
|
273
275
|
const { fields: subsequentFields, dependentTypes: subsequentDependentTypes } = this.buildSelectionSet(schemaType, [incrementalNode], { unsetTypes: true, parentFieldName: parentName });
|
|
274
276
|
const initialSet = this.selectionSetStringFromFields(initialFields);
|
|
@@ -462,12 +464,17 @@ export class SelectionSetToObject {
|
|
|
462
464
|
const selectionSetObjects = selectionSet.transformSelectionSet(options.parentFieldName ? `${options.parentFieldName}_${fieldName}` : fieldName);
|
|
463
465
|
linkFieldsInterfaces.push(...selectionSetObjects.dependentTypes);
|
|
464
466
|
const isConditional = hasConditionalDirectives(field) || inlineFragmentConditional;
|
|
465
|
-
const isOptional = options.unsetTypes;
|
|
466
467
|
linkFields.push({
|
|
467
468
|
alias: field.alias
|
|
468
|
-
? this._processor.config.formatNamedField(
|
|
469
|
+
? this._processor.config.formatNamedField({
|
|
470
|
+
name: field.alias.value,
|
|
471
|
+
isOptional: isConditional || options.unsetTypes,
|
|
472
|
+
})
|
|
469
473
|
: undefined,
|
|
470
|
-
name: this._processor.config.formatNamedField(
|
|
474
|
+
name: this._processor.config.formatNamedField({
|
|
475
|
+
name: field.name.value,
|
|
476
|
+
isOptional: isConditional || options.unsetTypes,
|
|
477
|
+
}),
|
|
471
478
|
type: realSelectedFieldType.name,
|
|
472
479
|
selectionSet: this._processor.config.wrapTypeWithModifiers(selectionSetObjects.mergedTypeString.split(`\n`).join(`\n `), selectedFieldType),
|
|
473
480
|
});
|
|
@@ -520,7 +527,7 @@ export class SelectionSetToObject {
|
|
|
520
527
|
if (nonOptionalTypename || addTypename || queriedForTypename) {
|
|
521
528
|
const optionalTypename = !queriedForTypename && !nonOptionalTypename;
|
|
522
529
|
return {
|
|
523
|
-
name:
|
|
530
|
+
name: this._processor.config.formatNamedField({ name: '__typename', isOptional: optionalTypename }),
|
|
524
531
|
type: `'${type.name}'`,
|
|
525
532
|
};
|
|
526
533
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/visitor-plugin-common",
|
|
3
|
-
"version": "7.0.0-alpha-
|
|
3
|
+
"version": "7.0.0-alpha-20251224115303-e89fc4c4d8e4b40f40bea6315bd68b4573109f50",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
6
6
|
},
|
|
@@ -19,6 +19,8 @@ export interface ParsedDocumentsConfig extends ParsedTypesConfig {
|
|
|
19
19
|
experimentalFragmentVariables: boolean;
|
|
20
20
|
mergeFragmentTypes: boolean;
|
|
21
21
|
customDirectives: CustomDirectivesConfig;
|
|
22
|
+
generatesOperationTypes: boolean;
|
|
23
|
+
importSchemaTypesFrom: string;
|
|
22
24
|
}
|
|
23
25
|
export interface RawDocumentsConfig extends RawTypesConfig {
|
|
24
26
|
/**
|
|
@@ -149,6 +151,52 @@ export interface RawDocumentsConfig extends RawTypesConfig {
|
|
|
149
151
|
* ```
|
|
150
152
|
*/
|
|
151
153
|
customDirectives?: CustomDirectivesConfig;
|
|
154
|
+
/**
|
|
155
|
+
* @description Whether to generate operation types such as Variables, Query/Mutation/Subscription selection set, and Fragment types
|
|
156
|
+
* This can be used with `importSchemaTypesFrom` to generate shared used Enums and Input.
|
|
157
|
+
* @default true
|
|
158
|
+
* @exampleMarkdown
|
|
159
|
+
* ```ts filename="codegen.ts"
|
|
160
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
161
|
+
*
|
|
162
|
+
* const config: CodegenConfig = {
|
|
163
|
+
* // ...
|
|
164
|
+
* generates: {
|
|
165
|
+
* 'path/to/file.ts': {
|
|
166
|
+
* plugins: ['typescript-operations'],
|
|
167
|
+
* config: {
|
|
168
|
+
* generatesOperationTypes: false,
|
|
169
|
+
* },
|
|
170
|
+
* },
|
|
171
|
+
* },
|
|
172
|
+
* };
|
|
173
|
+
* export default config;
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
generatesOperationTypes?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* @description The absolute (prefixed with `~`) or relative path from `cwd` to the shared used Enums and Input (See `generatesOperationTypes`).
|
|
179
|
+
* @default true
|
|
180
|
+
* @exampleMarkdown
|
|
181
|
+
* ```ts filename="codegen.ts"
|
|
182
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
183
|
+
*
|
|
184
|
+
* const config: CodegenConfig = {
|
|
185
|
+
* // ...
|
|
186
|
+
* generates: {
|
|
187
|
+
* 'path/to/file.ts': {
|
|
188
|
+
* plugins: ['typescript-operations'],
|
|
189
|
+
* config: {
|
|
190
|
+
* importSchemaTypesFrom: './path/to/shared-types.ts', // relative
|
|
191
|
+
* importSchemaTypesFrom: '~@my-org/package' // absolute
|
|
192
|
+
* },
|
|
193
|
+
* },
|
|
194
|
+
* },
|
|
195
|
+
* };
|
|
196
|
+
* export default config;
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
importSchemaTypesFrom?: string;
|
|
152
200
|
}
|
|
153
201
|
export declare class BaseDocumentsVisitor<TRawConfig extends RawDocumentsConfig = RawDocumentsConfig, TPluginConfig extends ParsedDocumentsConfig = ParsedDocumentsConfig> extends BaseVisitor<TRawConfig, TPluginConfig> {
|
|
154
202
|
protected _schema: GraphQLSchema;
|
|
@@ -166,5 +214,5 @@ export declare class BaseDocumentsVisitor<TRawConfig extends RawDocumentsConfig
|
|
|
166
214
|
private handleAnonymousOperation;
|
|
167
215
|
FragmentDefinition(node: FragmentDefinitionNode): string;
|
|
168
216
|
protected applyVariablesWrapper(variablesBlock: string, _operationType?: string): string;
|
|
169
|
-
OperationDefinition(node: OperationDefinitionNode): string;
|
|
217
|
+
OperationDefinition(node: OperationDefinitionNode): string | null;
|
|
170
218
|
}
|
|
@@ -19,6 +19,8 @@ export interface ParsedDocumentsConfig extends ParsedTypesConfig {
|
|
|
19
19
|
experimentalFragmentVariables: boolean;
|
|
20
20
|
mergeFragmentTypes: boolean;
|
|
21
21
|
customDirectives: CustomDirectivesConfig;
|
|
22
|
+
generatesOperationTypes: boolean;
|
|
23
|
+
importSchemaTypesFrom: string;
|
|
22
24
|
}
|
|
23
25
|
export interface RawDocumentsConfig extends RawTypesConfig {
|
|
24
26
|
/**
|
|
@@ -149,6 +151,52 @@ export interface RawDocumentsConfig extends RawTypesConfig {
|
|
|
149
151
|
* ```
|
|
150
152
|
*/
|
|
151
153
|
customDirectives?: CustomDirectivesConfig;
|
|
154
|
+
/**
|
|
155
|
+
* @description Whether to generate operation types such as Variables, Query/Mutation/Subscription selection set, and Fragment types
|
|
156
|
+
* This can be used with `importSchemaTypesFrom` to generate shared used Enums and Input.
|
|
157
|
+
* @default true
|
|
158
|
+
* @exampleMarkdown
|
|
159
|
+
* ```ts filename="codegen.ts"
|
|
160
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
161
|
+
*
|
|
162
|
+
* const config: CodegenConfig = {
|
|
163
|
+
* // ...
|
|
164
|
+
* generates: {
|
|
165
|
+
* 'path/to/file.ts': {
|
|
166
|
+
* plugins: ['typescript-operations'],
|
|
167
|
+
* config: {
|
|
168
|
+
* generatesOperationTypes: false,
|
|
169
|
+
* },
|
|
170
|
+
* },
|
|
171
|
+
* },
|
|
172
|
+
* };
|
|
173
|
+
* export default config;
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
generatesOperationTypes?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* @description The absolute (prefixed with `~`) or relative path from `cwd` to the shared used Enums and Input (See `generatesOperationTypes`).
|
|
179
|
+
* @default true
|
|
180
|
+
* @exampleMarkdown
|
|
181
|
+
* ```ts filename="codegen.ts"
|
|
182
|
+
* import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
183
|
+
*
|
|
184
|
+
* const config: CodegenConfig = {
|
|
185
|
+
* // ...
|
|
186
|
+
* generates: {
|
|
187
|
+
* 'path/to/file.ts': {
|
|
188
|
+
* plugins: ['typescript-operations'],
|
|
189
|
+
* config: {
|
|
190
|
+
* importSchemaTypesFrom: './path/to/shared-types.ts', // relative
|
|
191
|
+
* importSchemaTypesFrom: '~@my-org/package' // absolute
|
|
192
|
+
* },
|
|
193
|
+
* },
|
|
194
|
+
* },
|
|
195
|
+
* };
|
|
196
|
+
* export default config;
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
importSchemaTypesFrom?: string;
|
|
152
200
|
}
|
|
153
201
|
export declare class BaseDocumentsVisitor<TRawConfig extends RawDocumentsConfig = RawDocumentsConfig, TPluginConfig extends ParsedDocumentsConfig = ParsedDocumentsConfig> extends BaseVisitor<TRawConfig, TPluginConfig> {
|
|
154
202
|
protected _schema: GraphQLSchema;
|
|
@@ -166,5 +214,5 @@ export declare class BaseDocumentsVisitor<TRawConfig extends RawDocumentsConfig
|
|
|
166
214
|
private handleAnonymousOperation;
|
|
167
215
|
FragmentDefinition(node: FragmentDefinitionNode): string;
|
|
168
216
|
protected applyVariablesWrapper(variablesBlock: string, _operationType?: string): string;
|
|
169
|
-
OperationDefinition(node: OperationDefinitionNode): string;
|
|
217
|
+
OperationDefinition(node: OperationDefinitionNode): string | null;
|
|
170
218
|
}
|
|
@@ -478,8 +478,6 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
|
|
|
478
478
|
getInterfaceTypeDeclarationBlock(node: InterfaceTypeDefinitionNode, _originalNode: InterfaceTypeDefinitionNode): DeclarationBlock;
|
|
479
479
|
InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode, key: number | string, parent: any): string;
|
|
480
480
|
ScalarTypeDefinition(_node: ScalarTypeDefinitionNode): string;
|
|
481
|
-
protected _buildTypeImport(identifier: string, source: string, asDefault?: boolean): string;
|
|
482
|
-
protected handleEnumValueMapper(typeIdentifier: string, importIdentifier: string | null, sourceIdentifier: string | null, sourceFile: string | null): string[];
|
|
483
481
|
getEnumsImports(): string[];
|
|
484
482
|
EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
|
|
485
483
|
protected makeValidEnumIdentifier(identifier: string): string;
|
|
@@ -478,8 +478,6 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
|
|
|
478
478
|
getInterfaceTypeDeclarationBlock(node: InterfaceTypeDefinitionNode, _originalNode: InterfaceTypeDefinitionNode): DeclarationBlock;
|
|
479
479
|
InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode, key: number | string, parent: any): string;
|
|
480
480
|
ScalarTypeDefinition(_node: ScalarTypeDefinitionNode): string;
|
|
481
|
-
protected _buildTypeImport(identifier: string, source: string, asDefault?: boolean): string;
|
|
482
|
-
protected handleEnumValueMapper(typeIdentifier: string, importIdentifier: string | null, sourceIdentifier: string | null, sourceFile: string | null): string[];
|
|
483
481
|
getEnumsImports(): string[];
|
|
484
482
|
EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
|
|
485
483
|
protected makeValidEnumIdentifier(identifier: string): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EnumTypeDefinitionNode, EnumValueDefinitionNode, GraphQLSchema } from 'graphql';
|
|
2
2
|
import type { ConvertFn, ParsedEnumValuesMap } from './types.cjs';
|
|
3
3
|
import { type DeclarationBlockConfig } from './utils.cjs';
|
|
4
|
-
interface ConvertSchemaEnumToDeclarationBlockString {
|
|
4
|
+
export interface ConvertSchemaEnumToDeclarationBlockString {
|
|
5
5
|
schema: GraphQLSchema;
|
|
6
6
|
node: EnumTypeDefinitionNode;
|
|
7
7
|
enumName: string;
|
|
@@ -23,4 +23,3 @@ export declare const buildEnumValuesBlock: ({ typeName, values, schema, naming,
|
|
|
23
23
|
typeName: string;
|
|
24
24
|
values: ReadonlyArray<EnumValueDefinitionNode>;
|
|
25
25
|
}) => string;
|
|
26
|
-
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EnumTypeDefinitionNode, EnumValueDefinitionNode, GraphQLSchema } from 'graphql';
|
|
2
2
|
import type { ConvertFn, ParsedEnumValuesMap } from './types.js';
|
|
3
3
|
import { type DeclarationBlockConfig } from './utils.js';
|
|
4
|
-
interface ConvertSchemaEnumToDeclarationBlockString {
|
|
4
|
+
export interface ConvertSchemaEnumToDeclarationBlockString {
|
|
5
5
|
schema: GraphQLSchema;
|
|
6
6
|
node: EnumTypeDefinitionNode;
|
|
7
7
|
enumName: string;
|
|
@@ -23,4 +23,3 @@ export declare const buildEnumValuesBlock: ({ typeName, values, schema, naming,
|
|
|
23
23
|
typeName: string;
|
|
24
24
|
values: ReadonlyArray<EnumValueDefinitionNode>;
|
|
25
25
|
}) => string;
|
|
26
|
-
export {};
|
package/typings/imports.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ParsedEnumValuesMap } from './types';
|
|
1
2
|
export type ImportDeclaration<T = string> = {
|
|
2
3
|
outputPath: string;
|
|
3
4
|
importSource: ImportSource<T>;
|
|
@@ -30,3 +31,13 @@ export declare function resolveRelativeImport(from: string, to: string): string;
|
|
|
30
31
|
export declare function resolveImportSource<T>(source: string | ImportSource<T>): ImportSource<T>;
|
|
31
32
|
export declare function clearExtension(path: string): string;
|
|
32
33
|
export declare function fixLocalFilePath(path: string): string;
|
|
34
|
+
export declare function getEnumsImports({ enumValues, useTypeImports, }: {
|
|
35
|
+
enumValues: ParsedEnumValuesMap;
|
|
36
|
+
useTypeImports: boolean;
|
|
37
|
+
}): string[];
|
|
38
|
+
export declare function buildTypeImport({ identifier, source, useTypeImports, asDefault, }: {
|
|
39
|
+
identifier: string;
|
|
40
|
+
source: string;
|
|
41
|
+
useTypeImports: boolean;
|
|
42
|
+
asDefault?: boolean;
|
|
43
|
+
}): string;
|
package/typings/imports.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ParsedEnumValuesMap } from './types';
|
|
1
2
|
export type ImportDeclaration<T = string> = {
|
|
2
3
|
outputPath: string;
|
|
3
4
|
importSource: ImportSource<T>;
|
|
@@ -30,3 +31,13 @@ export declare function resolveRelativeImport(from: string, to: string): string;
|
|
|
30
31
|
export declare function resolveImportSource<T>(source: string | ImportSource<T>): ImportSource<T>;
|
|
31
32
|
export declare function clearExtension(path: string): string;
|
|
32
33
|
export declare function fixLocalFilePath(path: string): string;
|
|
34
|
+
export declare function getEnumsImports({ enumValues, useTypeImports, }: {
|
|
35
|
+
enumValues: ParsedEnumValuesMap;
|
|
36
|
+
useTypeImports: boolean;
|
|
37
|
+
}): string[];
|
|
38
|
+
export declare function buildTypeImport({ identifier, source, useTypeImports, asDefault, }: {
|
|
39
|
+
identifier: string;
|
|
40
|
+
source: string;
|
|
41
|
+
useTypeImports: boolean;
|
|
42
|
+
asDefault?: boolean;
|
|
43
|
+
}): string;
|
package/typings/index.d.cts
CHANGED
package/typings/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLInterfaceType, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, Location } from 'graphql';
|
|
2
|
-
import {
|
|
2
|
+
import { ConvertNameFn, NormalizedScalarsMap } from '../types.cjs';
|
|
3
3
|
export type PrimitiveField = {
|
|
4
4
|
isConditional: boolean;
|
|
5
5
|
fieldName: string;
|
|
@@ -26,9 +26,11 @@ export type SelectionSetProcessorConfig = {
|
|
|
26
26
|
enumPrefix: boolean | null;
|
|
27
27
|
enumSuffix: boolean | null;
|
|
28
28
|
scalars: NormalizedScalarsMap;
|
|
29
|
-
formatNamedField(
|
|
29
|
+
formatNamedField(params: {
|
|
30
|
+
name: string;
|
|
31
|
+
isOptional?: boolean;
|
|
32
|
+
}): string;
|
|
30
33
|
wrapTypeWithModifiers(baseType: string, type: GraphQLOutputType | GraphQLNamedType): string;
|
|
31
|
-
avoidOptionals?: AvoidOptionalsConfig | boolean;
|
|
32
34
|
printFieldsOnNewLines?: boolean;
|
|
33
35
|
};
|
|
34
36
|
export declare class BaseSelectionSetProcessor<Config extends SelectionSetProcessorConfig> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLInterfaceType, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, Location } from 'graphql';
|
|
2
|
-
import {
|
|
2
|
+
import { ConvertNameFn, NormalizedScalarsMap } from '../types.js';
|
|
3
3
|
export type PrimitiveField = {
|
|
4
4
|
isConditional: boolean;
|
|
5
5
|
fieldName: string;
|
|
@@ -26,9 +26,11 @@ export type SelectionSetProcessorConfig = {
|
|
|
26
26
|
enumPrefix: boolean | null;
|
|
27
27
|
enumSuffix: boolean | null;
|
|
28
28
|
scalars: NormalizedScalarsMap;
|
|
29
|
-
formatNamedField(
|
|
29
|
+
formatNamedField(params: {
|
|
30
|
+
name: string;
|
|
31
|
+
isOptional?: boolean;
|
|
32
|
+
}): string;
|
|
30
33
|
wrapTypeWithModifiers(baseType: string, type: GraphQLOutputType | GraphQLNamedType): string;
|
|
31
|
-
avoidOptionals?: AvoidOptionalsConfig | boolean;
|
|
32
34
|
printFieldsOnNewLines?: boolean;
|
|
33
35
|
};
|
|
34
36
|
export declare class BaseSelectionSetProcessor<Config extends SelectionSetProcessorConfig> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DirectiveNode, FieldNode, FragmentSpreadNode, GraphQLNamedType, GraphQLObjectType, GraphQLSchema, InlineFragmentNode, SelectionNode, SelectionSetNode } from 'graphql';
|
|
2
2
|
import { ParsedDocumentsConfig } from './base-documents-visitor.cjs';
|
|
3
3
|
import { BaseVisitorConvertOptions } from './base-visitor.cjs';
|
|
4
|
-
import { BaseSelectionSetProcessor, LinkField, NameAndType, PrimitiveAliasedFields, PrimitiveField } from './selection-set-processor/base.cjs';
|
|
4
|
+
import { BaseSelectionSetProcessor, LinkField, NameAndType, PrimitiveAliasedFields, PrimitiveField, type SelectionSetProcessorConfig as BaseSelectionSetProcessorConfig } from './selection-set-processor/base.cjs';
|
|
5
5
|
import { ConvertNameFn, FragmentDirectives, GetFragmentSuffixFn, LoadedFragment, NormalizedScalarsMap } from './types.cjs';
|
|
6
6
|
import { DeclarationBlockConfig } from './utils.cjs';
|
|
7
7
|
type FragmentSpreadUsage = {
|
|
@@ -20,8 +20,8 @@ type CollectedFragmentNode = (SelectionNode | FragmentSpreadUsage | DirectiveNod
|
|
|
20
20
|
type GroupedStringifiedTypes = Record<string, Array<string | {
|
|
21
21
|
union: string[];
|
|
22
22
|
}>>;
|
|
23
|
-
export declare class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedDocumentsConfig> {
|
|
24
|
-
protected _processor: BaseSelectionSetProcessor<
|
|
23
|
+
export declare class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedDocumentsConfig, SelectionSetProcessorConfig extends BaseSelectionSetProcessorConfig = BaseSelectionSetProcessorConfig> {
|
|
24
|
+
protected _processor: BaseSelectionSetProcessor<SelectionSetProcessorConfig>;
|
|
25
25
|
protected _scalars: NormalizedScalarsMap;
|
|
26
26
|
protected _schema: GraphQLSchema;
|
|
27
27
|
protected _convertName: ConvertNameFn<BaseVisitorConvertOptions>;
|
|
@@ -34,7 +34,7 @@ export declare class SelectionSetToObject<Config extends ParsedDocumentsConfig =
|
|
|
34
34
|
protected _primitiveAliasedFields: PrimitiveAliasedFields[];
|
|
35
35
|
protected _linksFields: LinkField[];
|
|
36
36
|
protected _queriedForTypename: boolean;
|
|
37
|
-
constructor(_processor: BaseSelectionSetProcessor<
|
|
37
|
+
constructor(_processor: BaseSelectionSetProcessor<SelectionSetProcessorConfig>, _scalars: NormalizedScalarsMap, _schema: GraphQLSchema, _convertName: ConvertNameFn<BaseVisitorConvertOptions>, _getFragmentSuffix: GetFragmentSuffixFn, _loadedFragments: LoadedFragment[], _config: Config, _parentSchemaType?: GraphQLNamedType, _selectionSet?: SelectionSetNode);
|
|
38
38
|
createNext(parentSchemaType: GraphQLNamedType, selectionSet: SelectionSetNode): SelectionSetToObject;
|
|
39
39
|
/**
|
|
40
40
|
* traverse the inline fragment nodes recursively for collecting the selectionSets on each type
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DirectiveNode, FieldNode, FragmentSpreadNode, GraphQLNamedType, GraphQLObjectType, GraphQLSchema, InlineFragmentNode, SelectionNode, SelectionSetNode } from 'graphql';
|
|
2
2
|
import { ParsedDocumentsConfig } from './base-documents-visitor.js';
|
|
3
3
|
import { BaseVisitorConvertOptions } from './base-visitor.js';
|
|
4
|
-
import { BaseSelectionSetProcessor, LinkField, NameAndType, PrimitiveAliasedFields, PrimitiveField } from './selection-set-processor/base.js';
|
|
4
|
+
import { BaseSelectionSetProcessor, LinkField, NameAndType, PrimitiveAliasedFields, PrimitiveField, type SelectionSetProcessorConfig as BaseSelectionSetProcessorConfig } from './selection-set-processor/base.js';
|
|
5
5
|
import { ConvertNameFn, FragmentDirectives, GetFragmentSuffixFn, LoadedFragment, NormalizedScalarsMap } from './types.js';
|
|
6
6
|
import { DeclarationBlockConfig } from './utils.js';
|
|
7
7
|
type FragmentSpreadUsage = {
|
|
@@ -20,8 +20,8 @@ type CollectedFragmentNode = (SelectionNode | FragmentSpreadUsage | DirectiveNod
|
|
|
20
20
|
type GroupedStringifiedTypes = Record<string, Array<string | {
|
|
21
21
|
union: string[];
|
|
22
22
|
}>>;
|
|
23
|
-
export declare class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedDocumentsConfig> {
|
|
24
|
-
protected _processor: BaseSelectionSetProcessor<
|
|
23
|
+
export declare class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedDocumentsConfig, SelectionSetProcessorConfig extends BaseSelectionSetProcessorConfig = BaseSelectionSetProcessorConfig> {
|
|
24
|
+
protected _processor: BaseSelectionSetProcessor<SelectionSetProcessorConfig>;
|
|
25
25
|
protected _scalars: NormalizedScalarsMap;
|
|
26
26
|
protected _schema: GraphQLSchema;
|
|
27
27
|
protected _convertName: ConvertNameFn<BaseVisitorConvertOptions>;
|
|
@@ -34,7 +34,7 @@ export declare class SelectionSetToObject<Config extends ParsedDocumentsConfig =
|
|
|
34
34
|
protected _primitiveAliasedFields: PrimitiveAliasedFields[];
|
|
35
35
|
protected _linksFields: LinkField[];
|
|
36
36
|
protected _queriedForTypename: boolean;
|
|
37
|
-
constructor(_processor: BaseSelectionSetProcessor<
|
|
37
|
+
constructor(_processor: BaseSelectionSetProcessor<SelectionSetProcessorConfig>, _scalars: NormalizedScalarsMap, _schema: GraphQLSchema, _convertName: ConvertNameFn<BaseVisitorConvertOptions>, _getFragmentSuffix: GetFragmentSuffixFn, _loadedFragments: LoadedFragment[], _config: Config, _parentSchemaType?: GraphQLNamedType, _selectionSet?: SelectionSetNode);
|
|
38
38
|
createNext(parentSchemaType: GraphQLNamedType, selectionSet: SelectionSetNode): SelectionSetToObject;
|
|
39
39
|
/**
|
|
40
40
|
* traverse the inline fragment nodes recursively for collecting the selectionSets on each type
|