@graphql-codegen/visitor-plugin-common 6.0.0-alpha-20250816104654-3cefeabda1bcfa915d43b4515cb86dd2dfb9df5b → 6.0.0-alpha-20250827103001-1f42d2b3d7d1c009e2fc2ed9b513fdda20e78b50

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.
@@ -60,7 +60,7 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
60
60
  directiveContextTypes: (0, utils_js_1.getConfigValue)(rawConfig.directiveContextTypes, []),
61
61
  resolverTypeSuffix: (0, utils_js_1.getConfigValue)(rawConfig.resolverTypeSuffix, 'Resolvers'),
62
62
  allResolversTypeName: (0, utils_js_1.getConfigValue)(rawConfig.allResolversTypeName, 'Resolvers'),
63
- rootValueType: (0, mappers_js_1.parseMapper)(rawConfig.rootValueType || '{}', 'RootValueType'),
63
+ rootValueType: (0, mappers_js_1.parseMapper)(rawConfig.rootValueType || 'Record<PropertyKey, never>', 'RootValueType'),
64
64
  namespacedImportName: (0, utils_js_1.getConfigValue)(rawConfig.namespacedImportName, ''),
65
65
  avoidOptionals: (0, avoid_optionals_js_1.normalizeAvoidOptionals)(rawConfig.avoidOptionals),
66
66
  defaultMapper: rawConfig.defaultMapper
@@ -129,7 +129,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
129
129
  .export()
130
130
  .asKind(this._parsedConfig.declarationKind.input)
131
131
  .withName(this.convertName(node))
132
- .withComment(node.description)
132
+ .withComment(node.description?.value)
133
133
  .withBlock(node.fields.join('\n'));
134
134
  }
135
135
  getInputObjectOneOfDeclarationBlock(node) {
@@ -140,14 +140,13 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
140
140
  .export()
141
141
  .asKind(declarationKind)
142
142
  .withName(this.convertName(node))
143
- .withComment(node.description)
143
+ .withComment(node.description?.value)
144
144
  .withContent(`\n` + node.fields.join('\n |'));
145
145
  }
