@graphql-codegen/visitor-plugin-common 6.2.0 → 7.0.0-alpha-20251125123407-8babe46fb9b33e9f9a377cd50c9580282e7981d3

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.
@@ -175,17 +175,15 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
175
175
  const isMapped = this.config.mappers[typeName];
176
176
  const isScalar = this.config.scalars[typeName];
177
177
  const hasDefaultMapper = !!this.config.defaultMapper?.type;
178
- // Check for mappers first, even for root types, to allow overriding rootValueType
179
- if (isMapped && this.config.mappers[typeName].type && !hasPlaceholder(this.config.mappers[typeName].type)) {
180
- this.markMapperAsUsed(typeName);
181
- prev[typeName] = applyWrapper(this.config.mappers[typeName].type);
182
- return prev;
183
- }
184
178
  if (isRootType) {
185
179
  prev[typeName] = applyWrapper(this.config.rootValueType.type);
186
180
  return prev;
187
181
  }
188
- if ((0, graphql_1.isEnumType)(schemaType) && this.config.enumValues[typeName]) {
182
+ if (isMapped && this.config.mappers[typeName].type && !hasPlaceholder(this.config.mappers[typeName].type)) {
183
+ this.markMapperAsUsed(typeName);
184
+ prev[typeName] = applyWrapper(this.config.mappers[typeName].type);
185
+ }
186
+ else if ((0, graphql_1.isEnumType)(schemaType) && this.config.enumValues[typeName]) {
189
187
  const isExternalFile = !!this.config.enumValues[typeName].sourceFile;
190
188
  prev[typeName] = isExternalFile
191
189
  ? this.convertName(this.config.enumValues[typeName].typeIdentifier, {
@@ -9,7 +9,7 @@ const mappers_js_1 = require("./mappers.js");
9
9
  const scalars_js_1 = require("./scalars.js");
10
10
  const utils_js_1 = require("./utils.js");
11
11
  const variables_to_object_js_1 = require("./variables-to-object.js");
12
- const onlyUnderscoresPattern = /^_+$/;
12
+ const convert_schema_enum_to_declaration_block_string_js_1 = require("./convert-schema-enum-to-declaration-block-string.js");
13
13
  class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
14
14
  _schema;
15
15
  _argumentsTransformer;
@@ -168,7 +168,7 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
168
168
  return '';
169
169
  const typeString = node.type;
170
170
  const { type } = this._parsedConfig.declarationKind;
171
- const comment = this.getNodeComment(node);
171
+ const comment = (0, utils_js_1.getNodeComment)(node);
172
172
  return comment + (0, utils_js_1.indent)(`${node.name.value}: ${typeString}${this.getPunctuation(type)}`);
173
173
  }
174
174
  UnionTypeDefinition(node, key, parent) {
@@ -304,7 +304,21 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
304
304
  useTypesSuffix: this.config.enumSuffix,
305
305
  }))
306
306
  .withComment(node.description.value)
307
- .withBlock(this.buildEnumValuesBlock(enumName, node.values)).string;
307
+ .withBlock((0, convert_schema_enum_to_declaration_block_string_js_1.buildEnumValuesBlock)({
308
+ typeName: enumName,
309
+ values: node.values,
310
+ schema: this._schema,
311
+ naming: {
312
+ convert: this.config.convert,
313
+ typesPrefix: this.config.typesPrefix,
314
+ useTypesPrefix: this.config.enumPrefix,
315
+ typesSuffix: this.config.typesSuffix,
316
+ useTypesSuffix: this.config.enumSuffix,
317
+ },
318
+ ignoreEnumValuesFromSchema: this.config.ignoreEnumValuesFromSchema,
319
+ declarationBlockConfig: this._declarationBlockConfig,
320
+ enumValues: this.config.enumValues,
321
+ })).string;
308
322
  }
309
323
  makeValidEnumIdentifier(identifier) {
310
324
  if (/^[0-9]/.exec(identifier)) {
@@ -312,31 +326,6 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
312
326
  }
313
327
  return identifier;
314
328
  }
315
- buildEnumValuesBlock(typeName, values) {
316
- const schemaEnumType = this._schema
317
- ? this._schema.getType(typeName)
318
- : undefined;
319
- return values
320
- .map(enumOption => {
321
- const optionName = this.makeValidEnumIdentifier(this.convertName(enumOption, {
322
- useTypesPrefix: false,
323
- // We can only strip out the underscores if the value contains other
324
- // characters. Otherwise we'll generate syntactically invalid code.
325
- transformUnderscore: !onlyUnderscoresPattern.test(enumOption.name.value),
326
- }));
327
- const comment = this.getNodeComment(enumOption);
328
- const schemaEnumValue = schemaEnumType && !this.config.ignoreEnumValuesFromSchema
329
- ? schemaEnumType.getValue(enumOption.name.value).value
330
- : undefined;
331
- let enumValue = typeof schemaEnumValue === 'undefined' ? enumOption.name.value : schemaEnumValue;
332
- if (typeof this.config.enumValues[typeName]?.mappedValues?.[enumValue] !== 'undefined') {
333
- enumValue = this.config.enumValues[typeName].mappedValues[enumValue];
334
- }
335
- return (comment +
336
- (0, utils_js_1.indent)(`${optionName}${this._declarationBlockConfig.enumNameValueSeparator} ${(0, utils_js_1.wrapWithSingleQuotes)(enumValue, typeof schemaEnumValue !== 'undefined')}`));
337
- })
338
- .join(',\n');
339
- }
340
329
  DirectiveDefinition(_node) {
341
330
  return '';
342
331
  }
