@graphql-codegen/visitor-plugin-common 7.2.8 → 7.2.9-alpha-20261005221753-a02bbddf0d367784d8a6c5f54bf7092266c814e0
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-types-visitor.js +16 -12
- package/cjs/convert-schema-enum-to-declaration-block-string.js +15 -10
- package/cjs/imports.js +4 -1
- package/cjs/mappers.js +1 -1
- package/cjs/naming.js +6 -5
- package/cjs/optimize-operations.js +6 -1
- package/cjs/utils.js +11 -7
- package/cjs/variables-to-object.js +3 -2
- package/esm/base-types-visitor.js +16 -12
- package/esm/convert-schema-enum-to-declaration-block-string.js +15 -10
- package/esm/imports.js +4 -1
- package/esm/mappers.js +1 -1
- package/esm/naming.js +6 -5
- package/esm/optimize-operations.js +6 -1
- package/esm/utils.js +11 -7
- package/esm/variables-to-object.js +3 -2
- package/package.json +1 -1
- package/typings/base-types-visitor.d.cts +1 -1
- package/typings/base-types-visitor.d.ts +1 -1
- package/typings/convert-schema-enum-to-declaration-block-string.d.cts +1 -1
- package/typings/convert-schema-enum-to-declaration-block-string.d.ts +1 -1
- package/typings/imports.d.cts +2 -2
- package/typings/imports.d.ts +2 -2
- package/typings/mappers.d.cts +1 -1
- package/typings/mappers.d.ts +1 -1
- package/typings/selection-set-processor/base.d.cts +1 -1
- package/typings/selection-set-processor/base.d.ts +1 -1
- package/typings/types.d.cts +4 -4
- package/typings/types.d.ts +4 -4
- package/typings/utils.d.cts +11 -11
- package/typings/utils.d.ts +11 -11
- package/typings/variables-to-object.d.cts +2 -2
- package/typings/variables-to-object.d.ts +2 -2
|
@@ -100,7 +100,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
100
100
|
}
|
|
101
101
|
return null;
|
|
102
102
|
})
|
|
103
|
-
.filter(a => a);
|
|
103
|
+
.filter((a) => !!a);
|
|
104
104
|
}
|
|
105
105
|
get scalarsDefinition() {
|
|
106
106
|
if (this.config.onlyEnums)
|
|
@@ -160,18 +160,19 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
160
160
|
.asKind(this._parsedConfig.declarationKind.input)
|
|
161
161
|
.withName(this.convertName(node))
|
|
162
162
|
.withComment(node.description?.value)
|
|
163
|
-
.withBlock(node.fields.join('\n'));
|
|
163
|
+
.withBlock((node.fields || []).join('\n'));
|
|
164
164
|
}
|
|
165
165
|
getInputObjectOneOfDeclarationBlock(node) {
|
|
166
|
+
const fields = node.fields || [];
|
|
166
167
|
return new utils_js_1.DeclarationBlock(this._declarationBlockConfig)
|
|
167
168
|
.export()
|
|
168
169
|
.asKind((0, utils_js_1.getOneOfInputDeclarationKind)({
|
|
169
|
-
fieldCount:
|
|
170
|
+
fieldCount: fields.length,
|
|
170
171
|
inputDeclarationKind: this._parsedConfig.declarationKind.input,
|
|
171
172
|
}))
|
|
172
173
|
.withName(this.convertName(node))
|
|
173
174
|
.withComment(node.description?.value)
|
|
174
|
-
.withContent(`\n` +
|
|
175
|
+
.withContent(`\n` + fields.join('\n |'));
|
|
175
176
|
}
|
|
176
177
|
InputObjectTypeDefinition(node) {
|
|
177
178
|
if (this.config.onlyEnums)
|
|
@@ -184,8 +185,9 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
184
185
|
InputValueDefinition(node, _key, _parent, _path, _ancestors) {
|
|
185
186
|
if (this.config.onlyEnums)
|
|
186
187
|
return '';
|
|
187
|
-
const comment = (0, utils_js_1.transformComment)(node.description
|
|
188
|
+
const comment = (0, utils_js_1.transformComment)(node.description?.value, 1);
|
|
188
189
|
const { input } = this._parsedConfig.declarationKind;
|
|
190
|
+
// `node.type` is already printed to a string by the visitor; removing the cast needs a visited-AST type for `node`
|
|
189
191
|
let type = node.type;
|
|
190
192
|
if (node.directives && this.config.directiveArgumentAndInputFieldMappings) {
|
|
191
193
|
type = this._getDirectiveOverrideType(node.directives) || type;
|
|
@@ -203,15 +205,16 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
203
205
|
UnionTypeDefinition(node, key, parent) {
|
|
204
206
|
if (this.config.onlyOperationTypes || this.config.onlyEnums)
|
|
205
207
|
return '';
|
|
208
|
+
// `node.types` are already printed strings, so the original AST node is read from `parent[key]`, and `parent` is `any` because oldVisit's parent is untyped
|
|
206
209
|
const originalNode = parent[key];
|
|
207
|
-
const possibleTypes = originalNode.types
|
|
210
|
+
const possibleTypes = (originalNode.types || [])
|
|
208
211
|
.map(t => this.scalars[t.name.value] ? this._getScalar(t.name.value, 'output') : this.convertName(t))
|
|
209
212
|
.join(' | ');
|
|
210
213
|
return new utils_js_1.DeclarationBlock(this._declarationBlockConfig)
|
|
211
214
|
.export()
|
|
212
215
|
.asKind('type')
|
|
213
216
|
.withName(this.convertName(node))
|
|
214
|
-
.withComment(node.description
|
|
217
|
+
.withComment(node.description?.value)
|
|
215
218
|
.withContent(possibleTypes).string;
|
|
216
219
|
}
|
|
217
220
|
mergeInterfaces(interfaces, hasOtherFields) {
|
|
@@ -224,13 +227,14 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
224
227
|
getObjectTypeDeclarationBlock(node, originalNode) {
|
|
225
228
|
const optionalTypename = this.config.nonOptionalTypename ? '__typename' : '__typename?';
|
|
226
229
|
const { type, interface: interfacesType } = this._parsedConfig.declarationKind;
|
|
230
|
+
// `node.fields` are already printed to strings by the visitor; dropping `as string[]` needs a visited-AST type for `node`
|
|
227
231
|
const allFields = [
|
|
228
232
|
...(this.config.addTypename
|
|
229
233
|
? [
|
|
230
234
|
(0, utils_js_1.indent)(`${this.config.immutableTypes ? 'readonly ' : ''}${optionalTypename}: '${node.name.value}'${this.getPunctuation(type)}`),
|
|
231
235
|
]
|
|
232
236
|
: []),
|
|
233
|
-
...node.fields,
|
|
237
|
+
...(node.fields || []),
|
|
234
238
|
];
|
|
235
239
|
const interfacesNames = originalNode.interfaces
|
|
236
240
|
? originalNode.interfaces.map(i => this.convertName(i))
|
|
@@ -272,7 +276,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
272
276
|
.asKind(this._parsedConfig.declarationKind.interface)
|
|
273
277
|
.withName(this.convertName(node))
|
|
274
278
|
.withComment(node.description?.value);
|
|
275
|
-
return declarationBlock.withBlock(node.fields.join('\n'));
|
|
279
|
+
return declarationBlock.withBlock((node.fields || []).join('\n'));
|
|
276
280
|
}
|
|
277
281
|
InterfaceTypeDefinition(node, key, parent) {
|
|
278
282
|
if (this.config.onlyOperationTypes || this.config.onlyEnums)
|
|
@@ -308,10 +312,10 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
308
312
|
useTypesPrefix: this.config.enumPrefix,
|
|
309
313
|
useTypesSuffix: this.config.enumSuffix,
|
|
310
314
|
}))
|
|
311
|
-
.withComment(node.description
|
|
315
|
+
.withComment(node.description?.value)
|
|
312
316
|
.withBlock((0, convert_schema_enum_to_declaration_block_string_js_1.buildEnumValuesBlock)({
|
|
313
317
|
typeName: enumName,
|
|
314
|
-
values: node.values,
|
|
318
|
+
values: node.values || [],
|
|
315
319
|
schema: this._schema,
|
|
316
320
|
naming: {
|
|
317
321
|
convert: this.config.convert,
|
|
@@ -350,7 +354,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
350
354
|
return this.getArgumentsObjectDeclarationBlock(node, name, field).string;
|
|
351
355
|
}
|
|
352
356
|
buildArgumentsBlock(node) {
|
|
353
|
-
const fieldsWithArguments = node.fields
|
|
357
|
+
const fieldsWithArguments = node.fields?.filter(field => field.arguments && field.arguments.length > 0) || [];
|
|
354
358
|
return fieldsWithArguments
|
|
355
359
|
.map(field => {
|
|
356
360
|
const name = node.name.value +
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildEnumValuesBlock = exports.convertSchemaEnumToDeclarationBlockString = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
4
5
|
const naming_js_1 = require("./naming.js");
|
|
5
6
|
const utils_js_1 = require("./utils.js");
|
|
6
7
|
const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumName, enumValues, futureProofEnums, ignoreEnumValuesFromSchema, outputType, declarationBlockConfig, naming, }) => {
|
|
@@ -27,7 +28,7 @@ const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumName, enu
|
|
|
27
28
|
.withComment(node.description?.value)
|
|
28
29
|
.withName(enumTypeName)
|
|
29
30
|
.withContent('\n' +
|
|
30
|
-
node.values
|
|
31
|
+
(node.values || [])
|
|
31
32
|
.map(enumOption => {
|
|
32
33
|
const name = enumOption.name.value;
|
|
33
34
|
const enumValue = getValueFromConfig(name) ?? name;
|
|
@@ -43,7 +44,7 @@ const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumName, enu
|
|
|
43
44
|
.withComment(node.description?.value)
|
|
44
45
|
.withName(enumTypeName)
|
|
45
46
|
.asKind('enum')
|
|
46
|
-
.withBlock(node.values
|
|
47
|
+
.withBlock((node.values || [])
|
|
47
48
|
.map((enumOption, i) => {
|
|
48
49
|
const valueFromConfig = getValueFromConfig(enumOption.name.value);
|
|
49
50
|
const enumValue = valueFromConfig ?? i;
|
|
@@ -73,7 +74,7 @@ const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumName, enu
|
|
|
73
74
|
.asKind('const')
|
|
74
75
|
.withName(enumTypeName)
|
|
75
76
|
.withComment(node.description?.value)
|
|
76
|
-
.withBlock(node.values
|
|
77
|
+
.withBlock((node.values || [])
|
|
77
78
|
.map(enumOption => {
|
|
78
79
|
const optionName = makeValidEnumIdentifier((0, naming_js_1.convertName)({
|
|
79
80
|
options: {
|
|
@@ -99,7 +100,7 @@ const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumName, enu
|
|
|
99
100
|
.withComment(node.description?.value)
|
|
100
101
|
.withBlock((0, exports.buildEnumValuesBlock)({
|
|
101
102
|
typeName: enumName,
|
|
102
|
-
values: node.values,
|
|
103
|
+
values: node.values || [],
|
|
103
104
|
schema,
|
|
104
105
|
naming,
|
|
105
106
|
ignoreEnumValuesFromSchema,
|
|
@@ -109,9 +110,8 @@ const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumName, enu
|
|
|
109
110
|
};
|
|
110
111
|
exports.convertSchemaEnumToDeclarationBlockString = convertSchemaEnumToDeclarationBlockString;
|
|
111
112
|
const buildEnumValuesBlock = ({ typeName, values, schema, naming, ignoreEnumValuesFromSchema, declarationBlockConfig, enumValues, }) => {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
: undefined;
|
|
113
|
+
const schemaType = schema?.getType(typeName);
|
|
114
|
+
const schemaEnumType = (0, graphql_1.isEnumType)(schemaType) ? schemaType : undefined;
|
|
115
115
|
return values
|
|
116
116
|
.map(enumOption => {
|
|
117
117
|
const onlyUnderscoresPattern = /^_+$/;
|
|
@@ -128,9 +128,14 @@ const buildEnumValuesBlock = ({ typeName, values, schema, naming, ignoreEnumValu
|
|
|
128
128
|
}),
|
|
129
129
|
}));
|
|
130
130
|
const comment = (0, utils_js_1.getNodeComment)(enumOption);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
let schemaEnumValue;
|
|
132
|
+
if (schemaEnumType && !ignoreEnumValuesFromSchema) {
|
|
133
|
+
const schemaEnumValueDefinition = schemaEnumType.getValue(enumOption.name.value);
|
|
134
|
+
if (!schemaEnumValueDefinition) {
|
|
135
|
+
throw new Error(`Enum value "${enumOption.name.value}" is not defined on enum "${typeName}" in the schema`);
|
|
136
|
+
}
|
|
137
|
+
schemaEnumValue = schemaEnumValueDefinition.value;
|
|
138
|
+
}
|
|
134
139
|
let enumValue = typeof schemaEnumValue === 'undefined' ? enumOption.name.value : schemaEnumValue;
|
|
135
140
|
if (typeof enumValues[typeName]?.mappedValues?.[enumValue] !== 'undefined') {
|
|
136
141
|
enumValue = enumValues[typeName].mappedValues[enumValue];
|
package/cjs/imports.js
CHANGED
|
@@ -16,7 +16,7 @@ function generateFragmentImportStatement(statement, kind) {
|
|
|
16
16
|
const { importSource: fragmentImportSource, ...rest } = statement;
|
|
17
17
|
const { identifiers, path, namespace } = fragmentImportSource;
|
|
18
18
|
const importSource = {
|
|
19
|
-
identifiers: identifiers
|
|
19
|
+
identifiers: (identifiers || [])
|
|
20
20
|
.filter(fragmentImport => kind === 'both' || kind === fragmentImport.kind)
|
|
21
21
|
.map(({ name }) => name),
|
|
22
22
|
path,
|
|
@@ -134,6 +134,9 @@ function getEnumsImports({ enumValues, useTypeImports, }) {
|
|
|
134
134
|
.filter(Boolean);
|
|
135
135
|
}
|
|
136
136
|
function buildTypeImport({ identifier, source, useTypeImports, asDefault = false, }) {
|
|
137
|
+
if (identifier == null || source == null) {
|
|
138
|
+
throw new Error(`Cannot build a type import without an identifier and a source (identifier: ${identifier}, source: ${source})`);
|
|
139
|
+
}
|
|
137
140
|
if (asDefault) {
|
|
138
141
|
if (useTypeImports) {
|
|
139
142
|
return `import type { default as ${identifier} } from '${source}';`;
|
package/cjs/mappers.js
CHANGED
|
@@ -141,7 +141,7 @@ function addSuffix(element, suffix) {
|
|
|
141
141
|
function isExternalMapper(value) {
|
|
142
142
|
return value.includes('#');
|
|
143
143
|
}
|
|
144
|
-
function transformMappers(rawMappers, mapperTypeSuffix) {
|
|
144
|
+
function transformMappers(rawMappers = {}, mapperTypeSuffix) {
|
|
145
145
|
const result = {};
|
|
146
146
|
for (const gqlTypeName of Object.keys(rawMappers)) {
|
|
147
147
|
const mapperDef = rawMappers[gqlTypeName];
|
package/cjs/naming.js
CHANGED
|
@@ -79,23 +79,24 @@ function convertFactory(config) {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
if (typeof config.namingConvention === 'function') {
|
|
82
|
+
const namingConvention = config.namingConvention;
|
|
82
83
|
return (str, opts = {}) => {
|
|
83
|
-
return convertNameParts(str,
|
|
84
|
+
return convertNameParts(str, namingConvention, (0, utils_js_1.getConfigValue)(opts?.transformUnderscore, false));
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
87
|
if (typeof config.namingConvention === 'object' && config.namingConvention[type] === 'keep') {
|
|
87
88
|
return str => str;
|
|
88
89
|
}
|
|
89
90
|
if (typeof config.namingConvention === 'object') {
|
|
90
|
-
|
|
91
|
+
const namingConvention = config.namingConvention;
|
|
92
|
+
if (!namingConvention[type]) {
|
|
91
93
|
return (str, opts = {}) => {
|
|
92
|
-
const transformUnderscore =
|
|
93
|
-
opts?.transformUnderscore;
|
|
94
|
+
const transformUnderscore = namingConvention.transformUnderscore || opts?.transformUnderscore;
|
|
94
95
|
return convertNameParts(str, change_case_all_1.pascalCase, (0, utils_js_1.getConfigValue)(transformUnderscore, false));
|
|
95
96
|
};
|
|
96
97
|
}
|
|
97
98
|
return (str, opts = {}) => {
|
|
98
|
-
return convertNameParts(str, (0, plugin_helpers_1.resolveExternalModuleAndFn)(
|
|
99
|
+
return convertNameParts(str, (0, plugin_helpers_1.resolveExternalModuleAndFn)(namingConvention[type]), (0, utils_js_1.getConfigValue)(opts?.transformUnderscore, true));
|
|
99
100
|
};
|
|
100
101
|
}
|
|
101
102
|
return config.namingConvention[type];
|
|
@@ -3,7 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.optimizeOperations = optimizeOperations;
|
|
4
4
|
const relay_operation_optimizer_1 = require("@graphql-tools/relay-operation-optimizer");
|
|
5
5
|
function optimizeOperations(schema, documents, options) {
|
|
6
|
-
const newDocuments = (0, relay_operation_optimizer_1.optimizeDocuments)(schema, documents.map(s =>
|
|
6
|
+
const newDocuments = (0, relay_operation_optimizer_1.optimizeDocuments)(schema, documents.map(s => {
|
|
7
|
+
if (!s.document) {
|
|
8
|
+
throw new Error(`Cannot optimize the document at "${s.location}": it has no parsed document`);
|
|
9
|
+
}
|
|
10
|
+
return s.document;
|
|
11
|
+
}), options);
|
|
7
12
|
return newDocuments.map((document, index) => ({
|
|
8
13
|
...documents[index],
|
|
9
14
|
location: documents[index]?.location || 'optimized by relay',
|
package/cjs/utils.js
CHANGED
|
@@ -151,6 +151,7 @@ class DeclarationBlock {
|
|
|
151
151
|
}
|
|
152
152
|
get string() {
|
|
153
153
|
let result = '';
|
|
154
|
+
const blockTransformer = this._config.blockTransformer || (block => block);
|
|
154
155
|
if (this._decorator) {
|
|
155
156
|
result += this._decorator + '\n';
|
|
156
157
|
}
|
|
@@ -177,17 +178,17 @@ class DeclarationBlock {
|
|
|
177
178
|
const after = blockWrapper + '}';
|
|
178
179
|
const block = [before, this._block, after].filter(val => !!val).join('\n');
|
|
179
180
|
if (this._methodName) {
|
|
180
|
-
result += `${this._methodName}(${
|
|
181
|
+
result += `${this._methodName}(${blockTransformer(block)})`;
|
|
181
182
|
}
|
|
182
183
|
else {
|
|
183
|
-
result +=
|
|
184
|
+
result += blockTransformer(block);
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
else if (this._content) {
|
|
187
188
|
result += this._content;
|
|
188
189
|
}
|
|
189
190
|
else if (this._kind) {
|
|
190
|
-
result +=
|
|
191
|
+
result += blockTransformer('{}');
|
|
191
192
|
}
|
|
192
193
|
return stripTrailingSpaces((this._comment || '') +
|
|
193
194
|
result +
|
|
@@ -482,8 +483,11 @@ function isOneOfInputObjectType(namedType) {
|
|
|
482
483
|
}
|
|
483
484
|
isOneOfType =
|
|
484
485
|
(0, graphql_1.isInputObjectType)(namedType) &&
|
|
485
|
-
|
|
486
|
-
|
|
486
|
+
// `isOneOf` only exists on GraphQLInputObjectType from graphql 16.9; removing this cast needs
|
|
487
|
+
// dropping support for older graphql versions
|
|
488
|
+
((namedType.isOneOf ||
|
|
489
|
+
namedType.astNode?.directives?.some(d => d.name.value === 'oneOf')) ??
|
|
490
|
+
false);
|
|
487
491
|
isOneOfTypeCache.set(namedType, isOneOfType);
|
|
488
492
|
return isOneOfType;
|
|
489
493
|
}
|
|
@@ -497,7 +501,7 @@ function groupBy(array, key) {
|
|
|
497
501
|
function flatten(array) {
|
|
498
502
|
return [].concat(...array);
|
|
499
503
|
}
|
|
500
|
-
function unique(array, key = item => item
|
|
504
|
+
function unique(array, key = item => String(item)) {
|
|
501
505
|
return Object.values(array.reduce((acc, item) => ({ [key(item)]: item, ...acc }), {}));
|
|
502
506
|
}
|
|
503
507
|
/**
|
|
@@ -571,7 +575,7 @@ exports.getNodeComment = getNodeComment;
|
|
|
571
575
|
const getDeprecationReason = (directive) => {
|
|
572
576
|
if (directive.name.value === 'deprecated') {
|
|
573
577
|
let reason = 'Field no longer supported';
|
|
574
|
-
const deprecatedReason = directive.arguments[0];
|
|
578
|
+
const deprecatedReason = directive.arguments?.[0];
|
|
575
579
|
if (deprecatedReason && deprecatedReason.value.kind === graphql_1.Kind.STRING) {
|
|
576
580
|
reason = deprecatedReason.value.value;
|
|
577
581
|
}
|
|
@@ -90,7 +90,8 @@ class OperationVariablesToObject {
|
|
|
90
90
|
else if (this._enumValues[typeName]?.sourceFile) {
|
|
91
91
|
typeValue =
|
|
92
92
|
this._enumValues[typeName].typeIdentifierConverted ||
|
|
93
|
-
this._enumValues[typeName].sourceIdentifier
|
|
93
|
+
this._enumValues[typeName].sourceIdentifier ||
|
|
94
|
+
'';
|
|
94
95
|
}
|
|
95
96
|
else {
|
|
96
97
|
typeValue = `${prefix}${this._convertName(baseType, {
|
|
@@ -99,7 +100,7 @@ class OperationVariablesToObject {
|
|
|
99
100
|
})}`;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
|
-
const fieldName = this.getName(variable);
|
|
103
|
+
const fieldName = this.getName(variable) || '';
|
|
103
104
|
const fieldType = this.wrapAstTypeWithModifiers(typeValue, variable.type, this._applyCoercion);
|
|
104
105
|
const hasDefaultValue = variable.defaultValue != null && typeof variable.defaultValue !== 'undefined';
|
|
105
106
|
const isNonNullType = variable.type.kind === graphql_1.Kind.NON_NULL_TYPE;
|
|
@@ -97,7 +97,7 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
97
97
|
}
|
|
98
98
|
return null;
|
|
99
99
|
})
|
|
100
|
-
.filter(a => a);
|
|
100
|
+
.filter((a) => !!a);
|
|
101
101
|
}
|
|
102
102
|
get scalarsDefinition() {
|
|
103
103
|
if (this.config.onlyEnums)
|
|
@@ -157,18 +157,19 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
157
157
|
.asKind(this._parsedConfig.declarationKind.input)
|
|
158
158
|
.withName(this.convertName(node))
|
|
159
159
|
.withComment(node.description?.value)
|
|
160
|
-
.withBlock(node.fields.join('\n'));
|
|
160
|
+
.withBlock((node.fields || []).join('\n'));
|
|
161
161
|
}
|
|
162
162
|
getInputObjectOneOfDeclarationBlock(node) {
|
|
163
|
+
const fields = node.fields || [];
|
|
163
164
|
return new DeclarationBlock(this._declarationBlockConfig)
|
|
164
165
|
.export()
|
|
165
166
|
.asKind(getOneOfInputDeclarationKind({
|
|
166
|
-
fieldCount:
|
|
167
|
+
fieldCount: fields.length,
|
|
167
168
|
inputDeclarationKind: this._parsedConfig.declarationKind.input,
|
|
168
169
|
}))
|
|
169
170
|
.withName(this.convertName(node))
|
|
170
171
|
.withComment(node.description?.value)
|
|
171
|
-
.withContent(`\n` +
|
|
172
|
+
.withContent(`\n` + fields.join('\n |'));
|
|
172
173
|
}
|
|
173
174
|
InputObjectTypeDefinition(node) {
|
|
174
175
|
if (this.config.onlyEnums)
|
|
@@ -181,8 +182,9 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
181
182
|
InputValueDefinition(node, _key, _parent, _path, _ancestors) {
|
|
182
183
|
if (this.config.onlyEnums)
|
|
183
184
|
return '';
|
|
184
|
-
const comment = transformComment(node.description
|
|
185
|
+
const comment = transformComment(node.description?.value, 1);
|
|
185
186
|
const { input } = this._parsedConfig.declarationKind;
|
|
187
|
+
// `node.type` is already printed to a string by the visitor; removing the cast needs a visited-AST type for `node`
|
|
186
188
|
let type = node.type;
|
|
187
189
|
if (node.directives && this.config.directiveArgumentAndInputFieldMappings) {
|
|
188
190
|
type = this._getDirectiveOverrideType(node.directives) || type;
|
|
@@ -200,15 +202,16 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
200
202
|
UnionTypeDefinition(node, key, parent) {
|
|
201
203
|
if (this.config.onlyOperationTypes || this.config.onlyEnums)
|
|
202
204
|
return '';
|
|
205
|
+
// `node.types` are already printed strings, so the original AST node is read from `parent[key]`, and `parent` is `any` because oldVisit's parent is untyped
|
|
203
206
|
const originalNode = parent[key];
|
|
204
|
-
const possibleTypes = originalNode.types
|
|
207
|
+
const possibleTypes = (originalNode.types || [])
|
|
205
208
|
.map(t => this.scalars[t.name.value] ? this._getScalar(t.name.value, 'output') : this.convertName(t))
|
|
206
209
|
.join(' | ');
|
|
207
210
|
return new DeclarationBlock(this._declarationBlockConfig)
|
|
208
211
|
.export()
|
|
209
212
|
.asKind('type')
|
|
210
213
|
.withName(this.convertName(node))
|
|
211
|
-
.withComment(node.description
|
|
214
|
+
.withComment(node.description?.value)
|
|
212
215
|
.withContent(possibleTypes).string;
|
|
213
216
|
}
|
|
214
217
|
mergeInterfaces(interfaces, hasOtherFields) {
|
|
@@ -221,13 +224,14 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
221
224
|
getObjectTypeDeclarationBlock(node, originalNode) {
|
|
222
225
|
const optionalTypename = this.config.nonOptionalTypename ? '__typename' : '__typename?';
|
|
223
226
|
const { type, interface: interfacesType } = this._parsedConfig.declarationKind;
|
|
227
|
+
// `node.fields` are already printed to strings by the visitor; dropping `as string[]` needs a visited-AST type for `node`
|
|
224
228
|
const allFields = [
|
|
225
229
|
...(this.config.addTypename
|
|
226
230
|
? [
|
|
227
231
|
indent(`${this.config.immutableTypes ? 'readonly ' : ''}${optionalTypename}: '${node.name.value}'${this.getPunctuation(type)}`),
|
|
228
232
|
]
|
|
229
233
|
: []),
|
|
230
|
-
...node.fields,
|
|
234
|
+
...(node.fields || []),
|
|
231
235
|
];
|
|
232
236
|
const interfacesNames = originalNode.interfaces
|
|
233
237
|
? originalNode.interfaces.map(i => this.convertName(i))
|
|
@@ -269,7 +273,7 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
269
273
|
.asKind(this._parsedConfig.declarationKind.interface)
|
|
270
274
|
.withName(this.convertName(node))
|
|
271
275
|
.withComment(node.description?.value);
|
|
272
|
-
return declarationBlock.withBlock(node.fields.join('\n'));
|
|
276
|
+
return declarationBlock.withBlock((node.fields || []).join('\n'));
|
|
273
277
|
}
|
|
274
278
|
InterfaceTypeDefinition(node, key, parent) {
|
|
275
279
|
if (this.config.onlyOperationTypes || this.config.onlyEnums)
|
|
@@ -305,10 +309,10 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
305
309
|
useTypesPrefix: this.config.enumPrefix,
|
|
306
310
|
useTypesSuffix: this.config.enumSuffix,
|
|
307
311
|
}))
|
|
308
|
-
.withComment(node.description
|
|
312
|
+
.withComment(node.description?.value)
|
|
309
313
|
.withBlock(buildEnumValuesBlock({
|
|
310
314
|
typeName: enumName,
|
|
311
|
-
values: node.values,
|
|
315
|
+
values: node.values || [],
|
|
312
316
|
schema: this._schema,
|
|
313
317
|
naming: {
|
|
314
318
|
convert: this.config.convert,
|
|
@@ -347,7 +351,7 @@ export class BaseTypesVisitor extends BaseVisitor {
|
|
|
347
351
|
return this.getArgumentsObjectDeclarationBlock(node, name, field).string;
|
|
348
352
|
}
|
|
349
353
|
buildArgumentsBlock(node) {
|
|
350
|
-
const fieldsWithArguments = node.fields
|
|
354
|
+
const fieldsWithArguments = node.fields?.filter(field => field.arguments && field.arguments.length > 0) || [];
|
|
351
355
|
return fieldsWithArguments
|
|
352
356
|
.map(field => {
|
|
353
357
|
const name = node.name.value +
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isEnumType, } from 'graphql';
|
|
1
2
|
import { convertName } from './naming.js';
|
|
2
3
|
import { DeclarationBlock, getNodeComment, indent, transformComment, wrapWithSingleQuotes, } from './utils.js';
|
|
3
4
|
export const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumName, enumValues, futureProofEnums, ignoreEnumValuesFromSchema, outputType, declarationBlockConfig, naming, }) => {
|
|
@@ -24,7 +25,7 @@ export const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumNa
|
|
|
24
25
|
.withComment(node.description?.value)
|
|
25
26
|
.withName(enumTypeName)
|
|
26
27
|
.withContent('\n' +
|
|
27
|
-
node.values
|
|
28
|
+
(node.values || [])
|
|
28
29
|
.map(enumOption => {
|
|
29
30
|
const name = enumOption.name.value;
|
|
30
31
|
const enumValue = getValueFromConfig(name) ?? name;
|
|
@@ -40,7 +41,7 @@ export const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumNa
|
|
|
40
41
|
.withComment(node.description?.value)
|
|
41
42
|
.withName(enumTypeName)
|
|
42
43
|
.asKind('enum')
|
|
43
|
-
.withBlock(node.values
|
|
44
|
+
.withBlock((node.values || [])
|
|
44
45
|
.map((enumOption, i) => {
|
|
45
46
|
const valueFromConfig = getValueFromConfig(enumOption.name.value);
|
|
46
47
|
const enumValue = valueFromConfig ?? i;
|
|
@@ -70,7 +71,7 @@ export const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumNa
|
|
|
70
71
|
.asKind('const')
|
|
71
72
|
.withName(enumTypeName)
|
|
72
73
|
.withComment(node.description?.value)
|
|
73
|
-
.withBlock(node.values
|
|
74
|
+
.withBlock((node.values || [])
|
|
74
75
|
.map(enumOption => {
|
|
75
76
|
const optionName = makeValidEnumIdentifier(convertName({
|
|
76
77
|
options: {
|
|
@@ -96,7 +97,7 @@ export const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumNa
|
|
|
96
97
|
.withComment(node.description?.value)
|
|
97
98
|
.withBlock(buildEnumValuesBlock({
|
|
98
99
|
typeName: enumName,
|
|
99
|
-
values: node.values,
|
|
100
|
+
values: node.values || [],
|
|
100
101
|
schema,
|
|
101
102
|
naming,
|
|
102
103
|
ignoreEnumValuesFromSchema,
|
|
@@ -105,9 +106,8 @@ export const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumNa
|
|
|
105
106
|
})).string;
|
|
106
107
|
};
|
|
107
108
|
export const buildEnumValuesBlock = ({ typeName, values, schema, naming, ignoreEnumValuesFromSchema, declarationBlockConfig, enumValues, }) => {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
: undefined;
|
|
109
|
+
const schemaType = schema?.getType(typeName);
|
|
110
|
+
const schemaEnumType = isEnumType(schemaType) ? schemaType : undefined;
|
|
111
111
|
return values
|
|
112
112
|
.map(enumOption => {
|
|
113
113
|
const onlyUnderscoresPattern = /^_+$/;
|
|
@@ -124,9 +124,14 @@ export const buildEnumValuesBlock = ({ typeName, values, schema, naming, ignoreE
|
|
|
124
124
|
}),
|
|
125
125
|
}));
|
|
126
126
|
const comment = getNodeComment(enumOption);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
let schemaEnumValue;
|
|
128
|
+
if (schemaEnumType && !ignoreEnumValuesFromSchema) {
|
|
129
|
+
const schemaEnumValueDefinition = schemaEnumType.getValue(enumOption.name.value);
|
|
130
|
+
if (!schemaEnumValueDefinition) {
|
|
131
|
+
throw new Error(`Enum value "${enumOption.name.value}" is not defined on enum "${typeName}" in the schema`);
|
|
132
|
+
}
|
|
133
|
+
schemaEnumValue = schemaEnumValueDefinition.value;
|
|
134
|
+
}
|
|
130
135
|
let enumValue = typeof schemaEnumValue === 'undefined' ? enumOption.name.value : schemaEnumValue;
|
|
131
136
|
if (typeof enumValues[typeName]?.mappedValues?.[enumValue] !== 'undefined') {
|
|
132
137
|
enumValue = enumValues[typeName].mappedValues[enumValue];
|
package/esm/imports.js
CHANGED
|
@@ -5,7 +5,7 @@ export function generateFragmentImportStatement(statement, kind) {
|
|
|
5
5
|
const { importSource: fragmentImportSource, ...rest } = statement;
|
|
6
6
|
const { identifiers, path, namespace } = fragmentImportSource;
|
|
7
7
|
const importSource = {
|
|
8
|
-
identifiers: identifiers
|
|
8
|
+
identifiers: (identifiers || [])
|
|
9
9
|
.filter(fragmentImport => kind === 'both' || kind === fragmentImport.kind)
|
|
10
10
|
.map(({ name }) => name),
|
|
11
11
|
path,
|
|
@@ -123,6 +123,9 @@ export function getEnumsImports({ enumValues, useTypeImports, }) {
|
|
|
123
123
|
.filter(Boolean);
|
|
124
124
|
}
|
|
125
125
|
export function buildTypeImport({ identifier, source, useTypeImports, asDefault = false, }) {
|
|
126
|
+
if (identifier == null || source == null) {
|
|
127
|
+
throw new Error(`Cannot build a type import without an identifier and a source (identifier: ${identifier}, source: ${source})`);
|
|
128
|
+
}
|
|
126
129
|
if (asDefault) {
|
|
127
130
|
if (useTypeImports) {
|
|
128
131
|
return `import type { default as ${identifier} } from '${source}';`;
|
package/esm/mappers.js
CHANGED
|
@@ -133,7 +133,7 @@ function addSuffix(element, suffix) {
|
|
|
133
133
|
export function isExternalMapper(value) {
|
|
134
134
|
return value.includes('#');
|
|
135
135
|
}
|
|
136
|
-
export function transformMappers(rawMappers, mapperTypeSuffix) {
|
|
136
|
+
export function transformMappers(rawMappers = {}, mapperTypeSuffix) {
|
|
137
137
|
const result = {};
|
|
138
138
|
for (const gqlTypeName of Object.keys(rawMappers)) {
|
|
139
139
|
const mapperDef = rawMappers[gqlTypeName];
|
package/esm/naming.js
CHANGED
|
@@ -75,23 +75,24 @@ export function convertFactory(config) {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
if (typeof config.namingConvention === 'function') {
|
|
78
|
+
const namingConvention = config.namingConvention;
|
|
78
79
|
return (str, opts = {}) => {
|
|
79
|
-
return convertNameParts(str,
|
|
80
|
+
return convertNameParts(str, namingConvention, getConfigValue(opts?.transformUnderscore, false));
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
83
|
if (typeof config.namingConvention === 'object' && config.namingConvention[type] === 'keep') {
|
|
83
84
|
return str => str;
|
|
84
85
|
}
|
|
85
86
|
if (typeof config.namingConvention === 'object') {
|
|
86
|
-
|
|
87
|
+
const namingConvention = config.namingConvention;
|
|
88
|
+
if (!namingConvention[type]) {
|
|
87
89
|
return (str, opts = {}) => {
|
|
88
|
-
const transformUnderscore =
|
|
89
|
-
opts?.transformUnderscore;
|
|
90
|
+
const transformUnderscore = namingConvention.transformUnderscore || opts?.transformUnderscore;
|
|
90
91
|
return convertNameParts(str, pascalCase, getConfigValue(transformUnderscore, false));
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
return (str, opts = {}) => {
|
|
94
|
-
return convertNameParts(str, resolveExternalModuleAndFn(
|
|
95
|
+
return convertNameParts(str, resolveExternalModuleAndFn(namingConvention[type]), getConfigValue(opts?.transformUnderscore, true));
|
|
95
96
|
};
|
|
96
97
|
}
|
|
97
98
|
return config.namingConvention[type];
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { optimizeDocuments } from '@graphql-tools/relay-operation-optimizer';
|
|
2
2
|
export function optimizeOperations(schema, documents, options) {
|
|
3
|
-
const newDocuments = optimizeDocuments(schema, documents.map(s =>
|
|
3
|
+
const newDocuments = optimizeDocuments(schema, documents.map(s => {
|
|
4
|
+
if (!s.document) {
|
|
5
|
+
throw new Error(`Cannot optimize the document at "${s.location}": it has no parsed document`);
|
|
6
|
+
}
|
|
7
|
+
return s.document;
|
|
8
|
+
}), options);
|
|
4
9
|
return newDocuments.map((document, index) => ({
|
|
5
10
|
...documents[index],
|
|
6
11
|
location: documents[index]?.location || 'optimized by relay',
|
package/esm/utils.js
CHANGED
|
@@ -122,6 +122,7 @@ export class DeclarationBlock {
|
|
|
122
122
|
}
|
|
123
123
|
get string() {
|
|
124
124
|
let result = '';
|
|
125
|
+
const blockTransformer = this._config.blockTransformer || (block => block);
|
|
125
126
|
if (this._decorator) {
|
|
126
127
|
result += this._decorator + '\n';
|
|
127
128
|
}
|
|
@@ -148,17 +149,17 @@ export class DeclarationBlock {
|
|
|
148
149
|
const after = blockWrapper + '}';
|
|
149
150
|
const block = [before, this._block, after].filter(val => !!val).join('\n');
|
|
150
151
|
if (this._methodName) {
|
|
151
|
-
result += `${this._methodName}(${
|
|
152
|
+
result += `${this._methodName}(${blockTransformer(block)})`;
|
|
152
153
|
}
|
|
153
154
|
else {
|
|
154
|
-
result +=
|
|
155
|
+
result += blockTransformer(block);
|
|
155
156
|
}
|
|
156
157
|
}
|
|
157
158
|
else if (this._content) {
|
|
158
159
|
result += this._content;
|
|
159
160
|
}
|
|
160
161
|
else if (this._kind) {
|
|
161
|
-
result +=
|
|
162
|
+
result += blockTransformer('{}');
|
|
162
163
|
}
|
|
163
164
|
return stripTrailingSpaces((this._comment || '') +
|
|
164
165
|
result +
|
|
@@ -451,8 +452,11 @@ export function isOneOfInputObjectType(namedType) {
|
|
|
451
452
|
}
|
|
452
453
|
isOneOfType =
|
|
453
454
|
isInputObjectType(namedType) &&
|
|
454
|
-
|
|
455
|
-
|
|
455
|
+
// `isOneOf` only exists on GraphQLInputObjectType from graphql 16.9; removing this cast needs
|
|
456
|
+
// dropping support for older graphql versions
|
|
457
|
+
((namedType.isOneOf ||
|
|
458
|
+
namedType.astNode?.directives?.some(d => d.name.value === 'oneOf')) ??
|
|
459
|
+
false);
|
|
456
460
|
isOneOfTypeCache.set(namedType, isOneOfType);
|
|
457
461
|
return isOneOfType;
|
|
458
462
|
}
|
|
@@ -466,7 +470,7 @@ export function groupBy(array, key) {
|
|
|
466
470
|
export function flatten(array) {
|
|
467
471
|
return [].concat(...array);
|
|
468
472
|
}
|
|
469
|
-
export function unique(array, key = item => item
|
|
473
|
+
export function unique(array, key = item => String(item)) {
|
|
470
474
|
return Object.values(array.reduce((acc, item) => ({ [key(item)]: item, ...acc }), {}));
|
|
471
475
|
}
|
|
472
476
|
/**
|
|
@@ -539,7 +543,7 @@ export const getNodeComment = (node) => {
|
|
|
539
543
|
const getDeprecationReason = (directive) => {
|
|
540
544
|
if (directive.name.value === 'deprecated') {
|
|
541
545
|
let reason = 'Field no longer supported';
|
|
542
|
-
const deprecatedReason = directive.arguments[0];
|
|
546
|
+
const deprecatedReason = directive.arguments?.[0];
|
|
543
547
|
if (deprecatedReason && deprecatedReason.value.kind === Kind.STRING) {
|
|
544
548
|
reason = deprecatedReason.value.value;
|
|
545
549
|
}
|
|
@@ -86,7 +86,8 @@ export class OperationVariablesToObject {
|
|
|
86
86
|
else if (this._enumValues[typeName]?.sourceFile) {
|
|
87
87
|
typeValue =
|
|
88
88
|
this._enumValues[typeName].typeIdentifierConverted ||
|
|
89
|
-
this._enumValues[typeName].sourceIdentifier
|
|
89
|
+
this._enumValues[typeName].sourceIdentifier ||
|
|
90
|
+
'';
|
|
90
91
|
}
|
|
91
92
|
else {
|
|
92
93
|
typeValue = `${prefix}${this._convertName(baseType, {
|
|
@@ -95,7 +96,7 @@ export class OperationVariablesToObject {
|
|
|
95
96
|
})}`;
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
const fieldName = this.getName(variable);
|
|
99
|
+
const fieldName = this.getName(variable) || '';
|
|
99
100
|
const fieldType = this.wrapAstTypeWithModifiers(typeValue, variable.type, this._applyCoercion);
|
|
100
101
|
const hasDefaultValue = variable.defaultValue != null && typeof variable.defaultValue !== 'undefined';
|
|
101
102
|
const isNonNullType = variable.type.kind === Kind.NON_NULL_TYPE;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/visitor-plugin-common",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.9-alpha-20261005221753-a02bbddf0d367784d8a6c5f54bf7092266c814e0",
|
|
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 || ^17.0.0"
|
|
6
6
|
},
|
|
@@ -449,7 +449,7 @@ export interface RawTypesConfig extends RawConfig {
|
|
|
449
449
|
export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTypesConfig, TPluginConfig extends ParsedTypesConfig = ParsedTypesConfig> extends BaseVisitor<TRawConfig, TPluginConfig> {
|
|
450
450
|
protected _schema: GraphQLSchema;
|
|
451
451
|
protected _argumentsTransformer: OperationVariablesToObject;
|
|
452
|
-
constructor(_schema: GraphQLSchema, rawConfig: TRawConfig, additionalConfig: TPluginConfig
|
|
452
|
+
constructor(_schema: GraphQLSchema, rawConfig: TRawConfig, additionalConfig: Partial<TPluginConfig>, defaultScalars?: NormalizedScalarsMap);
|
|
453
453
|
protected getExportPrefix(): string;
|
|
454
454
|
getFieldWrapperValue(): string;
|
|
455
455
|
getEntireFieldWrapperValue(): string;
|
|
@@ -449,7 +449,7 @@ export interface RawTypesConfig extends RawConfig {
|
|
|
449
449
|
export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTypesConfig, TPluginConfig extends ParsedTypesConfig = ParsedTypesConfig> extends BaseVisitor<TRawConfig, TPluginConfig> {
|
|
450
450
|
protected _schema: GraphQLSchema;
|
|
451
451
|
protected _argumentsTransformer: OperationVariablesToObject;
|
|
452
|
-
constructor(_schema: GraphQLSchema, rawConfig: TRawConfig, additionalConfig: TPluginConfig
|
|
452
|
+
constructor(_schema: GraphQLSchema, rawConfig: TRawConfig, additionalConfig: Partial<TPluginConfig>, defaultScalars?: NormalizedScalarsMap);
|
|
453
453
|
protected getExportPrefix(): string;
|
|
454
454
|
getFieldWrapperValue(): string;
|
|
455
455
|
getEntireFieldWrapperValue(): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EnumTypeDefinitionNode, type EnumValueDefinitionNode, type GraphQLSchema } from 'graphql';
|
|
2
2
|
import type { ConvertFn, ParsedEnumValuesMap } from './types.cjs';
|
|
3
3
|
import { type DeclarationBlockConfig } from './utils.cjs';
|
|
4
4
|
export interface ConvertSchemaEnumToDeclarationBlockString {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EnumTypeDefinitionNode, type EnumValueDefinitionNode, type GraphQLSchema } from 'graphql';
|
|
2
2
|
import type { ConvertFn, ParsedEnumValuesMap } from './types.js';
|
|
3
3
|
import { type DeclarationBlockConfig } from './utils.js';
|
|
4
4
|
export interface ConvertSchemaEnumToDeclarationBlockString {
|
package/typings/imports.d.cts
CHANGED
|
@@ -37,8 +37,8 @@ export declare function getEnumsImports({ enumValues, useTypeImports, }: {
|
|
|
37
37
|
useTypeImports: boolean;
|
|
38
38
|
}): string[];
|
|
39
39
|
export declare function buildTypeImport({ identifier, source, useTypeImports, asDefault, }: {
|
|
40
|
-
identifier: string;
|
|
41
|
-
source: string;
|
|
40
|
+
identifier: string | null | undefined;
|
|
41
|
+
source: string | null | undefined;
|
|
42
42
|
useTypeImports: boolean;
|
|
43
43
|
asDefault?: boolean;
|
|
44
44
|
}): string;
|
package/typings/imports.d.ts
CHANGED
|
@@ -37,8 +37,8 @@ export declare function getEnumsImports({ enumValues, useTypeImports, }: {
|
|
|
37
37
|
useTypeImports: boolean;
|
|
38
38
|
}): string[];
|
|
39
39
|
export declare function buildTypeImport({ identifier, source, useTypeImports, asDefault, }: {
|
|
40
|
-
identifier: string;
|
|
41
|
-
source: string;
|
|
40
|
+
identifier: string | null | undefined;
|
|
41
|
+
source: string | null | undefined;
|
|
42
42
|
useTypeImports: boolean;
|
|
43
43
|
asDefault?: boolean;
|
|
44
44
|
}): string;
|
package/typings/mappers.d.cts
CHANGED
|
@@ -15,7 +15,7 @@ export interface ExternalParsedMapper {
|
|
|
15
15
|
export declare function isExternalMapperType(m: ParsedMapper): m is ExternalParsedMapper;
|
|
16
16
|
export declare function parseMapper(mapper: string, gqlTypeName?: string | null, suffix?: string): ParsedMapper;
|
|
17
17
|
export declare function isExternalMapper(value: string): boolean;
|
|
18
|
-
export declare function transformMappers(rawMappers
|
|
18
|
+
export declare function transformMappers(rawMappers?: RawResolversConfig['mappers'], mapperTypeSuffix?: string): ParsedResolversConfig['mappers'];
|
|
19
19
|
export declare function transformDirectiveArgumentAndInputFieldMappings(rawDirectiveArgumentAndInputFieldMappings: DirectiveArgumentAndInputFieldMappings, directiveArgumentAndInputFieldMappingTypeSuffix?: string): ParsedDirectiveArgumentAndInputFieldMappings;
|
|
20
20
|
export declare function buildMapperImport(source: string, types: {
|
|
21
21
|
identifier: string;
|
package/typings/mappers.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface ExternalParsedMapper {
|
|
|
15
15
|
export declare function isExternalMapperType(m: ParsedMapper): m is ExternalParsedMapper;
|
|
16
16
|
export declare function parseMapper(mapper: string, gqlTypeName?: string | null, suffix?: string): ParsedMapper;
|
|
17
17
|
export declare function isExternalMapper(value: string): boolean;
|
|
18
|
-
export declare function transformMappers(rawMappers
|
|
18
|
+
export declare function transformMappers(rawMappers?: RawResolversConfig['mappers'], mapperTypeSuffix?: string): ParsedResolversConfig['mappers'];
|
|
19
19
|
export declare function transformDirectiveArgumentAndInputFieldMappings(rawDirectiveArgumentAndInputFieldMappings: DirectiveArgumentAndInputFieldMappings, directiveArgumentAndInputFieldMappingTypeSuffix?: string): ParsedDirectiveArgumentAndInputFieldMappings;
|
|
20
20
|
export declare function buildMapperImport(source: string, types: {
|
|
21
21
|
identifier: string;
|
|
@@ -38,7 +38,7 @@ export declare class BaseSelectionSetProcessor<Config extends SelectionSetProces
|
|
|
38
38
|
typeCache: Map<Location, Map<string, [string, string]>>;
|
|
39
39
|
constructor(config: Config);
|
|
40
40
|
buildFieldsIntoObject(allObjectsMerged: string[]): string;
|
|
41
|
-
buildSelectionSetFromStrings(pieces: string[]): string;
|
|
41
|
+
buildSelectionSetFromStrings(pieces: string[]): string | null;
|
|
42
42
|
transformPrimitiveFields(_schemaType: GraphQLObjectType | GraphQLInterfaceType, _fields: PrimitiveField[], _unsetTypes?: boolean): ProcessResult;
|
|
43
43
|
transformAliasesPrimitiveFields(_schemaType: GraphQLObjectType | GraphQLInterfaceType, _fields: PrimitiveAliasedFields[], _unsetTypes?: boolean): ProcessResult;
|
|
44
44
|
transformLinkFields(_fields: LinkField[], _unsetTypes?: boolean): ProcessResult;
|
|
@@ -38,7 +38,7 @@ export declare class BaseSelectionSetProcessor<Config extends SelectionSetProces
|
|
|
38
38
|
typeCache: Map<Location, Map<string, [string, string]>>;
|
|
39
39
|
constructor(config: Config);
|
|
40
40
|
buildFieldsIntoObject(allObjectsMerged: string[]): string;
|
|
41
|
-
buildSelectionSetFromStrings(pieces: string[]): string;
|
|
41
|
+
buildSelectionSetFromStrings(pieces: string[]): string | null;
|
|
42
42
|
transformPrimitiveFields(_schemaType: GraphQLObjectType | GraphQLInterfaceType, _fields: PrimitiveField[], _unsetTypes?: boolean): ProcessResult;
|
|
43
43
|
transformAliasesPrimitiveFields(_schemaType: GraphQLObjectType | GraphQLInterfaceType, _fields: PrimitiveAliasedFields[], _unsetTypes?: boolean): ProcessResult;
|
|
44
44
|
transformLinkFields(_fields: LinkField[], _unsetTypes?: boolean): ProcessResult;
|
package/typings/types.d.cts
CHANGED
|
@@ -54,12 +54,12 @@ export type ParsedEnumValuesMap = {
|
|
|
54
54
|
[enumName: string]: {
|
|
55
55
|
mappedValues?: {
|
|
56
56
|
[valueName: string]: string | number;
|
|
57
|
-
};
|
|
57
|
+
} | null;
|
|
58
58
|
typeIdentifier: string;
|
|
59
59
|
typeIdentifierConverted: string;
|
|
60
|
-
sourceIdentifier?: string;
|
|
61
|
-
sourceFile?: string;
|
|
62
|
-
importIdentifier?: string;
|
|
60
|
+
sourceIdentifier?: string | null;
|
|
61
|
+
sourceFile?: string | null;
|
|
62
|
+
importIdentifier?: string | null;
|
|
63
63
|
isDefault?: boolean;
|
|
64
64
|
};
|
|
65
65
|
};
|
package/typings/types.d.ts
CHANGED
|
@@ -54,12 +54,12 @@ export type ParsedEnumValuesMap = {
|
|
|
54
54
|
[enumName: string]: {
|
|
55
55
|
mappedValues?: {
|
|
56
56
|
[valueName: string]: string | number;
|
|
57
|
-
};
|
|
57
|
+
} | null;
|
|
58
58
|
typeIdentifier: string;
|
|
59
59
|
typeIdentifierConverted: string;
|
|
60
|
-
sourceIdentifier?: string;
|
|
61
|
-
sourceFile?: string;
|
|
62
|
-
importIdentifier?: string;
|
|
60
|
+
sourceIdentifier?: string | null;
|
|
61
|
+
sourceFile?: string | null;
|
|
62
|
+
importIdentifier?: string | null;
|
|
63
63
|
isDefault?: boolean;
|
|
64
64
|
};
|
|
65
65
|
};
|
package/typings/utils.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ import type { EnrichedFieldNode } from './selection-set-to-object.cjs';
|
|
|
4
4
|
import type { DeclarationKind, NormalizedScalarsMap, ParsedScalarsMap, ScalarsMap } from './types.cjs';
|
|
5
5
|
export declare const getConfigValue: <T = any>(value: T | null | undefined, defaultValue: T) => T;
|
|
6
6
|
export declare function quoteIfNeeded(array: string[], joinWith?: string): string;
|
|
7
|
-
export declare function block(array:
|
|
7
|
+
export declare function block(array: string[] | null | undefined): string;
|
|
8
8
|
export declare function wrapWithSingleQuotes(value: string | number | NameNode, skipNumericCheck?: boolean): string;
|
|
9
9
|
export declare function breakLine(str: string): string;
|
|
10
10
|
export declare function indent(str: string, count?: number): string;
|
|
@@ -15,17 +15,17 @@ export interface DeclarationBlockConfig {
|
|
|
15
15
|
enumNameValueSeparator?: string;
|
|
16
16
|
ignoreExport?: boolean;
|
|
17
17
|
}
|
|
18
|
-
export declare function transformComment(comment: string | StringValueNode, indentLevel?: number, disabled?: boolean): string;
|
|
18
|
+
export declare function transformComment(comment: string | StringValueNode | undefined | null, indentLevel?: number, disabled?: boolean): string;
|
|
19
19
|
export declare class DeclarationBlock {
|
|
20
20
|
private _config;
|
|
21
|
-
_decorator:
|
|
21
|
+
_decorator: string | null;
|
|
22
22
|
_export: boolean;
|
|
23
|
-
_name:
|
|
24
|
-
_kind:
|
|
25
|
-
_methodName:
|
|
26
|
-
_content:
|
|
27
|
-
_block:
|
|
28
|
-
_nameGenerics:
|
|
23
|
+
_name: string | NameNode | null;
|
|
24
|
+
_kind: string | null;
|
|
25
|
+
_methodName: string | null;
|
|
26
|
+
_content: string | null;
|
|
27
|
+
_block: string | null;
|
|
28
|
+
_nameGenerics: string | null;
|
|
29
29
|
_comment: string | null;
|
|
30
30
|
_ignoreBlockWrapper: boolean;
|
|
31
31
|
constructor(_config: DeclarationBlockConfig);
|
|
@@ -34,14 +34,14 @@ export declare class DeclarationBlock {
|
|
|
34
34
|
asKind(kind: string): DeclarationBlock;
|
|
35
35
|
withComment(comment: string | StringValueNode | null | undefined, disabled?: boolean): DeclarationBlock;
|
|
36
36
|
withMethodCall(methodName: string, ignoreBlockWrapper?: boolean): DeclarationBlock;
|
|
37
|
-
withBlock(block: string): DeclarationBlock;
|
|
37
|
+
withBlock(block: string | null): DeclarationBlock;
|
|
38
38
|
withContent(content: string): DeclarationBlock;
|
|
39
39
|
withName(name: string | NameNode, generics?: string | null): DeclarationBlock;
|
|
40
40
|
get string(): string;
|
|
41
41
|
}
|
|
42
42
|
export declare function getBaseTypeNode(typeNode: TypeNode): NamedTypeNode;
|
|
43
43
|
export declare function buildScalarsFromConfig(schema: GraphQLSchema | undefined, config: RawConfig, defaultScalarsMapping?: NormalizedScalarsMap, defaultScalarType?: string): ParsedScalarsMap;
|
|
44
|
-
export declare function buildScalars(schema: GraphQLSchema | undefined, scalarsMapping: ScalarsMap, defaultScalarsMapping?: NormalizedScalarsMap, defaultScalarType?: string | null): ParsedScalarsMap;
|
|
44
|
+
export declare function buildScalars(schema: GraphQLSchema | undefined, scalarsMapping: ScalarsMap | undefined, defaultScalarsMapping?: NormalizedScalarsMap, defaultScalarType?: string | null): ParsedScalarsMap;
|
|
45
45
|
export declare function stripMapperTypeInterpolation(identifier: string): string;
|
|
46
46
|
export declare const OMIT_TYPE = "export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;";
|
|
47
47
|
export declare const REQUIRE_FIELDS_TYPE = "export type RequireFields<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: NonNullable<T[P]> };";
|
package/typings/utils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { EnrichedFieldNode } from './selection-set-to-object.js';
|
|
|
4
4
|
import type { DeclarationKind, NormalizedScalarsMap, ParsedScalarsMap, ScalarsMap } from './types.js';
|
|
5
5
|
export declare const getConfigValue: <T = any>(value: T | null | undefined, defaultValue: T) => T;
|
|
6
6
|
export declare function quoteIfNeeded(array: string[], joinWith?: string): string;
|
|
7
|
-
export declare function block(array:
|
|
7
|
+
export declare function block(array: string[] | null | undefined): string;
|
|
8
8
|
export declare function wrapWithSingleQuotes(value: string | number | NameNode, skipNumericCheck?: boolean): string;
|
|
9
9
|
export declare function breakLine(str: string): string;
|
|
10
10
|
export declare function indent(str: string, count?: number): string;
|
|
@@ -15,17 +15,17 @@ export interface DeclarationBlockConfig {
|
|
|
15
15
|
enumNameValueSeparator?: string;
|
|
16
16
|
ignoreExport?: boolean;
|
|
17
17
|
}
|
|
18
|
-
export declare function transformComment(comment: string | StringValueNode, indentLevel?: number, disabled?: boolean): string;
|
|
18
|
+
export declare function transformComment(comment: string | StringValueNode | undefined | null, indentLevel?: number, disabled?: boolean): string;
|
|
19
19
|
export declare class DeclarationBlock {
|
|
20
20
|
private _config;
|
|
21
|
-
_decorator:
|
|
21
|
+
_decorator: string | null;
|
|
22
22
|
_export: boolean;
|
|
23
|
-
_name:
|
|
24
|
-
_kind:
|
|
25
|
-
_methodName:
|
|
26
|
-
_content:
|
|
27
|
-
_block:
|
|
28
|
-
_nameGenerics:
|
|
23
|
+
_name: string | NameNode | null;
|
|
24
|
+
_kind: string | null;
|
|
25
|
+
_methodName: string | null;
|
|
26
|
+
_content: string | null;
|
|
27
|
+
_block: string | null;
|
|
28
|
+
_nameGenerics: string | null;
|
|
29
29
|
_comment: string | null;
|
|
30
30
|
_ignoreBlockWrapper: boolean;
|
|
31
31
|
constructor(_config: DeclarationBlockConfig);
|
|
@@ -34,14 +34,14 @@ export declare class DeclarationBlock {
|
|
|
34
34
|
asKind(kind: string): DeclarationBlock;
|
|
35
35
|
withComment(comment: string | StringValueNode | null | undefined, disabled?: boolean): DeclarationBlock;
|
|
36
36
|
withMethodCall(methodName: string, ignoreBlockWrapper?: boolean): DeclarationBlock;
|
|
37
|
-
withBlock(block: string): DeclarationBlock;
|
|
37
|
+
withBlock(block: string | null): DeclarationBlock;
|
|
38
38
|
withContent(content: string): DeclarationBlock;
|
|
39
39
|
withName(name: string | NameNode, generics?: string | null): DeclarationBlock;
|
|
40
40
|
get string(): string;
|
|
41
41
|
}
|
|
42
42
|
export declare function getBaseTypeNode(typeNode: TypeNode): NamedTypeNode;
|
|
43
43
|
export declare function buildScalarsFromConfig(schema: GraphQLSchema | undefined, config: RawConfig, defaultScalarsMapping?: NormalizedScalarsMap, defaultScalarType?: string): ParsedScalarsMap;
|
|
44
|
-
export declare function buildScalars(schema: GraphQLSchema | undefined, scalarsMapping: ScalarsMap, defaultScalarsMapping?: NormalizedScalarsMap, defaultScalarType?: string | null): ParsedScalarsMap;
|
|
44
|
+
export declare function buildScalars(schema: GraphQLSchema | undefined, scalarsMapping: ScalarsMap | undefined, defaultScalarsMapping?: NormalizedScalarsMap, defaultScalarType?: string | null): ParsedScalarsMap;
|
|
45
45
|
export declare function stripMapperTypeInterpolation(identifier: string): string;
|
|
46
46
|
export declare const OMIT_TYPE = "export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;";
|
|
47
47
|
export declare const REQUIRE_FIELDS_TYPE = "export type RequireFields<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: NonNullable<T[P]> };";
|
|
@@ -19,8 +19,8 @@ export declare class OperationVariablesToObject {
|
|
|
19
19
|
protected _applyCoercion: boolean;
|
|
20
20
|
protected _directiveArgumentAndInputFieldMappings: ParsedDirectiveArgumentAndInputFieldMappings;
|
|
21
21
|
constructor(_scalars: NormalizedScalarsMap, _convertName: ConvertNameFn<BaseVisitorConvertOptions>, _namespacedImportName?: string | null, _enumNames?: string[], _enumPrefix?: boolean, _enumSuffix?: boolean, _enumValues?: ParsedEnumValuesMap, _applyCoercion?: boolean, _directiveArgumentAndInputFieldMappings?: ParsedDirectiveArgumentAndInputFieldMappings);
|
|
22
|
-
getName<TDefinitionType extends InterfaceOrVariable>(node: TDefinitionType): string;
|
|
23
|
-
transform<TDefinitionType extends InterfaceOrVariable>(variablesNode: ReadonlyArray<TDefinitionType> | undefined): string;
|
|
22
|
+
getName<TDefinitionType extends InterfaceOrVariable>(node: TDefinitionType): string | null;
|
|
23
|
+
transform<TDefinitionType extends InterfaceOrVariable>(variablesNode: ReadonlyArray<TDefinitionType> | undefined): string | null;
|
|
24
24
|
protected getScalar(name: string): string;
|
|
25
25
|
protected getDirectiveMapping(name: string): string;
|
|
26
26
|
protected getDirectiveOverrideType(directives: ReadonlyArray<DirectiveNode>): string | null;
|
|
@@ -19,8 +19,8 @@ export declare class OperationVariablesToObject {
|
|
|
19
19
|
protected _applyCoercion: boolean;
|
|
20
20
|
protected _directiveArgumentAndInputFieldMappings: ParsedDirectiveArgumentAndInputFieldMappings;
|
|
21
21
|
constructor(_scalars: NormalizedScalarsMap, _convertName: ConvertNameFn<BaseVisitorConvertOptions>, _namespacedImportName?: string | null, _enumNames?: string[], _enumPrefix?: boolean, _enumSuffix?: boolean, _enumValues?: ParsedEnumValuesMap, _applyCoercion?: boolean, _directiveArgumentAndInputFieldMappings?: ParsedDirectiveArgumentAndInputFieldMappings);
|
|
22
|
-
getName<TDefinitionType extends InterfaceOrVariable>(node: TDefinitionType): string;
|
|
23
|
-
transform<TDefinitionType extends InterfaceOrVariable>(variablesNode: ReadonlyArray<TDefinitionType> | undefined): string;
|
|
22
|
+
getName<TDefinitionType extends InterfaceOrVariable>(node: TDefinitionType): string | null;
|
|
23
|
+
transform<TDefinitionType extends InterfaceOrVariable>(variablesNode: ReadonlyArray<TDefinitionType> | undefined): string | null;
|
|
24
24
|
protected getScalar(name: string): string;
|
|
25
25
|
protected getDirectiveMapping(name: string): string;
|
|
26
26
|
protected getDirectiveOverrideType(directives: ReadonlyArray<DirectiveNode>): string | null;
|