146
146
  InputObjectTypeDefinition(node) {
147
147
  if (this.config.onlyEnums)
148
148
  return '';
149
- // Why the heck is node.name a string and not { value: string } at runtime ?!
150
- if ((0, utils_js_1.isOneOfInputObjectType)(this._schema.getType(node.name))) {
149
+ if ((0, utils_js_1.isOneOfInputObjectType)(this._schema.getType(node.name.value))) {
151
150
  return this.getInputObjectOneOfDeclarationBlock(node).string;
152
151
  }
153
152
  return this.getInputObjectDeclarationBlock(node).string;
@@ -155,16 +154,13 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
155
154
  InputValueDefinition(node) {
156
155
  if (this.config.onlyEnums)
157
156
  return '';
158
- const comment = (0, utils_js_1.transformComment)(node.description, 1);
157
+ const comment = (0, utils_js_1.transformComment)(node.description.value, 1);
159
158
  const { input } = this._parsedConfig.declarationKind;
160
159
  let type = node.type;
161
160
  if (node.directives && this.config.directiveArgumentAndInputFieldMappings) {
162
161
  type = this._getDirectiveOverrideType(node.directives) || type;
163
162
  }
164
- return comment + (0, utils_js_1.indent)(`${node.name}: ${type}${this.getPunctuation(input)}`);
165
- }
166
- Name(node) {
167
- return node.value;
163
+ return comment + (0, utils_js_1.indent)(`${node.name.value}: ${type}${this.getPunctuation(input)}`);
168
164
  }
169
165
  FieldDefinition(node) {
170
166
  if (this.config.onlyEnums)
@@ -172,7 +168,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
172
168
  const typeString = node.type;
173
169
  const { type } = this._parsedConfig.declarationKind;
174
170
  const comment = this.getNodeComment(node);
175
- return comment + (0, utils_js_1.indent)(`${node.name}: ${typeString}${this.getPunctuation(type)}`);
171
+ return comment + (0, utils_js_1.indent)(`${node.name.value}: ${typeString}${this.getPunctuation(type)}`);
176
172
  }
177
173
  UnionTypeDefinition(node, key, parent) {
178
174
  if (this.config.onlyOperationTypes || this.config.onlyEnums)
@@ -185,7 +181,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
185
181
  .export()
186
182
  .asKind('type')
187
183
  .withName(this.convertName(node))
188
- .withComment(node.description)
184
+ .withComment(node.description.value)
189
185
  .withContent(possibleTypes).string;
190
186
  }
191
187
  mergeInterfaces(interfaces, hasOtherFields) {
@@ -201,7 +197,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
201
197
  const allFields = [
202
198
  ...(this.config.addTypename
203
199
  ? [
204
- (0, utils_js_1.indent)(`${this.config.immutableTypes ? 'readonly ' : ''}${optionalTypename}: '${node.name}'${this.getPunctuation(type)}`),
200
+ (0, utils_js_1.indent)(`${this.config.immutableTypes ? 'readonly ' : ''}${optionalTypename}: '${node.name.value}'${this.getPunctuation(type)}`),
205
201
  ]
206
202
  : []),
207
203
  ...node.fields,
@@ -211,7 +207,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
211
207
  .export()
212
208
  .asKind(type)
213
209
  .withName(this.convertName(node))
214
- .withComment(node.description);
210
+ .withComment(node.description?.value);
215
211
  if (type === 'interface' || type === 'class') {
216
212
  if (interfacesNames.length > 0) {
217
213
  const keyword = interfacesType === 'interface' && type === 'class' ? 'implements' : 'extends';
@@ -240,7 +236,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
240
236
  .export()
241
237
  .asKind(this._parsedConfig.declarationKind.interface)
242
238
  .withName(this.convertName(node))
243
- .withComment(node.description);
239
+ .withComment(node.description?.value);
244
240
  return declarationBlock.withBlock(node.fields.join('\n'));
245
241
  }
246
242
  InterfaceTypeDefinition(node, key, parent) {
@@ -294,7 +290,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
294
290
  .filter(Boolean);
295
291
  }
296
292
  EnumTypeDefinition(node) {
297
- const enumName = node.name;
293
+ const enumName = node.name.value;
298
294
  // In case of mapped external enum string
299
295
  if (this.config.enumValues[enumName]?.sourceFile) {
300
296
  return null;
@@ -306,13 +302,9 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
306
302
  useTypesPrefix: this.config.enumPrefix,
307
303
  useTypesSuffix: this.config.enumSuffix,
308
304
  }))
309
- .withComment(node.description)
305
+ .withComment(node.description.value)
310
306
  .withBlock(this.buildEnumValuesBlock(enumName, node.values)).string;
311
307
  }
312
- // We are using it in order to transform "description" field
313
- StringValue(node) {
314
- return node.value;
315
- }
316
308
  makeValidEnumIdentifier(identifier) {
317
309
  if (/^[0-9]/.exec(identifier)) {
318
310
  return (0, utils_js_1.wrapWithSingleQuotes)(identifier, true);
@@ -331,9 +323,9 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
331
323
  }));
332
324
  const comment = this.getNodeComment(enumOption);
333
325
  const schemaEnumValue = schemaEnumType && !this.config.ignoreEnumValuesFromSchema
334
- ? schemaEnumType.getValue(enumOption.name).value
326
+ ? schemaEnumType.getValue(enumOption.name.value).value
335
327
  : undefined;
336
- let enumValue = typeof schemaEnumValue === 'undefined' ? enumOption.name : schemaEnumValue;
328
+ let enumValue = typeof schemaEnumValue === 'undefined' ? enumOption.name.value : schemaEnumValue;
337
329
  if (typeof this.config.enumValues[typeName]?.mappedValues?.[enumValue] !== 'undefined') {
338
330
  enumValue = this.config.enumValues[typeName].mappedValues[enumValue];
339
331
  }
@@ -350,7 +342,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
350
342
  .export()
351
343
  .asKind(this._parsedConfig.declarationKind.arguments)
352
344
  .withName(this.convertName(name))
353
- .withComment(node.description)
345
+ .withComment(node.description?.value)
354
346
  .withBlock(this._argumentsTransformer.transform(field.arguments));
355
347
  }
356
348
  getArgumentsObjectTypeDefinition(node, name, field) {
@@ -382,7 +374,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
382
374
  _getDirectiveOverrideType(directives) {
383
375
  const type = directives
384
376
  .map(directive => {
385
- const directiveName = directive.name;
377
+ const directiveName = directive.name.value;
386
378
  if (this.config.directiveArgumentAndInputFieldMappings[directiveName]) {
387
379
  return this._getDirectiveArgumentNadInputFieldMapping(directiveName);
388
380
  }
@@ -393,14 +385,14 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
393
385
  return type || null;
394
386
  }
395
387
  _getTypeForNode(node, isVisitingInputType) {
396
- const typeAsString = node.name;
388
+ const typeAsString = node.name.value;
397
389
  if (this.scalars[typeAsString]) {
398
390
  return this._getScalar(typeAsString, isVisitingInputType ? 'input' : 'output');
399
391
  }
400
392
  if (this.config.enumValues[typeAsString]) {
401
393
  return this.config.enumValues[typeAsString].typeIdentifier;
402
394
  }
403
- const schemaType = this._schema.getType(node.name);
395
+ const schemaType = this._schema.getType(typeAsString);
404
396
  if (schemaType && (0, graphql_1.isEnumType)(schemaType)) {
405
397
  return this.convertName(node, {
406
398
  useTypesPrefix: this.config.enumPrefix,
@@ -426,8 +418,8 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
426
418
  return null;
427
419
  }
428
420
  getNodeComment(node) {
429
- let commentText = node.description;
430
- const deprecationDirective = node.directives.find((v) => v.name === 'deprecated');
421
+ let commentText = node.description?.value;
422
+ const deprecationDirective = node.directives.find(v => v.name.value === 'deprecated');
431
423
  if (deprecationDirective) {
432
424
  const deprecationReason = this.getDeprecationReason(deprecationDirective);
433
425
  commentText = `${commentText ? `${commentText}\n` : ''}@deprecated ${deprecationReason}`;
@@ -436,11 +428,11 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
436
428
  return comment;
437
429
  }
438
430
  getDeprecationReason(directive) {
439
- if (directive.name === 'deprecated') {
440
- const hasArguments = directive.arguments.length > 0;
431
+ if (directive.name.value === 'deprecated') {
441
432
  let reason = 'Field no longer supported';
442
- if (hasArguments) {
443
- reason = directive.arguments[0].value;
433
+ const deprecatedReason = directive.arguments[0];
434
+ if (deprecatedReason && deprecatedReason.value.kind === graphql_1.Kind.STRING) {
435
+ reason = deprecatedReason.value.value;
444
436
  }
445
437
  return reason;
446
438
  }
@@ -18,7 +18,6 @@ class BaseVisitor {
18
18
  addTypename: !rawConfig.skipTypename,
19
19
  nonOptionalTypename: !!rawConfig.nonOptionalTypename,
20
20
  useTypeImports: !!rawConfig.useTypeImports,
21
- dedupeFragments: !!rawConfig.dedupeFragments,
22
21
  allowEnumStringTypes: !!rawConfig.allowEnumStringTypes,
23
22
  inlineFragmentTypes: rawConfig.inlineFragmentTypes ?? 'inline',
24
23
  emitLegacyCommonJSImports: rawConfig.emitLegacyCommonJSImports === undefined ? true : !!rawConfig.emitLegacyCommonJSImports,
@@ -48,12 +48,7 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
48
48
  documentVariableSuffix: (0, utils_js_1.getConfigValue)(rawConfig.documentVariableSuffix, 'Document'),
49
49
  fragmentVariablePrefix: (0, utils_js_1.getConfigValue)(rawConfig.fragmentVariablePrefix, ''),
50
50
  fragmentVariableSuffix: (0, utils_js_1.getConfigValue)(rawConfig.fragmentVariableSuffix, 'FragmentDoc'),
51
- documentMode: ((rawConfig) => {
52
- if (typeof rawConfig.noGraphQLTag === 'boolean') {
53
- return rawConfig.noGraphQLTag ? DocumentMode.documentNode : DocumentMode.graphQLTag;
54
- }
55
- return (0, utils_js_1.getConfigValue)(rawConfig.documentMode, DocumentMode.graphQLTag);
56
- })(rawConfig),
51
+ documentMode: (0, utils_js_1.getConfigValue)(rawConfig.documentMode, DocumentMode.graphQLTag),
57
52
  importDocumentNodeExternallyFrom: (0, utils_js_1.getConfigValue)(rawConfig.importDocumentNodeExternallyFrom, ''),
58
53
  pureMagicComment: (0, utils_js_1.getConfigValue)(rawConfig.pureMagicComment, false),
59
54
  experimentalFragmentVariables: (0, utils_js_1.getConfigValue)(rawConfig.experimentalFragmentVariables, false),
@@ -95,7 +90,7 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
95
90
  _transformFragments(fragmentNames) {
96
91
  return fragmentNames.map(document => this.getFragmentVariableName(document));
97
92
  }
98
- _includeFragments(fragments, nodeKind) {
93
+ _includeFragments(fragments) {
99
94
  if (fragments && fragments.length > 0) {
100
95
  if (this.config.documentMode === DocumentMode.documentNode || this.config.documentMode === DocumentMode.string) {
101
96
  return Array.from(this._fragments.values())
@@ -106,9 +101,6 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
106
101
  if (this.config.documentMode === DocumentMode.documentNodeImportFragments) {
107
102
  return '';
108
103
  }
109
- if (this.config.dedupeFragments && nodeKind !== 'OperationDefinition') {
110
- return '';
111
- }
112
104
  return String(fragments.map(name => '${' + name + '}').join('\n'));
113
105
  }
114
106
  return '';
@@ -117,14 +109,12 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
117
109
  return documentStr;
118
110
  }
119
111
  _gql(node) {
120
- const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode ||
121
- this.config.documentMode === DocumentMode.string ||
122
- (this.config.dedupeFragments && node.kind === 'OperationDefinition');
112
+ const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode || this.config.documentMode === DocumentMode.string;
123
113
  const fragmentNames = this._extractFragments(node, includeNestedFragments);
124
114
  const fragments = this._transformFragments(fragmentNames);
125
115
  const doc = this._prepareDocument(`
126
116
  ${(0, graphql_1.print)(node).split('\\').join('\\\\') /* Re-escape escaped values in GraphQL syntax */}
127
- ${this._includeFragments(fragments, node.kind)}`);
117
+ ${this._includeFragments(fragments)}`);
128
118
  if (this.config.documentMode === DocumentMode.documentNode) {
129
119
  let gqlObj = (0, graphql_tag_1.default)([doc]);
130
120
  if (this.config.optimizeDocumentNode) {
@@ -534,7 +534,7 @@ class SelectionSetToObject {
534
534
  return 'never';
535
535
  }
536
536
  getEmptyObjectType() {
537
- return `{}`;
537
+ return 'Record<PropertyKey, never>';
538
538
  }
539
539
  getEmptyObjectTypeString(mustAddEmptyObject) {
540
540
  return mustAddEmptyObject ? this.getEmptyObjectType() : ``;
@@ -56,7 +56,7 @@ export class BaseResolversVisitor extends BaseVisitor {
56
56
  directiveContextTypes: getConfigValue(rawConfig.directiveContextTypes, []),
57
57
  resolverTypeSuffix: getConfigValue(rawConfig.resolverTypeSuffix, 'Resolvers'),
58
58
  allResolversTypeName: getConfigValue(rawConfig.allResolversTypeName, 'Resolvers'),
59
- rootValueType: parseMapper(rawConfig.rootValueType || '{}', 'RootValueType'),
59
+ rootValueType: parseMapper(rawConfig.rootValueType || 'Record<PropertyKey, never>', 'RootValueType'),
60
60
  namespacedImportName: getConfigValue(rawConfig.namespacedImportName, ''),
61
61
  avoidOptionals: normalizeAvoidOptionals(rawConfig.avoidOptionals),
62
62
  defaultMapper: rawConfig.defaultMapper
@@ -126,7 +126,7 @@ export class BaseTypesVisitor extends BaseVisitor {
126
126
  .export()
127
127
  .asKind(this._parsedConfig.declarationKind.input)
128
128
  .withName(this.convertName(node))
129
- .withComment(node.description)
129
+ .withComment(node.description?.value)
130
130
  .withBlock(node.fields.join('\n'));
131
131
  }
132
132
  getInputObjectOneOfDeclarationBlock(node) {
@@ -137,14 +137,13 @@ export class BaseTypesVisitor extends BaseVisitor {
137
137
  .export()
138
138
  .asKind(declarationKind)
139
139
  .withName(this.convertName(node))
140
- .withComment(node.description)
140
+ .withComment(node.description?.value)
141
141
  .withContent(`\n` + node.fields.join('\n |'));
142
142
  }
143
143
  InputObjectTypeDefinition(node) {
144
144
  if (this.config.onlyEnums)
145
145
  return '';
146
- // Why the heck is node.name a string and not { value: string } at runtime ?!
147
- if (isOneOfInputObjectType(this._schema.getType(node.name))) {
146
+ if (isOneOfInputObjectType(this._schema.getType(node.name.value))) {
148
147
  return this.getInputObjectOneOfDeclarationBlock(node).string;
149
148
  }
150
149
  return this.getInputObjectDeclarationBlock(node).string;
@@ -152,16 +151,13 @@ export class BaseTypesVisitor extends BaseVisitor {
152
151
  InputValueDefinition(node) {
153
152
  if (this.config.onlyEnums)
154
153
  return '';
155
- const comment = transformComment(node.description, 1);
154
+ const comment = transformComment(node.description.value, 1);
156
155
  const { input } = this._parsedConfig.declarationKind;
157
156
  let type = node.type;
158
157
  if (node.directives && this.config.directiveArgumentAndInputFieldMappings) {
159
158
  type = this._getDirectiveOverrideType(node.directives) || type;
160
159
  }
161
- return comment + indent(`${node.name}: ${type}${this.getPunctuation(input)}`);
162
- }
163
- Name(node) {
164
- return node.value;
160
+ return comment + indent(`${node.name.value}: ${type}${this.getPunctuation(input)}`);
165
161
  }
166
162
  FieldDefinition(node) {
167
163
  if (this.config.onlyEnums)
@@ -169,7 +165,7 @@ export class BaseTypesVisitor extends BaseVisitor {
169
165
  const typeString = node.type;
170
166
  const { type } = this._parsedConfig.declarationKind;
171
167
  const comment = this.getNodeComment(node);
172
- return comment + indent(`${node.name}: ${typeString}${this.getPunctuation(type)}`);
168
+ return comment + indent(`${node.name.value}: ${typeString}${this.getPunctuation(type)}`);
173
169
  }
174
170
  UnionTypeDefinition(node, key, parent) {
175
171
  if (this.config.onlyOperationTypes || this.config.onlyEnums)
@@ -182,7 +178,7 @@ export class BaseTypesVisitor extends BaseVisitor {
182
178
  .export()
183
179
  .asKind('type')
184
180
  .withName(this.convertName(node))
185
- .withComment(node.description)
181
+ .withComment(node.description.value)
186
182
  .withContent(possibleTypes).string;
187
183
  }
188
184
  mergeInterfaces(interfaces, hasOtherFields) {
@@ -198,7 +194,7 @@ export class BaseTypesVisitor extends BaseVisitor {
198
194
  const allFields = [
199
195
  ...(this.config.addTypename
200
196
  ? [
201
- indent(`${this.config.immutableTypes ? 'readonly ' : ''}${optionalTypename}: '${node.name}'${this.getPunctuation(type)}`),
197
+ indent(`${this.config.immutableTypes ? 'readonly ' : ''}${optionalTypename}: '${node.name.value}'${this.getPunctuation(type)}`),
202
198
  ]
203
199
  : []),
204
200
  ...node.fields,
@@ -208,7 +204,7 @@ export class BaseTypesVisitor extends BaseVisitor {
208
204
  .export()
209
205
  .asKind(type)
210
206
  .withName(this.convertName(node))
211
- .withComment(node.description);
207
+ .withComment(node.description?.value);
212
208
  if (type === 'interface' || type === 'class') {
213
209
  if (interfacesNames.length > 0) {
214
210
  const keyword = interfacesType === 'interface' && type === 'class' ? 'implements' : 'extends';
@@ -237,7 +233,7 @@ export class BaseTypesVisitor extends BaseVisitor {
237
233
  .export()
238
234
  .asKind(this._parsedConfig.declarationKind.interface)
239
235
  .withName(this.convertName(node))
240
- .withComment(node.description);
236
+ .withComment(node.description?.value);
241
237
  return declarationBlock.withBlock(node.fields.join('\n'));
242
238
  }
243
239
  InterfaceTypeDefinition(node, key, parent) {
@@ -291,7 +287,7 @@ export class BaseTypesVisitor extends BaseVisitor {
291
287
  .filter(Boolean);
292
288
  }
293
289
  EnumTypeDefinition(node) {
294
- const enumName = node.name;
290
+ const enumName = node.name.value;
295
291
  // In case of mapped external enum string
296
292
  if (this.config.enumValues[enumName]?.sourceFile) {
297
293
  return null;
@@ -303,13 +299,9 @@ export class BaseTypesVisitor extends BaseVisitor {
303
299
  useTypesPrefix: this.config.enumPrefix,
304
300
  useTypesSuffix: this.config.enumSuffix,
305
301
  }))
306
- .withComment(node.description)
302
+ .withComment(node.description.value)
307
303
  .withBlock(this.buildEnumValuesBlock(enumName, node.values)).string;
308
304
  }
309
- // We are using it in order to transform "description" field
310
- StringValue(node) {
311
- return node.value;
312
- }
313
305
  makeValidEnumIdentifier(identifier) {
314
306
  if (/^[0-9]/.exec(identifier)) {
315
307
  return wrapWithSingleQuotes(identifier, true);
@@ -328,9 +320,9 @@ export class BaseTypesVisitor extends BaseVisitor {
328
320
  }));
329
321
  const comment = this.getNodeComment(enumOption);
330
322
  const schemaEnumValue = schemaEnumType && !this.config.ignoreEnumValuesFromSchema
331
- ? schemaEnumType.getValue(enumOption.name).value
323
+ ? schemaEnumType.getValue(enumOption.name.value).value
332
324
  : undefined;
333
- let enumValue = typeof schemaEnumValue === 'undefined' ? enumOption.name : schemaEnumValue;
325
+ let enumValue = typeof schemaEnumValue === 'undefined' ? enumOption.name.value : schemaEnumValue;
334
326
  if (typeof this.config.enumValues[typeName]?.mappedValues?.[enumValue] !== 'undefined') {
335
327
  enumValue = this.config.enumValues[typeName].mappedValues[enumValue];
336
328
  }
@@ -347,7 +339,7 @@ export class BaseTypesVisitor extends BaseVisitor {
347
339
  .export()
348
340
  .asKind(this._parsedConfig.declarationKind.arguments)
349
341
  .withName(this.convertName(name))
350
- .withComment(node.description)
342
+ .withComment(node.description?.value)
351
343
  .withBlock(this._argumentsTransformer.transform(field.arguments));
352
344
  }
353
345
  getArgumentsObjectTypeDefinition(node, name, field) {
@@ -379,7 +371,7 @@ export class BaseTypesVisitor extends BaseVisitor {
379
371
  _getDirectiveOverrideType(directives) {
380
372
  const type = directives
381
373
  .map(directive => {
382
- const directiveName = directive.name;
374
+ const directiveName = directive.name.value;
383
375
  if (this.config.directiveArgumentAndInputFieldMappings[directiveName]) {
384
376
  return this._getDirectiveArgumentNadInputFieldMapping(directiveName);
385
377
  }
@@ -390,14 +382,14 @@ export class BaseTypesVisitor extends BaseVisitor {
390
382
  return type || null;
391
383
  }
392
384
  _getTypeForNode(node, isVisitingInputType) {
393
- const typeAsString = node.name;
385
+ const typeAsString = node.name.value;
394
386
  if (this.scalars[typeAsString]) {
395
387
  return this._getScalar(typeAsString, isVisitingInputType ? 'input' : 'output');
396
388
  }
397
389
  if (this.config.enumValues[typeAsString]) {
398
390
  return this.config.enumValues[typeAsString].typeIdentifier;
399
391
  }
400
- const schemaType = this._schema.getType(node.name);
392
+ const schemaType = this._schema.getType(typeAsString);
401
393
  if (schemaType && isEnumType(schemaType)) {
402
394
  return this.convertName(node, {
403
395
  useTypesPrefix: this.config.enumPrefix,
@@ -423,8 +415,8 @@ export class BaseTypesVisitor extends BaseVisitor {
423
415
  return null;
424
416
  }
425
417
  getNodeComment(node) {
426
- let commentText = node.description;
427
- const deprecationDirective = node.directives.find((v) => v.name === 'deprecated');
418
+ let commentText = node.description?.value;
419
+ const deprecationDirective = node.directives.find(v => v.name.value === 'deprecated');
428
420
  if (deprecationDirective) {
429
421
  const deprecationReason = this.getDeprecationReason(deprecationDirective);
430
422
  commentText = `${commentText ? `${commentText}\n` : ''}@deprecated ${deprecationReason}`;
@@ -433,11 +425,11 @@ export class BaseTypesVisitor extends BaseVisitor {
433
425
  return comment;
434
426
  }
435
427
  getDeprecationReason(directive) {
436
- if (directive.name === 'deprecated') {
437
- const hasArguments = directive.arguments.length > 0;
428
+ if (directive.name.value === 'deprecated') {
438
429
  let reason = 'Field no longer supported';
439
- if (hasArguments) {
440
- reason = directive.arguments[0].value;
430
+ const deprecatedReason = directive.arguments[0];
431
+ if (deprecatedReason && deprecatedReason.value.kind === Kind.STRING) {
432
+ reason = deprecatedReason.value.value;
441
433
  }
442
434
  return reason;
443
435
  }
@@ -14,7 +14,6 @@ export class BaseVisitor {
14
14
  addTypename: !rawConfig.skipTypename,
15
15
  nonOptionalTypename: !!rawConfig.nonOptionalTypename,
16
16
  useTypeImports: !!rawConfig.useTypeImports,
17
- dedupeFragments: !!rawConfig.dedupeFragments,
18
17
  allowEnumStringTypes: !!rawConfig.allowEnumStringTypes,
19
18
  inlineFragmentTypes: rawConfig.inlineFragmentTypes ?? 'inline',
20
19
  emitLegacyCommonJSImports: rawConfig.emitLegacyCommonJSImports === undefined ? true : !!rawConfig.emitLegacyCommonJSImports,
@@ -44,12 +44,7 @@ export class ClientSideBaseVisitor extends BaseVisitor {
44
44
  documentVariableSuffix: getConfigValue(rawConfig.documentVariableSuffix, 'Document'),
45
45
  fragmentVariablePrefix: getConfigValue(rawConfig.fragmentVariablePrefix, ''),
46
46
  fragmentVariableSuffix: getConfigValue(rawConfig.fragmentVariableSuffix, 'FragmentDoc'),
47
- documentMode: ((rawConfig) => {
48
- if (typeof rawConfig.noGraphQLTag === 'boolean') {
49
- return rawConfig.noGraphQLTag ? DocumentMode.documentNode : DocumentMode.graphQLTag;
50
- }
51
- return getConfigValue(rawConfig.documentMode, DocumentMode.graphQLTag);
52
- })(rawConfig),
47
+ documentMode: getConfigValue(rawConfig.documentMode, DocumentMode.graphQLTag),
53
48
  importDocumentNodeExternallyFrom: getConfigValue(rawConfig.importDocumentNodeExternallyFrom, ''),
54
49
  pureMagicComment: getConfigValue(rawConfig.pureMagicComment, false),
55
50
  experimentalFragmentVariables: getConfigValue(rawConfig.experimentalFragmentVariables, false),
@@ -91,7 +86,7 @@ export class ClientSideBaseVisitor extends BaseVisitor {
91
86
  _transformFragments(fragmentNames) {
92
87
  return fragmentNames.map(document => this.getFragmentVariableName(document));
93
88
  }
94
- _includeFragments(fragments, nodeKind) {
89
+ _includeFragments(fragments) {
95
90
  if (fragments && fragments.length > 0) {
96
91
  if (this.config.documentMode === DocumentMode.documentNode || this.config.documentMode === DocumentMode.string) {
97
92
  return Array.from(this._fragments.values())
@@ -102,9 +97,6 @@ export class ClientSideBaseVisitor extends BaseVisitor {
102
97
  if (this.config.documentMode === DocumentMode.documentNodeImportFragments) {
103
98
  return '';
104
99
  }
105
- if (this.config.dedupeFragments && nodeKind !== 'OperationDefinition') {
106
- return '';
107
- }
108
100
  return String(fragments.map(name => '${' + name + '}').join('\n'));
109
101
  }
110
102
  return '';
@@ -113,14 +105,12 @@ export class ClientSideBaseVisitor extends BaseVisitor {
113
105
  return documentStr;
114
106
  }
115
107
  _gql(node) {
116
- const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode ||
117
- this.config.documentMode === DocumentMode.string ||
118
- (this.config.dedupeFragments && node.kind === 'OperationDefinition');
108
+ const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode || this.config.documentMode === DocumentMode.string;
119
109
  const fragmentNames = this._extractFragments(node, includeNestedFragments);
120
110
  const fragments = this._transformFragments(fragmentNames);
121
111
  const doc = this._prepareDocument(`
122
112
  ${print(node).split('\\').join('\\\\') /* Re-escape escaped values in GraphQL syntax */}
123
- ${this._includeFragments(fragments, node.kind)}`);
113
+ ${this._includeFragments(fragments)}`);
124
114
  if (this.config.documentMode === DocumentMode.documentNode) {
125
115
  let gqlObj = gqlTag([doc]);
126
116
  if (this.config.optimizeDocumentNode) {
@@ -530,7 +530,7 @@ export class SelectionSetToObject {
530
530
  return 'never';
531
531
  }
532
532
  getEmptyObjectType() {
533
- return `{}`;
533
+ return 'Record<PropertyKey, never>';
534
534
  }
535
535
  getEmptyObjectTypeString(mustAddEmptyObject) {
536
536
  return mustAddEmptyObject ? this.getEmptyObjectType() : ``;
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-codegen/visitor-plugin-common",
3
- "version": "6.0.0-alpha-20250816104654-3cefeabda1bcfa915d43b4515cb86dd2dfb9df5b",
3
+ "version": "6.0.0-alpha-20250827103001-1f42d2b3d7d1c009e2fc2ed9b513fdda20e78b50",
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
  },
7
7
  "dependencies": {
8
8
  "@graphql-tools/optimize": "^2.0.0",
9
- "@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250816104654-3cefeabda1bcfa915d43b4515cb86dd2dfb9df5b",
9
+ "@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250827103001-1f42d2b3d7d1c009e2fc2ed9b513fdda20e78b50",
10
10
  "@graphql-tools/relay-operation-optimizer": "^7.0.0",
11
11
  "@graphql-tools/utils": "^10.0.0",
12
- "auto-bind": "~4.0.0",
12
+ "auto-bind": "^5.0.0",
13
13
  "dependency-graph": "^1.0.0",
14
14
  "graphql-tag": "^2.11.0",
15
15
  "parse-filepath": "^1.0.2",
@@ -1,4 +1,4 @@
1
- import { DirectiveDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NameNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, StringValueNode, UnionTypeDefinitionNode } from 'graphql';
1
+ import { DirectiveDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode } from 'graphql';
2
2
  import { BaseVisitor, ParsedConfig, RawConfig } from './base-visitor.cjs';
3
3
  import { DeclarationKind, DeclarationKindConfig, DirectiveArgumentAndInputFieldMappings, EnumValuesMap, NormalizedScalarsMap, ParsedDirectiveArgumentAndInputFieldMappings, ParsedEnumValuesMap } from './types.cjs';
4
4
  import { DeclarationBlock, DeclarationBlockConfig } from './utils.cjs';
@@ -468,7 +468,6 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
468
468
  getInputObjectOneOfDeclarationBlock(node: InputObjectTypeDefinitionNode): DeclarationBlock;
469
469
  InputObjectTypeDefinition(node: InputObjectTypeDefinitionNode): string;
470
470
  InputValueDefinition(node: InputValueDefinitionNode): string;
471
- Name(node: NameNode): string;
472
471
  FieldDefinition(node: FieldDefinitionNode): string;
473
472
  UnionTypeDefinition(node: UnionTypeDefinitionNode, key: string | number | undefined, parent: any): string;
474
473
  protected mergeInterfaces(interfaces: string[], hasOtherFields: boolean): string;
@@ -483,7 +482,6 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
483
482
  protected handleEnumValueMapper(typeIdentifier: string, importIdentifier: string | null, sourceIdentifier: string | null, sourceFile: string | null): string[];
484
483
  getEnumsImports(): string[];
485
484
  EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
486
- StringValue(node: StringValueNode): string;
487
485
  protected makeValidEnumIdentifier(identifier: string): string;
488
486
  protected buildEnumValuesBlock(typeName: string, values: ReadonlyArray<EnumValueDefinitionNode>): string;
489
487
  DirectiveDefinition(_node: DirectiveDefinitionNode): string;
@@ -1,4 +1,4 @@
1
- import { DirectiveDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NameNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, StringValueNode, UnionTypeDefinitionNode } from 'graphql';
1
+ import { DirectiveDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode } from 'graphql';
2
2
  import { BaseVisitor, ParsedConfig, RawConfig } from './base-visitor.js';
3
3
  import { DeclarationKind, DeclarationKindConfig, DirectiveArgumentAndInputFieldMappings, EnumValuesMap, NormalizedScalarsMap, ParsedDirectiveArgumentAndInputFieldMappings, ParsedEnumValuesMap } from './types.js';
4
4
  import { DeclarationBlock, DeclarationBlockConfig } from './utils.js';
@@ -468,7 +468,6 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
468
468
  getInputObjectOneOfDeclarationBlock(node: InputObjectTypeDefinitionNode): DeclarationBlock;
469
469
  InputObjectTypeDefinition(node: InputObjectTypeDefinitionNode): string;
470
470
  InputValueDefinition(node: InputValueDefinitionNode): string;
471
- Name(node: NameNode): string;
472
471
  FieldDefinition(node: FieldDefinitionNode): string;
473
472
  UnionTypeDefinition(node: UnionTypeDefinitionNode, key: string | number | undefined, parent: any): string;
474
473
  protected mergeInterfaces(interfaces: string[], hasOtherFields: boolean): string;
@@ -483,7 +482,6 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
483
482
  protected handleEnumValueMapper(typeIdentifier: string, importIdentifier: string | null, sourceIdentifier: string | null, sourceFile: string | null): string[];
484
483
  getEnumsImports(): string[];
485
484
  EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
486
- StringValue(node: StringValueNode): string;
487
485
  protected makeValidEnumIdentifier(identifier: string): string;
488
486
  protected buildEnumValuesBlock(typeName: string, values: ReadonlyArray<EnumValueDefinitionNode>): string;
489
487
  DirectiveDefinition(_node: DirectiveDefinitionNode): string;
@@ -19,7 +19,6 @@ export interface ParsedConfig {
19
19
  fragmentImports: ImportDeclaration<FragmentImport>[];
20
20
  immutableTypes: boolean;
21
21
  useTypeImports: boolean;
22
- dedupeFragments: boolean;
23
22
  allowEnumStringTypes: boolean;
24
23
  inlineFragmentTypes: InlineFragmentTypeOptions;
25
24
  emitLegacyCommonJSImports: boolean;
@@ -329,15 +328,6 @@ export interface RawConfig {
329
328
  * @ignore
330
329
  */
331
330
  globalNamespace?: boolean;
332
- /**
333
- * @description Removes fragment duplicates for reducing data transfer.
334
- * It is done by removing sub-fragments imports from fragment definition
335
- * Instead - all of them are imported to the Operation node.
336
- * @type boolean
337
- * @default false
338
- * @deprecated This option is no longer needed. It will be removed in the next major version.
339
- */
340
- dedupeFragments?: boolean;
341
331
  /**
342
332
  * @ignore
343
333
  */
@@ -19,7 +19,6 @@ export interface ParsedConfig {
19
19
  fragmentImports: ImportDeclaration<FragmentImport>[];
20
20
  immutableTypes: boolean;
21
21
  useTypeImports: boolean;
22
- dedupeFragments: boolean;
23
22
  allowEnumStringTypes: boolean;
24
23
  inlineFragmentTypes: InlineFragmentTypeOptions;
25
24
  emitLegacyCommonJSImports: boolean;
@@ -329,15 +328,6 @@ export interface RawConfig {
329
328
  * @ignore
330
329
  */
331
330
  globalNamespace?: boolean;
332
- /**
333
- * @description Removes fragment duplicates for reducing data transfer.
334
- * It is done by removing sub-fragments imports from fragment definition
335
- * Instead - all of them are imported to the Operation node.
336
- * @type boolean
337
- * @default false
338
- * @deprecated This option is no longer needed. It will be removed in the next major version.
339
- */
340
- dedupeFragments?: boolean;
341
331
  /**
342
332
  * @ignore
343
333
  */
@@ -10,11 +10,6 @@ export declare enum DocumentMode {
10
10
  string = "string"
11
11
  }
12
12
  export interface RawClientSideBasePluginConfig extends RawConfig {
13
- /**
14
- * @description Deprecated. Changes the documentMode to `documentNode`.
15
- * @default false
16
- */
17
- noGraphQLTag?: boolean;
18
13
  /**
19
14
  * @default graphql-tag#gql
20
15
  * @description Customize from which module will `gql` be imported from.
@@ -224,7 +219,7 @@ export declare class ClientSideBaseVisitor<TRawConfig extends RawClientSideBaseP
224
219
  constructor(_schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: TRawConfig, additionalConfig: Partial<TPluginConfig>, documents?: Types.DocumentFile[]);
225
220
  protected _extractFragments(document: FragmentDefinitionNode | OperationDefinitionNode, withNested?: boolean): string[];
226
221
  protected _transformFragments(fragmentNames: Array<string>): string[];
227
- protected _includeFragments(fragments: string[], nodeKind: 'FragmentDefinition' | 'OperationDefinition'): string;
222
+ protected _includeFragments(fragments: string[]): string;
228
223
  protected _prepareDocument(documentStr: string): string;
229
224
  protected _gql(node: FragmentDefinitionNode | OperationDefinitionNode): string;
230
225
  protected _getGraphQLCodegenMetadata(node: OperationDefinitionNode, definitions?: ReadonlyArray<DefinitionNode>): Record<string, any> | void | undefined;
@@ -10,11 +10,6 @@ export declare enum DocumentMode {
10
10
  string = "string"
11
11
  }
12
12
  export interface RawClientSideBasePluginConfig extends RawConfig {
13
- /**
14
- * @description Deprecated. Changes the documentMode to `documentNode`.
15
- * @default false
16
- */
17
- noGraphQLTag?: boolean;
18
13
  /**
19
14
  * @default graphql-tag#gql
20
15
  * @description Customize from which module will `gql` be imported from.
@@ -224,7 +219,7 @@ export declare class ClientSideBaseVisitor<TRawConfig extends RawClientSideBaseP
224
219
  constructor(_schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: TRawConfig, additionalConfig: Partial<TPluginConfig>, documents?: Types.DocumentFile[]);
225
220
  protected _extractFragments(document: FragmentDefinitionNode | OperationDefinitionNode, withNested?: boolean): string[];
226
221
  protected _transformFragments(fragmentNames: Array<string>): string[];
227
- protected _includeFragments(fragments: string[], nodeKind: 'FragmentDefinition' | 'OperationDefinition'): string;
222
+ protected _includeFragments(fragments: string[]): string;
228
223
  protected _prepareDocument(documentStr: string): string;
229
224
  protected _gql(node: FragmentDefinitionNode | OperationDefinitionNode): string;
230
225
  protected _getGraphQLCodegenMetadata(node: OperationDefinitionNode, definitions?: ReadonlyArray<DefinitionNode>): Record<string, any> | void | undefined;