@@ -423,26 +412,6 @@ class BaseTypesVisitor extends base_visitor_js_1.BaseVisitor {
423
412
  SchemaExtension() {
424
413
  return null;
425
414
  }
426
- getNodeComment(node) {
427
- let commentText = node.description?.value;
428
- const deprecationDirective = node.directives.find(v => v.name.value === 'deprecated');
429
- if (deprecationDirective) {
430
- const deprecationReason = this.getDeprecationReason(deprecationDirective);
431
- commentText = `${commentText ? `${commentText}\n` : ''}@deprecated ${deprecationReason}`;
432
- }
433
- const comment = (0, utils_js_1.transformComment)(commentText, 1);
434
- return comment;
435
- }
436
- getDeprecationReason(directive) {
437
- if (directive.name.value === 'deprecated') {
438
- let reason = 'Field no longer supported';
439
- const deprecatedReason = directive.arguments[0];
440
- if (deprecatedReason && deprecatedReason.value.kind === graphql_1.Kind.STRING) {
441
- reason = deprecatedReason.value.value;
442
- }
443
- return reason;
444
- }
445
- }
446
415
  wrapWithListType(str) {
447
416
  return `Array<${str}>`;
448
417
  }
@@ -4,16 +4,11 @@ exports.BaseVisitor = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
6
6
  const naming_js_1 = require("./naming.js");
7
- const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
8
7
  class BaseVisitor {
9
8
  _parsedConfig;
10
9
  _declarationBlockConfig = {};
11
10
  scalars;
12
11
  constructor(rawConfig, additionalConfig) {
13
- const importExtension = (0, plugin_helpers_1.normalizeImportExtension)({
14
- emitLegacyCommonJSImports: rawConfig.emitLegacyCommonJSImports,
15
- importExtension: rawConfig.importExtension,
16
- });
17
12
  this._parsedConfig = {
18
13
  convert: (0, naming_js_1.convertFactory)(rawConfig),
19
14
  typesPrefix: rawConfig.typesPrefix || '',
@@ -25,8 +20,7 @@ class BaseVisitor {
25
20
  useTypeImports: !!rawConfig.useTypeImports,
26
21
  allowEnumStringTypes: !!rawConfig.allowEnumStringTypes,
27
22
  inlineFragmentTypes: rawConfig.inlineFragmentTypes ?? 'inline',
28
- emitLegacyCommonJSImports: rawConfig.emitLegacyCommonJSImports ?? true,
29
- importExtension,
23
+ emitLegacyCommonJSImports: rawConfig.emitLegacyCommonJSImports === undefined ? true : !!rawConfig.emitLegacyCommonJSImports,
30
24
  extractAllFieldsToTypes: rawConfig.extractAllFieldsToTypes ?? false,
31
25
  printFieldsOnNewLines: rawConfig.printFieldsOnNewLines ?? false,
32
26
  includeExternalFragments: rawConfig.includeExternalFragments ?? false,
@@ -296,11 +296,7 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
296
296
  }
297
297
  clearExtension(path) {
298
298
  const extension = (0, path_1.extname)(path);
299
- const importExtension = (0, plugin_helpers_1.normalizeImportExtension)({
300
- emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
301
- importExtension: this.config.importExtension,
302
- });
303
- if (extension === importExtension) {
299
+ if (!this.config.emitLegacyCommonJSImports && extension === '.js') {
304
300
  return path;
305
301
  }
306
302
  if (EXTENSIONS_TO_REMOVE.includes(extension)) {
@@ -334,10 +330,9 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
334
330
  if (this._collectedOperations.length > 0) {
335
331
  if (this.config.importDocumentNodeExternallyFrom === 'near-operation-file' && this._documents.length === 1) {
336
332
  let documentPath = `./${this.clearExtension((0, path_1.basename)(this._documents[0].location))}`;
337
- documentPath += (0, plugin_helpers_1.normalizeImportExtension)({
338
- emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
339
- importExtension: this.config.importExtension,
340
- });
333
+ if (!this.config.emitLegacyCommonJSImports) {
334
+ documentPath += '.js';
335
+ }
341
336
  this._imports.add(`import * as Operations from '${documentPath}';`);
342
337
  }
343
338
  else {
@@ -355,10 +350,6 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
355
350
  }
356
351
  const excludeFragments = options.excludeFragments || this.config.globalNamespace || this.config.documentMode !== DocumentMode.graphQLTag;
357
352
  if (!excludeFragments) {
358
- const importExtension = (0, plugin_helpers_1.normalizeImportExtension)({
359
- emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
360
- importExtension: this.config.importExtension,
361
- });
362
353
  const deduplicatedImports = Object.values((0, utils_js_1.groupBy)(this.config.fragmentImports, fi => fi.importSource.path))
363
354
  .map((fragmentImports) => ({
364
355
  ...fragmentImports[0],
@@ -367,7 +358,6 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
367
358
  identifiers: (0, utils_js_1.unique)((0, utils_js_1.flatten)(fragmentImports.map(fi => fi.importSource.identifiers)), identifier => identifier.name),
368
359
  },
369
360
  emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
370
- importExtension,
371
361
  }))
372
362
  .filter(fragmentImport => fragmentImport.outputPath !== fragmentImport.importSource.path);
373
363
  for (const fragmentImport of deduplicatedImports) {
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildEnumValuesBlock = exports.convertSchemaEnumToDeclarationBlockString = void 0;
4
+ const utils_js_1 = require("./utils.js");
5
+ const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumName, enumValues, futureProofEnums, ignoreEnumValuesFromSchema, outputType, declarationBlockConfig, naming, }) => {
6
+ if (enumValues[enumName]?.sourceFile) {
7
+ return `export { ${enumValues[enumName].typeIdentifier} };\n`;
8
+ }
9
+ const getValueFromConfig = (enumValue) => {
10
+ if (typeof enumValues[enumName]?.mappedValues?.[enumValue] !== 'undefined') {
11
+ return enumValues[enumName].mappedValues[enumValue];
12
+ }
13
+ return null;
14
+ };
15
+ const withFutureAddedValue = [futureProofEnums ? [(0, utils_js_1.indent)('| ' + (0, utils_js_1.wrapWithSingleQuotes)('%future added value'))] : []];
16
+ const enumTypeName = convertName({
17
+ options: {
18
+ typesPrefix: naming.typesPrefix,
19
+ typesSuffix: naming.typesSuffix,
20
+ useTypesPrefix: naming.useTypesPrefix,
21
+ useTypesSuffix: naming.useTypesSuffix,
22
+ },
23
+ convert: () => naming.convert(node),
24
+ });
25
+ if (outputType === 'string-literal') {
26
+ return new utils_js_1.DeclarationBlock(declarationBlockConfig)
27
+ .export()
28
+ .asKind('type')
29
+ .withComment(node.description?.value)
30
+ .withName(enumTypeName)
31
+ .withContent('\n' +
32
+ node.values
33
+ .map(enumOption => {
34
+ const name = enumOption.name.value;
35
+ const enumValue = getValueFromConfig(name) ?? name;
36
+ const comment = (0, utils_js_1.transformComment)(enumOption.description?.value, 1);
37
+ return comment + (0, utils_js_1.indent)('| ' + (0, utils_js_1.wrapWithSingleQuotes)(enumValue));
38
+ })
39
+ .concat(...withFutureAddedValue)
40
+ .join('\n')).string;
41
+ }
42
+ if (outputType === 'native-numeric') {
43
+ return new utils_js_1.DeclarationBlock(declarationBlockConfig)
44
+ .export()
45
+ .withComment(node.description?.value)
46
+ .withName(enumTypeName)
47
+ .asKind('enum')
48
+ .withBlock(node.values
49
+ .map((enumOption, i) => {
50
+ const valueFromConfig = getValueFromConfig(enumOption.name.value);
51
+ const enumValue = valueFromConfig ?? i;
52
+ const comment = (0, utils_js_1.transformComment)(enumOption.description?.value, 1);
53
+ const optionName = makeValidEnumIdentifier(convertName({
54
+ options: {
55
+ typesPrefix: naming.typesPrefix,
56
+ typesSuffix: naming.typesSuffix,
57
+ useTypesPrefix: false,
58
+ },
59
+ convert: () => naming.convert(enumOption, { transformUnderscore: true }),
60
+ }));
61
+ return comment + (0, utils_js_1.indent)(optionName) + ` = ${enumValue}`;
62
+ })
63
+ .concat(...withFutureAddedValue)
64
+ .join(',\n')).string;
65
+ }
66
+ if (outputType === 'const') {
67
+ const typeName = `export type ${enumTypeName} = typeof ${enumTypeName}[keyof typeof ${enumTypeName}];`;
68
+ const enumAsConst = new utils_js_1.DeclarationBlock({
69
+ ...declarationBlockConfig,
70
+ blockTransformer: block => {
71
+ return block + ' as const';
72
+ },
73
+ })
74
+ .export()
75
+ .asKind('const')
76
+ .withName(enumTypeName)
77
+ .withComment(node.description?.value)
78
+ .withBlock(node.values
79
+ .map(enumOption => {
80
+ const optionName = makeValidEnumIdentifier(convertName({
81
+ options: {
82
+ typesPrefix: naming.typesPrefix,
83
+ typesSuffix: naming.typesPrefix,
84
+ },
85
+ convert: () => naming.convert(enumOption, {
86
+ transformUnderscore: true,
87
+ }),
88
+ }));
89
+ const comment = (0, utils_js_1.transformComment)(enumOption.description?.value, 1);
90
+ const name = enumOption.name.value;
91
+ const enumValue = getValueFromConfig(name) ?? name;
92
+ return comment + (0, utils_js_1.indent)(`${optionName}: ${(0, utils_js_1.wrapWithSingleQuotes)(enumValue)}`);
93
+ })
94
+ .join(',\n')).string;
95
+ return [enumAsConst, typeName].join('\n');
96
+ }
97
+ return new utils_js_1.DeclarationBlock(declarationBlockConfig)
98
+ .export()
99
+ .asKind(outputType === 'native-const' ? 'const enum' : 'enum')
100
+ .withName(enumTypeName)
101
+ .withComment(node.description?.value)
102
+ .withBlock((0, exports.buildEnumValuesBlock)({
103
+ typeName: enumName,
104
+ values: node.values,
105
+ schema,
106
+ naming,
107
+ ignoreEnumValuesFromSchema,
108
+ declarationBlockConfig,
109
+ enumValues,
110
+ })).string;
111
+ };
112
+ exports.convertSchemaEnumToDeclarationBlockString = convertSchemaEnumToDeclarationBlockString;
113
+ const buildEnumValuesBlock = ({ typeName, values, schema, naming, ignoreEnumValuesFromSchema, declarationBlockConfig, enumValues, }) => {
114
+ const schemaEnumType = schema
115
+ ? schema.getType(typeName)
116
+ : undefined;
117
+ return values
118
+ .map(enumOption => {
119
+ const onlyUnderscoresPattern = /^_+$/;
120
+ const optionName = makeValidEnumIdentifier(convertName({
121
+ options: {
122
+ useTypesPrefix: false,
123
+ typesPrefix: naming.typesPrefix,
124
+ typesSuffix: naming.typesSuffix,
125
+ },
126
+ convert: () => naming.convert(enumOption, {
127
+ // We can only strip out the underscores if the value contains other
128
+ // characters. Otherwise we'll generate syntactically invalid code.
129
+ transformUnderscore: !onlyUnderscoresPattern.test(enumOption.name.value),
130
+ }),
131
+ }));
132
+ const comment = (0, utils_js_1.getNodeComment)(enumOption);
133
+ const schemaEnumValue = schemaEnumType && !ignoreEnumValuesFromSchema
134
+ ? schemaEnumType.getValue(enumOption.name.value).value
135
+ : undefined;
136
+ let enumValue = typeof schemaEnumValue === 'undefined' ? enumOption.name.value : schemaEnumValue;
137
+ if (typeof enumValues[typeName]?.mappedValues?.[enumValue] !== 'undefined') {
138
+ enumValue = enumValues[typeName].mappedValues[enumValue];
139
+ }
140
+ return (comment +
141
+ (0, utils_js_1.indent)(`${optionName}${declarationBlockConfig.enumNameValueSeparator} ${(0, utils_js_1.wrapWithSingleQuotes)(enumValue, typeof schemaEnumValue !== 'undefined')}`));
142
+ })
143
+ .join(',\n');
144
+ };
145
+ exports.buildEnumValuesBlock = buildEnumValuesBlock;
146
+ const makeValidEnumIdentifier = (identifier) => {
147
+ if (/^[0-9]/.exec(identifier)) {
148
+ return (0, utils_js_1.wrapWithSingleQuotes)(identifier, true);
149
+ }
150
+ return identifier;
151
+ };
152
+ const convertName = ({ convert, options, }) => {
153
+ const useTypesPrefix = typeof options.useTypesPrefix === 'boolean' ? options.useTypesPrefix : true;
154
+ const useTypesSuffix = typeof options.useTypesSuffix === 'boolean' ? options.useTypesSuffix : true;
155
+ let convertedName = '';
156
+ if (useTypesPrefix) {
157
+ convertedName += options.typesPrefix;
158
+ }
159
+ convertedName += convert();
160
+ if (useTypesSuffix) {
161
+ convertedName += options.typesSuffix;
162
+ }
163
+ return convertedName;
164
+ };
package/cjs/imports.js CHANGED
@@ -9,7 +9,6 @@ exports.fixLocalFilePath = fixLocalFilePath;
9
9
  const tslib_1 = require("tslib");
10
10
  const path_1 = require("path");
11
11
  const parse_filepath_1 = tslib_1.__importDefault(require("parse-filepath"));
12
- const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
13
12
  function generateFragmentImportStatement(statement, kind) {
14
13
  const { importSource: fragmentImportSource, ...rest } = statement;
15
14
  const { identifiers, path, namespace } = fragmentImportSource;
@@ -32,12 +31,7 @@ function generateImportStatement(statement) {
32
31
  const importNames = importSource.identifiers?.length
33
32
  ? `{ ${Array.from(new Set(importSource.identifiers)).join(', ')} }`
34
33
  : '*';
35
- const importExtension = importPath.startsWith('/') || importPath.startsWith('.')
36
- ? (0, plugin_helpers_1.normalizeImportExtension)({
37
- emitLegacyCommonJSImports: statement.emitLegacyCommonJSImports,
38
- importExtension: statement.importExtension,
39
- })
40
- : '';
34
+ const importExtension = importPath.startsWith('/') || importPath.startsWith('.') ? (statement.emitLegacyCommonJSImports ? '' : '.js') : '';
41
35
  const importAlias = importSource.namespace ? ` as ${importSource.namespace}` : '';
42
36
  const importStatement = typesImport ? 'import type' : 'import';
43
37
  return `${importStatement} ${importNames}${importAlias} from '${importPath}${importExtension}';${importAlias ? '\n' : ''}`;
package/cjs/index.js CHANGED
@@ -20,3 +20,4 @@ tslib_1.__exportStar(require("./selection-set-to-object.js"), exports);
20
20
  tslib_1.__exportStar(require("./types.js"), exports);
21
21
  tslib_1.__exportStar(require("./utils.js"), exports);
22
22
  tslib_1.__exportStar(require("./variables-to-object.js"), exports);
23
+ tslib_1.__exportStar(require("./convert-schema-enum-to-declaration-block-string.js"), exports);
package/cjs/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFieldNames = exports.getFieldNodeNameValue = exports.REQUIRE_FIELDS_TYPE = exports.OMIT_TYPE = exports.DeclarationBlock = exports.getConfigValue = void 0;
3
+ exports.getNodeComment = exports.getFieldNames = exports.getFieldNodeNameValue = exports.REQUIRE_FIELDS_TYPE = exports.OMIT_TYPE = exports.DeclarationBlock = exports.getConfigValue = void 0;
4
4
  exports.quoteIfNeeded = quoteIfNeeded;
5
5
  exports.block = block;
6
6
  exports.wrapWithSingleQuotes = wrapWithSingleQuotes;
@@ -535,3 +535,24 @@ const getFieldNames = ({ selections, fieldNames = new Set(), parentName = '', lo
535
535
  return fieldNames;
536
536
  };
537
537
  exports.getFieldNames = getFieldNames;
538
+ const getNodeComment = (node) => {
539
+ let commentText = node.description?.value;
540
+ const deprecationDirective = node.directives.find(v => v.name.value === 'deprecated');
541
+ if (deprecationDirective) {
542
+ const deprecationReason = getDeprecationReason(deprecationDirective);
543
+ commentText = `${commentText ? `${commentText}\n` : ''}@deprecated ${deprecationReason}`;
544
+ }
545
+ const comment = transformComment(commentText, 1);
546
+ return comment;
547
+ };
548
+ exports.getNodeComment = getNodeComment;
549
+ const getDeprecationReason = (directive) => {
550
+ if (directive.name.value === 'deprecated') {
551
+ let reason = 'Field no longer supported';
552
+ const deprecatedReason = directive.arguments[0];
553
+ if (deprecatedReason && deprecatedReason.value.kind === graphql_1.Kind.STRING) {
554
+ reason = deprecatedReason.value.value;
555
+ }
556
+ return reason;
557
+ }
558
+ };
@@ -171,17 +171,15 @@ export class BaseResolversVisitor extends BaseVisitor {
171
171
  const isMapped = this.config.mappers[typeName];
172
172
  const isScalar = this.config.scalars[typeName];
173
173
  const hasDefaultMapper = !!this.config.defaultMapper?.type;
174
- // Check for mappers first, even for root types, to allow overriding rootValueType
175
- if (isMapped && this.config.mappers[typeName].type && !hasPlaceholder(this.config.mappers[typeName].type)) {
176
- this.markMapperAsUsed(typeName);
177
- prev[typeName] = applyWrapper(this.config.mappers[typeName].type);
178
- return prev;
179
- }
180
174
  if (isRootType) {
181
175
  prev[typeName] = applyWrapper(this.config.rootValueType.type);
182
176
  return prev;
183
177
  }
184
- if (isEnumType(schemaType) && this.config.enumValues[typeName]) {
178
+ if (isMapped && this.config.mappers[typeName].type && !hasPlaceholder(this.config.mappers[typeName].type)) {
179
+ this.markMapperAsUsed(typeName);
180
+ prev[typeName] = applyWrapper(this.config.mappers[typeName].type);
181
+ }
182
+ else if (isEnumType(schemaType) && this.config.enumValues[typeName]) {
185
183
  const isExternalFile = !!this.config.enumValues[typeName].sourceFile;
186
184
  prev[typeName] = isExternalFile
187
185
  ? this.convertName(this.config.enumValues[typeName].typeIdentifier, {
@@ -4,9 +4,9 @@ import { normalizeDeclarationKind } from './declaration-kinds.js';
4
4
  import { parseEnumValues } from './enum-values.js';
5
5
  import { transformDirectiveArgumentAndInputFieldMappings } from './mappers.js';
6
6
  import { DEFAULT_SCALARS } from './scalars.js';
7
- import { buildScalarsFromConfig, DeclarationBlock, getConfigValue, indent, isOneOfInputObjectType, transformComment, wrapWithSingleQuotes, } from './utils.js';
7
+ import { buildScalarsFromConfig, DeclarationBlock, getConfigValue, indent, isOneOfInputObjectType, transformComment, getNodeComment, wrapWithSingleQuotes, } from './utils.js';
8
8
  import { OperationVariablesToObject } from './variables-to-object.js';
9
- const onlyUnderscoresPattern = /^_+$/;
9
+ import { buildEnumValuesBlock } from './convert-schema-enum-to-declaration-block-string.js';
10
10
  export class BaseTypesVisitor extends BaseVisitor {
11
11
  _schema;
12
12
  _argumentsTransformer;
@@ -165,7 +165,7 @@ export class BaseTypesVisitor extends BaseVisitor {
165
165
  return '';
166
166
  const typeString = node.type;
167
167
  const { type } = this._parsedConfig.declarationKind;
168
- const comment = this.getNodeComment(node);
168
+ const comment = getNodeComment(node);
169
169
  return comment + indent(`${node.name.value}: ${typeString}${this.getPunctuation(type)}`);
170
170
  }
171
171
  UnionTypeDefinition(node, key, parent) {
@@ -301,7 +301,21 @@ export class BaseTypesVisitor extends BaseVisitor {
301
301
  useTypesSuffix: this.config.enumSuffix,
302
302
  }))
303
303
  .withComment(node.description.value)
304
- .withBlock(this.buildEnumValuesBlock(enumName, node.values)).string;
304
+ .withBlock(buildEnumValuesBlock({
305
+ typeName: enumName,
306
+ values: node.values,
307
+ schema: this._schema,
308
+ naming: {
309
+ convert: this.config.convert,
310
+ typesPrefix: this.config.typesPrefix,
311
+ useTypesPrefix: this.config.enumPrefix,
312
+ typesSuffix: this.config.typesSuffix,
313
+ useTypesSuffix: this.config.enumSuffix,
314
+ },
315
+ ignoreEnumValuesFromSchema: this.config.ignoreEnumValuesFromSchema,
316
+ declarationBlockConfig: this._declarationBlockConfig,
317
+ enumValues: this.config.enumValues,
318
+ })).string;
305
319
  }
306
320
  makeValidEnumIdentifier(identifier) {
307
321
  if (/^[0-9]/.exec(identifier)) {
@@ -309,31 +323,6 @@ export class BaseTypesVisitor extends BaseVisitor {
309
323
  }
310
324
  return identifier;
311
325
  }
312
- buildEnumValuesBlock(typeName, values) {
313
- const schemaEnumType = this._schema
314
- ? this._schema.getType(typeName)
315
- : undefined;
316
- return values
317
- .map(enumOption => {
318
- const optionName = this.makeValidEnumIdentifier(this.convertName(enumOption, {
319
- useTypesPrefix: false,
320
- // We can only strip out the underscores if the value contains other
321
- // characters. Otherwise we'll generate syntactically invalid code.
322
- transformUnderscore: !onlyUnderscoresPattern.test(enumOption.name.value),
323
- }));
324
- const comment = this.getNodeComment(enumOption);
325
- const schemaEnumValue = schemaEnumType && !this.config.ignoreEnumValuesFromSchema
326
- ? schemaEnumType.getValue(enumOption.name.value).value
327
- : undefined;
328
- let enumValue = typeof schemaEnumValue === 'undefined' ? enumOption.name.value : schemaEnumValue;
329
- if (typeof this.config.enumValues[typeName]?.mappedValues?.[enumValue] !== 'undefined') {
330
- enumValue = this.config.enumValues[typeName].mappedValues[enumValue];
331
- }
332
- return (comment +
333
- indent(`${optionName}${this._declarationBlockConfig.enumNameValueSeparator} ${wrapWithSingleQuotes(enumValue, typeof schemaEnumValue !== 'undefined')}`));
334
- })
335
- .join(',\n');
336
- }
337
326
  DirectiveDefinition(_node) {
338
327
  return '';
339
328
  }
@@ -420,26 +409,6 @@ export class BaseTypesVisitor extends BaseVisitor {
420
409
  SchemaExtension() {
421
410
  return null;
422
411
  }
423
- getNodeComment(node) {
424
- let commentText = node.description?.value;
425
- const deprecationDirective = node.directives.find(v => v.name.value === 'deprecated');
426
- if (deprecationDirective) {
427
- const deprecationReason = this.getDeprecationReason(deprecationDirective);
428
- commentText = `${commentText ? `${commentText}\n` : ''}@deprecated ${deprecationReason}`;
429
- }
430
- const comment = transformComment(commentText, 1);
431
- return comment;
432
- }
433
- getDeprecationReason(directive) {
434
- if (directive.name.value === 'deprecated') {
435
- let reason = 'Field no longer supported';
436
- const deprecatedReason = directive.arguments[0];
437
- if (deprecatedReason && deprecatedReason.value.kind === Kind.STRING) {
438
- reason = deprecatedReason.value.value;
439
- }
440
- return reason;
441
- }
442
- }
443
412
  wrapWithListType(str) {
444
413
  return `Array<${str}>`;
445
414
  }
@@ -1,15 +1,10 @@
1
1
  import autoBind from 'auto-bind';
2
2
  import { convertFactory } from './naming.js';
3
- import { normalizeImportExtension } from '@graphql-codegen/plugin-helpers';
4
3
  export class BaseVisitor {
5
4
  _parsedConfig;
6
5
  _declarationBlockConfig = {};
7
6
  scalars;
8
7
  constructor(rawConfig, additionalConfig) {
9
- const importExtension = normalizeImportExtension({
10
- emitLegacyCommonJSImports: rawConfig.emitLegacyCommonJSImports,
11
- importExtension: rawConfig.importExtension,
12
- });
13
8
  this._parsedConfig = {
14
9
  convert: convertFactory(rawConfig),
15
10
  typesPrefix: rawConfig.typesPrefix || '',
@@ -21,8 +16,7 @@ export class BaseVisitor {
21
16
  useTypeImports: !!rawConfig.useTypeImports,
22
17
  allowEnumStringTypes: !!rawConfig.allowEnumStringTypes,
23
18
  inlineFragmentTypes: rawConfig.inlineFragmentTypes ?? 'inline',
24
- emitLegacyCommonJSImports: rawConfig.emitLegacyCommonJSImports ?? true,
25
- importExtension,
19
+ emitLegacyCommonJSImports: rawConfig.emitLegacyCommonJSImports === undefined ? true : !!rawConfig.emitLegacyCommonJSImports,
26
20
  extractAllFieldsToTypes: rawConfig.extractAllFieldsToTypes ?? false,
27
21
  printFieldsOnNewLines: rawConfig.printFieldsOnNewLines ?? false,
28
22
  includeExternalFragments: rawConfig.includeExternalFragments ?? false,
@@ -1,5 +1,5 @@
1
1
  import { basename, extname } from 'path';
2
- import { normalizeImportExtension, oldVisit } from '@graphql-codegen/plugin-helpers';
2
+ import { oldVisit } from '@graphql-codegen/plugin-helpers';
3
3
  import { optimizeDocumentNode } from '@graphql-tools/optimize';
4
4
  import autoBind from 'auto-bind';
5
5
  import { pascalCase } from 'change-case-all';
@@ -292,11 +292,7 @@ export class ClientSideBaseVisitor extends BaseVisitor {
292
292
  }
293
293
  clearExtension(path) {
294
294
  const extension = extname(path);
295
- const importExtension = normalizeImportExtension({
296
- emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
297
- importExtension: this.config.importExtension,
298
- });
299
- if (extension === importExtension) {
295
+ if (!this.config.emitLegacyCommonJSImports && extension === '.js') {
300
296
  return path;
301
297
  }
302
298
  if (EXTENSIONS_TO_REMOVE.includes(extension)) {
@@ -330,10 +326,9 @@ export class ClientSideBaseVisitor extends BaseVisitor {
330
326
  if (this._collectedOperations.length > 0) {
331
327
  if (this.config.importDocumentNodeExternallyFrom === 'near-operation-file' && this._documents.length === 1) {
332
328
  let documentPath = `./${this.clearExtension(basename(this._documents[0].location))}`;
333
- documentPath += normalizeImportExtension({
334
- emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
335
- importExtension: this.config.importExtension,
336
- });
329
+ if (!this.config.emitLegacyCommonJSImports) {
330
+ documentPath += '.js';
331
+ }
337
332
  this._imports.add(`import * as Operations from '${documentPath}';`);
338
333
  }
339
334
  else {
@@ -351,10 +346,6 @@ export class ClientSideBaseVisitor extends BaseVisitor {
351
346
  }
352
347
  const excludeFragments = options.excludeFragments || this.config.globalNamespace || this.config.documentMode !== DocumentMode.graphQLTag;
353
348
  if (!excludeFragments) {
354
- const importExtension = normalizeImportExtension({
355
- emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
356
- importExtension: this.config.importExtension,
357
- });
358
349
  const deduplicatedImports = Object.values(groupBy(this.config.fragmentImports, fi => fi.importSource.path))
359
350
  .map((fragmentImports) => ({
360
351
  ...fragmentImports[0],
@@ -363,7 +354,6 @@ export class ClientSideBaseVisitor extends BaseVisitor {
363
354
  identifiers: unique(flatten(fragmentImports.map(fi => fi.importSource.identifiers)), identifier => identifier.name),
364
355
  },
365
356
  emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
366
- importExtension,
367
357
  }))
368
358
  .filter(fragmentImport => fragmentImport.outputPath !== fragmentImport.importSource.path);
369
359
  for (const fragmentImport of deduplicatedImports) {
@@ -0,0 +1,159 @@
1
+ import { DeclarationBlock, indent, transformComment, getNodeComment, wrapWithSingleQuotes, } from './utils.js';
2
+ export const convertSchemaEnumToDeclarationBlockString = ({ schema, node, enumName, enumValues, futureProofEnums, ignoreEnumValuesFromSchema, outputType, declarationBlockConfig, naming, }) => {
3
+ if (enumValues[enumName]?.sourceFile) {
4
+ return `export { ${enumValues[enumName].typeIdentifier} };\n`;
5
+ }
6
+ const getValueFromConfig = (enumValue) => {
7
+ if (typeof enumValues[enumName]?.mappedValues?.[enumValue] !== 'undefined') {
8
+ return enumValues[enumName].mappedValues[enumValue];
9
+ }
10
+ return null;
11
+ };
12
+ const withFutureAddedValue = [futureProofEnums ? [indent('| ' + wrapWithSingleQuotes('%future added value'))] : []];
13
+ const enumTypeName = convertName({
14
+ options: {
15
+ typesPrefix: naming.typesPrefix,
16
+ typesSuffix: naming.typesSuffix,
17
+ useTypesPrefix: naming.useTypesPrefix,
18
+ useTypesSuffix: naming.useTypesSuffix,
19
+ },
20
+ convert: () => naming.convert(node),
21
+ });
22
+ if (outputType === 'string-literal') {
23
+ return new DeclarationBlock(declarationBlockConfig)
24
+ .export()
25
+ .asKind('type')
26
+ .withComment(node.description?.value)
27
+ .withName(enumTypeName)
28
+ .withContent('\n' +
29
+ node.values
30
+ .map(enumOption => {
31
+ const name = enumOption.name.value;
32
+ const enumValue = getValueFromConfig(name) ?? name;
33
+ const comment = transformComment(enumOption.description?.value, 1);
34
+ return comment + indent('| ' + wrapWithSingleQuotes(enumValue));
35
+ })
36
+ .concat(...withFutureAddedValue)
37
+ .join('\n')).string;
38
+ }
39
+ if (outputType === 'native-numeric') {
40
+ return new DeclarationBlock(declarationBlockConfig)
41
+ .export()
42
+ .withComment(node.description?.value)
43
+ .withName(enumTypeName)
44
+ .asKind('enum')
45
+ .withBlock(node.values
46
+ .map((enumOption, i) => {
47
+ const valueFromConfig = getValueFromConfig(enumOption.name.value);
48
+ const enumValue = valueFromConfig ?? i;
49
+ const comment = transformComment(enumOption.description?.value, 1);
50
+ const optionName = makeValidEnumIdentifier(convertName({
51
+ options: {
52
+ typesPrefix: naming.typesPrefix,
53
+ typesSuffix: naming.typesSuffix,
54
+ useTypesPrefix: false,
55
+ },
56
+ convert: () => naming.convert(enumOption, { transformUnderscore: true }),
57
+ }));
58
+ return comment + indent(optionName) + ` = ${enumValue}`;
59
+ })
60
+ .concat(...withFutureAddedValue)
61
+ .join(',\n')).string;
62
+ }
63
+ if (outputType === 'const') {
64
+ const typeName = `export type ${enumTypeName} = typeof ${enumTypeName}[keyof typeof ${enumTypeName}];`;
65
+ const enumAsConst = new DeclarationBlock({
66
+ ...declarationBlockConfig,
67
+ blockTransformer: block => {
68
+ return block + ' as const';
69
+ },
70
+ })
71
+ .export()
72
+ .asKind('const')
73
+ .withName(enumTypeName)
74
+ .withComment(node.description?.value)
75
+ .withBlock(node.values
76
+ .map(enumOption => {
77
+ const optionName = makeValidEnumIdentifier(convertName({
78
+ options: {
79
+ typesPrefix: naming.typesPrefix,
80
+ typesSuffix: naming.typesPrefix,
81
+ },
82
+ convert: () => naming.convert(enumOption, {
83
+ transformUnderscore: true,
84
+ }),
85
+ }));
86
+ const comment = transformComment(enumOption.description?.value, 1);
87
+ const name = enumOption.name.value;
88
+ const enumValue = getValueFromConfig(name) ?? name;
89
+ return comment + indent(`${optionName}: ${wrapWithSingleQuotes(enumValue)}`);
90
+ })
91
+ .join(',\n')).string;
92
+ return [enumAsConst, typeName].join('\n');
93
+ }
94
+ return new DeclarationBlock(declarationBlockConfig)
95
+ .export()
96
+ .asKind(outputType === 'native-const' ? 'const enum' : 'enum')
97
+ .withName(enumTypeName)
98
+ .withComment(node.description?.value)
99
+ .withBlock(buildEnumValuesBlock({
100
+ typeName: enumName,
101
+ values: node.values,
102
+ schema,
103
+ naming,
104
+ ignoreEnumValuesFromSchema,
105
+ declarationBlockConfig,
106
+ enumValues,
107
+ })).string;
108
+ };
109
+ export const buildEnumValuesBlock = ({ typeName, values, schema, naming, ignoreEnumValuesFromSchema, declarationBlockConfig, enumValues, }) => {
110
+ const schemaEnumType = schema
111
+ ? schema.getType(typeName)
112
+ : undefined;
113
+ return values
114
+ .map(enumOption => {
115
+ const onlyUnderscoresPattern = /^_+$/;
116
+ const optionName = makeValidEnumIdentifier(convertName({
117
+ options: {
118
+ useTypesPrefix: false,
119
+ typesPrefix: naming.typesPrefix,
120
+ typesSuffix: naming.typesSuffix,
121
+ },
122
+ convert: () => naming.convert(enumOption, {
123
+ // We can only strip out the underscores if the value contains other
124
+ // characters. Otherwise we'll generate syntactically invalid code.
125
+ transformUnderscore: !onlyUnderscoresPattern.test(enumOption.name.value),
126
+ }),
127
+ }));
128
+ const comment = getNodeComment(enumOption);
129
+ const schemaEnumValue = schemaEnumType && !ignoreEnumValuesFromSchema
130
+ ? schemaEnumType.getValue(enumOption.name.value).value
131
+ : undefined;
132
+ let enumValue = typeof schemaEnumValue === 'undefined' ? enumOption.name.value : schemaEnumValue;
133
+ if (typeof enumValues[typeName]?.mappedValues?.[enumValue] !== 'undefined') {
134
+ enumValue = enumValues[typeName].mappedValues[enumValue];
135
+ }
136
+ return (comment +
137
+ indent(`${optionName}${declarationBlockConfig.enumNameValueSeparator} ${wrapWithSingleQuotes(enumValue, typeof schemaEnumValue !== 'undefined')}`));
138
+ })
139
+ .join(',\n');
140
+ };
141
+ const makeValidEnumIdentifier = (identifier) => {
142
+ if (/^[0-9]/.exec(identifier)) {
143
+ return wrapWithSingleQuotes(identifier, true);
144
+ }
145
+ return identifier;
146
+ };
147
+ const convertName = ({ convert, options, }) => {
148
+ const useTypesPrefix = typeof options.useTypesPrefix === 'boolean' ? options.useTypesPrefix : true;
149
+ const useTypesSuffix = typeof options.useTypesSuffix === 'boolean' ? options.useTypesSuffix : true;
150
+ let convertedName = '';
151
+ if (useTypesPrefix) {
152
+ convertedName += options.typesPrefix;
153
+ }
154
+ convertedName += convert();
155
+ if (useTypesSuffix) {
156
+ convertedName += options.typesSuffix;
157
+ }
158
+ return convertedName;
159
+ };
package/esm/imports.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { dirname, isAbsolute, join, relative, resolve } from 'path';
2
2
  import parse from 'parse-filepath';
3
- import { normalizeImportExtension } from '@graphql-codegen/plugin-helpers';
4
3
  export function generateFragmentImportStatement(statement, kind) {
5
4
  const { importSource: fragmentImportSource, ...rest } = statement;
6
5
  const { identifiers, path, namespace } = fragmentImportSource;
@@ -23,12 +22,7 @@ export function generateImportStatement(statement) {
23
22
  const importNames = importSource.identifiers?.length
24
23
  ? `{ ${Array.from(new Set(importSource.identifiers)).join(', ')} }`
25
24
  : '*';
26
- const importExtension = importPath.startsWith('/') || importPath.startsWith('.')
27
- ? normalizeImportExtension({
28
- emitLegacyCommonJSImports: statement.emitLegacyCommonJSImports,
29
- importExtension: statement.importExtension,
30
- })
31
- : '';
25
+ const importExtension = importPath.startsWith('/') || importPath.startsWith('.') ? (statement.emitLegacyCommonJSImports ? '' : '.js') : '';
32
26
  const importAlias = importSource.namespace ? ` as ${importSource.namespace}` : '';
33
27
  const importStatement = typesImport ? 'import type' : 'import';
34
28
  return `${importStatement} ${importNames}${importAlias} from '${importPath}${importExtension}';${importAlias ? '\n' : ''}`;
package/esm/index.js CHANGED
@@ -17,3 +17,4 @@ export * from './selection-set-to-object.js';
17
17
  export * from './types.js';
18
18
  export * from './utils.js';
19
19
  export * from './variables-to-object.js';
20
+ export * from './convert-schema-enum-to-declaration-block-string.js';
package/esm/utils.js CHANGED
@@ -503,3 +503,23 @@ export const getFieldNames = ({ selections, fieldNames = new Set(), parentName =
503
503
  }
504
504
  return fieldNames;
505
505
  };
506
+ export const getNodeComment = (node) => {
507
+ let commentText = node.description?.value;
508
+ const deprecationDirective = node.directives.find(v => v.name.value === 'deprecated');
509
+ if (deprecationDirective) {
510
+ const deprecationReason = getDeprecationReason(deprecationDirective);
511
+ commentText = `${commentText ? `${commentText}\n` : ''}@deprecated ${deprecationReason}`;
512
+ }
513
+ const comment = transformComment(commentText, 1);
514
+ return comment;
515
+ };
516
+ const getDeprecationReason = (directive) => {
517
+ if (directive.name.value === 'deprecated') {
518
+ let reason = 'Field no longer supported';
519
+ const deprecatedReason = directive.arguments[0];
520
+ if (deprecatedReason && deprecatedReason.value.kind === Kind.STRING) {
521
+ reason = deprecatedReason.value.value;
522
+ }
523
+ return reason;
524
+ }
525
+ };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@graphql-codegen/visitor-plugin-common",
3
- "version": "6.2.0",
3
+ "version": "7.0.0-alpha-20251125123407-8babe46fb9b33e9f9a377cd50c9580282e7981d3",
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.1.0",
9
+ "@graphql-codegen/plugin-helpers": "^6.0.0",
10
10
  "@graphql-tools/relay-operation-optimizer": "^7.0.0",
11
11
  "@graphql-tools/utils": "^10.0.0",
12
12
  "auto-bind": "~4.0.0",
@@ -1,4 +1,4 @@
1
- import { DirectiveDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode } from 'graphql';
1
+ import { DirectiveDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, 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';
@@ -483,7 +483,6 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
483
483
  getEnumsImports(): string[];
484
484
  EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
485
485
  protected makeValidEnumIdentifier(identifier: string): string;
486
- protected buildEnumValuesBlock(typeName: string, values: ReadonlyArray<EnumValueDefinitionNode>): string;
487
486
  DirectiveDefinition(_node: DirectiveDefinitionNode): string;
488
487
  getArgumentsObjectDeclarationBlock(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode, name: string, field: FieldDefinitionNode): DeclarationBlock;
489
488
  getArgumentsObjectTypeDefinition(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode, name: string, field: FieldDefinitionNode): string;
@@ -496,7 +495,5 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
496
495
  ListType(node: ListTypeNode, _key: any, _parent: any, _path: any, _ancestors: any): string;
497
496
  SchemaDefinition(): any;
498
497
  SchemaExtension(): any;
499
- getNodeComment(node: FieldDefinitionNode | EnumValueDefinitionNode | InputValueDefinitionNode): string;
500
- protected getDeprecationReason(directive: DirectiveNode): string | void;
501
498
  protected wrapWithListType(str: string): string;
502
499
  }
@@ -1,4 +1,4 @@
1
- import { DirectiveDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ListTypeNode, NamedTypeNode, NonNullTypeNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, UnionTypeDefinitionNode } from 'graphql';
1
+ import { DirectiveDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, 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';
@@ -483,7 +483,6 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
483
483
  getEnumsImports(): string[];
484
484
  EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
485
485
  protected makeValidEnumIdentifier(identifier: string): string;
486
- protected buildEnumValuesBlock(typeName: string, values: ReadonlyArray<EnumValueDefinitionNode>): string;
487
486
  DirectiveDefinition(_node: DirectiveDefinitionNode): string;
488
487
  getArgumentsObjectDeclarationBlock(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode, name: string, field: FieldDefinitionNode): DeclarationBlock;
489
488
  getArgumentsObjectTypeDefinition(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode, name: string, field: FieldDefinitionNode): string;
@@ -496,7 +495,5 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
496
495
  ListType(node: ListTypeNode, _key: any, _parent: any, _path: any, _ancestors: any): string;
497
496
  SchemaDefinition(): any;
498
497
  SchemaExtension(): any;
499
- getNodeComment(node: FieldDefinitionNode | EnumValueDefinitionNode | InputValueDefinitionNode): string;
500
- protected getDeprecationReason(directive: DirectiveNode): string | void;
501
498
  protected wrapWithListType(str: string): string;
502
499
  }
@@ -21,8 +21,7 @@ export interface ParsedConfig {
21
21
  useTypeImports: boolean;
22
22
  allowEnumStringTypes: boolean;
23
23
  inlineFragmentTypes: InlineFragmentTypeOptions;
24
- emitLegacyCommonJSImports?: boolean;
25
- importExtension: '' | `.${string}`;
24
+ emitLegacyCommonJSImports: boolean;
26
25
  printFieldsOnNewLines: boolean;
27
26
  includeExternalFragments: boolean;
28
27
  }
@@ -344,17 +343,11 @@ export interface RawConfig {
344
343
  */
345
344
  inlineFragmentTypes?: InlineFragmentTypeOptions;
346
345
  /**
347
- * @deprecated Please use `importExtension` instead.
348
346
  * @default true
349
347
  * @description Emit legacy common js imports.
350
348
  * Default it will be `true` this way it ensure that generated code works with [non-compliant bundlers](https://github.com/dotansimha/graphql-code-generator/issues/8065).
351
349
  */
352
350
  emitLegacyCommonJSImports?: boolean;
353
- /**
354
- * @description Append this extension to all imports.
355
- * Useful for ESM environments that require file extensions in import statements.
356
- */
357
- importExtension?: '' | `.${string}`;
358
351
  /**
359
352
  * @default false
360
353
  * @description Extract all field types to their own types, instead of inlining them.
@@ -21,8 +21,7 @@ export interface ParsedConfig {
21
21
  useTypeImports: boolean;
22
22
  allowEnumStringTypes: boolean;
23
23
  inlineFragmentTypes: InlineFragmentTypeOptions;
24
- emitLegacyCommonJSImports?: boolean;
25
- importExtension: '' | `.${string}`;
24
+ emitLegacyCommonJSImports: boolean;
26
25
  printFieldsOnNewLines: boolean;
27
26
  includeExternalFragments: boolean;
28
27
  }
@@ -344,17 +343,11 @@ export interface RawConfig {
344
343
  */
345
344
  inlineFragmentTypes?: InlineFragmentTypeOptions;
346
345
  /**
347
- * @deprecated Please use `importExtension` instead.
348
346
  * @default true
349
347
  * @description Emit legacy common js imports.
350
348
  * Default it will be `true` this way it ensure that generated code works with [non-compliant bundlers](https://github.com/dotansimha/graphql-code-generator/issues/8065).
351
349
  */
352
350
  emitLegacyCommonJSImports?: boolean;
353
- /**
354
- * @description Append this extension to all imports.
355
- * Useful for ESM environments that require file extensions in import statements.
356
- */
357
- importExtension?: '' | `.${string}`;
358
351
  /**
359
352
  * @default false
360
353
  * @description Extract all field types to their own types, instead of inlining them.
@@ -0,0 +1,26 @@
1
+ import type { EnumTypeDefinitionNode, EnumValueDefinitionNode, GraphQLSchema } from 'graphql';
2
+ import type { ConvertFn, ParsedEnumValuesMap } from './types.cjs';
3
+ import { type DeclarationBlockConfig } from './utils.cjs';
4
+ interface ConvertSchemaEnumToDeclarationBlockString {
5
+ schema: GraphQLSchema;
6
+ node: EnumTypeDefinitionNode;
7
+ enumName: string;
8
+ enumValues: ParsedEnumValuesMap;
9
+ futureProofEnums: boolean;
10
+ ignoreEnumValuesFromSchema: boolean;
11
+ naming: {
12
+ convert: ConvertFn;
13
+ typesPrefix: string;
14
+ typesSuffix: string;
15
+ useTypesPrefix?: boolean;
16
+ useTypesSuffix?: boolean;
17
+ };
18
+ outputType: 'string-literal' | 'native-numeric' | 'const' | 'native-const' | 'native';
19
+ declarationBlockConfig: DeclarationBlockConfig;
20
+ }
21
+ export declare const convertSchemaEnumToDeclarationBlockString: ({ schema, node, enumName, enumValues, futureProofEnums, ignoreEnumValuesFromSchema, outputType, declarationBlockConfig, naming, }: ConvertSchemaEnumToDeclarationBlockString) => string;
22
+ export declare const buildEnumValuesBlock: ({ typeName, values, schema, naming, ignoreEnumValuesFromSchema, declarationBlockConfig, enumValues, }: Pick<ConvertSchemaEnumToDeclarationBlockString, "schema" | "naming" | "ignoreEnumValuesFromSchema" | "declarationBlockConfig" | "enumValues"> & {
23
+ typeName: string;
24
+ values: ReadonlyArray<EnumValueDefinitionNode>;
25
+ }) => string;
26
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { EnumTypeDefinitionNode, EnumValueDefinitionNode, GraphQLSchema } from 'graphql';
2
+ import type { ConvertFn, ParsedEnumValuesMap } from './types.js';
3
+ import { type DeclarationBlockConfig } from './utils.js';
4
+ interface ConvertSchemaEnumToDeclarationBlockString {
5
+ schema: GraphQLSchema;
6
+ node: EnumTypeDefinitionNode;
7
+ enumName: string;
8
+ enumValues: ParsedEnumValuesMap;
9
+ futureProofEnums: boolean;
10
+ ignoreEnumValuesFromSchema: boolean;
11
+ naming: {
12
+ convert: ConvertFn;
13
+ typesPrefix: string;
14
+ typesSuffix: string;
15
+ useTypesPrefix?: boolean;
16
+ useTypesSuffix?: boolean;
17
+ };
18
+ outputType: 'string-literal' | 'native-numeric' | 'const' | 'native-const' | 'native';
19
+ declarationBlockConfig: DeclarationBlockConfig;
20
+ }
21
+ export declare const convertSchemaEnumToDeclarationBlockString: ({ schema, node, enumName, enumValues, futureProofEnums, ignoreEnumValuesFromSchema, outputType, declarationBlockConfig, naming, }: ConvertSchemaEnumToDeclarationBlockString) => string;
22
+ export declare const buildEnumValuesBlock: ({ typeName, values, schema, naming, ignoreEnumValuesFromSchema, declarationBlockConfig, enumValues, }: Pick<ConvertSchemaEnumToDeclarationBlockString, "schema" | "naming" | "ignoreEnumValuesFromSchema" | "declarationBlockConfig" | "enumValues"> & {
23
+ typeName: string;
24
+ values: ReadonlyArray<EnumValueDefinitionNode>;
25
+ }) => string;
26
+ export {};
@@ -4,8 +4,7 @@ export type ImportDeclaration<T = string> = {
4
4
  baseOutputDir: string;
5
5
  baseDir: string;
6
6
  typesImport: boolean;
7
- emitLegacyCommonJSImports?: boolean;
8
- importExtension: '' | `.${string}`;
7
+ emitLegacyCommonJSImports: boolean;
9
8
  };
10
9
  export type ImportSource<T = string> = {
11
10
  /**
@@ -4,8 +4,7 @@ export type ImportDeclaration<T = string> = {
4
4
  baseOutputDir: string;
5
5
  baseDir: string;
6
6
  typesImport: boolean;
7
- emitLegacyCommonJSImports?: boolean;
8
- importExtension: '' | `.${string}`;
7
+ emitLegacyCommonJSImports: boolean;
9
8
  };
10
9
  export type ImportSource<T = string> = {
11
10
  /**
@@ -17,3 +17,4 @@ export * from './selection-set-to-object.cjs';
17
17
  export * from './types.cjs';
18
18
  export * from './utils.cjs';
19
19
  export * from './variables-to-object.cjs';
20
+ export * from './convert-schema-enum-to-declaration-block-string.cjs';
@@ -17,3 +17,4 @@ export * from './selection-set-to-object.js';
17
17
  export * from './types.js';
18
18
  export * from './utils.js';
19
19
  export * from './variables-to-object.js';
20
+ export * from './convert-schema-enum-to-declaration-block-string.js';
@@ -1,4 +1,4 @@
1
- import { FieldNode, FragmentSpreadNode, GraphQLInputObjectType, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, GraphQLSchema, InlineFragmentNode, NamedTypeNode, NameNode, SelectionNode, SelectionSetNode, StringValueNode, TypeNode, DirectiveNode } from 'graphql';
1
+ import { FieldNode, FragmentSpreadNode, GraphQLInputObjectType, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, GraphQLSchema, InlineFragmentNode, NamedTypeNode, NameNode, SelectionNode, SelectionSetNode, StringValueNode, TypeNode, DirectiveNode, FieldDefinitionNode, EnumValueDefinitionNode, InputValueDefinitionNode } from 'graphql';
2
2
  import { RawConfig } from './base-visitor.cjs';
3
3
  import { NormalizedScalarsMap, ParsedScalarsMap, ScalarsMap, FragmentDirectives, LoadedFragment } from './types.cjs';
4
4
  export declare const getConfigValue: <T = any>(value: T, defaultValue: T) => T;
@@ -82,4 +82,5 @@ export declare const getFieldNames: ({ selections, fieldNames, parentName, loade
82
82
  parentName?: string;
83
83
  loadedFragments: LoadedFragment[];
84
84
  }) => Set<string>;
85
+ export declare const getNodeComment: (node: FieldDefinitionNode | EnumValueDefinitionNode | InputValueDefinitionNode) => string;
85
86
  export {};
@@ -1,4 +1,4 @@
1
- import { FieldNode, FragmentSpreadNode, GraphQLInputObjectType, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, GraphQLSchema, InlineFragmentNode, NamedTypeNode, NameNode, SelectionNode, SelectionSetNode, StringValueNode, TypeNode, DirectiveNode } from 'graphql';
1
+ import { FieldNode, FragmentSpreadNode, GraphQLInputObjectType, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, GraphQLSchema, InlineFragmentNode, NamedTypeNode, NameNode, SelectionNode, SelectionSetNode, StringValueNode, TypeNode, DirectiveNode, FieldDefinitionNode, EnumValueDefinitionNode, InputValueDefinitionNode } from 'graphql';
2
2
  import { RawConfig } from './base-visitor.js';
3
3
  import { NormalizedScalarsMap, ParsedScalarsMap, ScalarsMap, FragmentDirectives, LoadedFragment } from './types.js';
4
4
  export declare const getConfigValue: <T = any>(value: T, defaultValue: T) => T;
@@ -82,4 +82,5 @@ export declare const getFieldNames: ({ selections, fieldNames, parentName, loade
82
82
  parentName?: string;
83
83
  loadedFragments: LoadedFragment[];
84
84
  }) => Set<string>;
85
+ export declare const getNodeComment: (node: FieldDefinitionNode | EnumValueDefinitionNode | InputValueDefinitionNode) => string;
85
86
  export {};