@graphql-codegen/visitor-plugin-common 6.2.2 → 7.0.0-alpha-20251224115216-0c4a535bdb152e75b9296d4c259f7dad0a13158f

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.
Files changed (45) hide show
  1. package/cjs/base-documents-visitor.js +8 -0
  2. package/cjs/base-resolvers-visitor.js +5 -7
  3. package/cjs/base-types-visitor.js +40 -87
  4. package/cjs/base-visitor.js +1 -7
  5. package/cjs/client-side-base-visitor.js +4 -14
  6. package/cjs/convert-schema-enum-to-declaration-block-string.js +164 -0
  7. package/cjs/graphql-type-utils.js +15 -0
  8. package/cjs/imports.js +55 -7
  9. package/cjs/index.js +2 -0
  10. package/cjs/selection-set-processor/pre-resolve-types.js +9 -5
  11. package/cjs/selection-set-to-object.js +12 -18
  12. package/cjs/utils.js +22 -1
  13. package/esm/base-documents-visitor.js +8 -0
  14. package/esm/base-resolvers-visitor.js +5 -7
  15. package/esm/base-types-visitor.js +41 -88
  16. package/esm/base-visitor.js +1 -7
  17. package/esm/client-side-base-visitor.js +5 -15
  18. package/esm/convert-schema-enum-to-declaration-block-string.js +159 -0
  19. package/esm/graphql-type-utils.js +11 -0
  20. package/esm/imports.js +53 -7
  21. package/esm/index.js +2 -0
  22. package/esm/selection-set-processor/pre-resolve-types.js +11 -7
  23. package/esm/selection-set-to-object.js +12 -18
  24. package/esm/utils.js +20 -0
  25. package/package.json +2 -2
  26. package/typings/base-documents-visitor.d.cts +49 -1
  27. package/typings/base-documents-visitor.d.ts +49 -1
  28. package/typings/base-types-visitor.d.cts +1 -6
  29. package/typings/base-types-visitor.d.ts +1 -6
  30. package/typings/base-visitor.d.cts +1 -8
  31. package/typings/base-visitor.d.ts +1 -8
  32. package/typings/convert-schema-enum-to-declaration-block-string.d.cts +25 -0
  33. package/typings/convert-schema-enum-to-declaration-block-string.d.ts +25 -0
  34. package/typings/graphql-type-utils.d.cts +2 -0
  35. package/typings/graphql-type-utils.d.ts +2 -0
  36. package/typings/imports.d.cts +12 -2
  37. package/typings/imports.d.ts +12 -2
  38. package/typings/index.d.cts +2 -0
  39. package/typings/index.d.ts +2 -0
  40. package/typings/selection-set-processor/base.d.cts +5 -3
  41. package/typings/selection-set-processor/base.d.ts +5 -3
  42. package/typings/selection-set-to-object.d.cts +4 -4
  43. package/typings/selection-set-to-object.d.ts +4 -4
  44. package/typings/utils.d.cts +2 -1
  45. package/typings/utils.d.ts +2 -1
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' : ''}`;
@@ -62,3 +56,55 @@ export function clearExtension(path) {
62
56
  export function fixLocalFilePath(path) {
63
57
  return path.startsWith('..') ? path : `./${path}`;
64
58
  }
59
+ export function getEnumsImports({ enumValues, useTypeImports, }) {
60
+ function handleEnumValueMapper({ typeIdentifier, importIdentifier, sourceIdentifier, sourceFile, useTypeImports, }) {
61
+ if (importIdentifier !== sourceIdentifier) {
62
+ // use namespace import to dereference nested enum
63
+ // { enumValues: { MyEnum: './my-file#NS.NestedEnum' } }
64
+ return [
65
+ buildTypeImport({ identifier: importIdentifier || sourceIdentifier, source: sourceFile, useTypeImports }),
66
+ `import ${typeIdentifier} = ${sourceIdentifier};`,
67
+ ];
68
+ }
69
+ if (sourceIdentifier !== typeIdentifier) {
70
+ return [
71
+ buildTypeImport({ identifier: `${sourceIdentifier} as ${typeIdentifier}`, source: sourceFile, useTypeImports }),
72
+ ];
73
+ }
74
+ return [buildTypeImport({ identifier: importIdentifier || sourceIdentifier, source: sourceFile, useTypeImports })];
75
+ }
76
+ return Object.keys(enumValues)
77
+ .flatMap(enumName => {
78
+ const mappedValue = enumValues[enumName];
79
+ if (mappedValue.sourceFile) {
80
+ if (mappedValue.isDefault) {
81
+ return [
82
+ buildTypeImport({
83
+ identifier: mappedValue.typeIdentifier,
84
+ source: mappedValue.sourceFile,
85
+ asDefault: true,
86
+ useTypeImports,
87
+ }),
88
+ ];
89
+ }
90
+ return handleEnumValueMapper({
91
+ typeIdentifier: mappedValue.typeIdentifier,
92
+ importIdentifier: mappedValue.importIdentifier,
93
+ sourceIdentifier: mappedValue.sourceIdentifier,
94
+ sourceFile: mappedValue.sourceFile,
95
+ useTypeImports,
96
+ });
97
+ }
98
+ return [];
99
+ })
100
+ .filter(Boolean);
101
+ }
102
+ export function buildTypeImport({ identifier, source, useTypeImports, asDefault = false, }) {
103
+ if (asDefault) {
104
+ if (useTypeImports) {
105
+ return `import type { default as ${identifier} } from '${source}';`;
106
+ }
107
+ return `import ${identifier} from '${source}';`;
108
+ }
109
+ return `import${useTypeImports ? ' type' : ''} { ${identifier} } from '${source}';`;
110
+ }
package/esm/index.js CHANGED
@@ -17,3 +17,5 @@ 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';
21
+ export * from './graphql-type-utils.js';
@@ -1,5 +1,5 @@
1
- import { getBaseType, removeNonNullWrapper } from '@graphql-codegen/plugin-helpers';
2
- import { isEnumType, isNonNullType } from 'graphql';
1
+ import { getBaseType } from '@graphql-codegen/plugin-helpers';
2
+ import { isEnumType } from 'graphql';
3
3
  import { BaseSelectionSetProcessor, } from './base.js';
4
4
  export class PreResolveTypesProcessor extends BaseSelectionSetProcessor {
5
5
  transformTypenameField(type, name) {
@@ -18,9 +18,10 @@ export class PreResolveTypesProcessor extends BaseSelectionSetProcessor {
18
18
  const fieldObj = schemaType.getFields()[field.fieldName];
19
19
  const baseType = getBaseType(fieldObj.type);
20
20
  let typeToUse = baseType.name;
21
- const useInnerType = field.isConditional && isNonNullType(fieldObj.type);
22
- const innerType = useInnerType ? removeNonNullWrapper(fieldObj.type) : undefined;
23
- const name = this.config.formatNamedField(field.fieldName, useInnerType ? innerType : fieldObj.type, field.isConditional, unsetTypes);
21
+ const name = this.config.formatNamedField({
22
+ name: field.fieldName,
23
+ isOptional: field.isConditional || unsetTypes,
24
+ });
24
25
  if (unsetTypes) {
25
26
  return {
26
27
  name,
@@ -51,7 +52,7 @@ export class PreResolveTypesProcessor extends BaseSelectionSetProcessor {
51
52
  }
52
53
  return fields.map(aliasedField => {
53
54
  if (aliasedField.fieldName === '__typename') {
54
- const name = this.config.formatNamedField(aliasedField.alias, null);
55
+ const name = this.config.formatNamedField({ name: aliasedField.alias });
55
56
  return {
56
57
  name,
57
58
  type: `'${schemaType.name}'`,
@@ -68,7 +69,10 @@ export class PreResolveTypesProcessor extends BaseSelectionSetProcessor {
68
69
  useTypesSuffix: this.config.enumSuffix,
69
70
  });
70
71
  }
71
- const name = this.config.formatNamedField(aliasedField.alias, fieldObj.type, aliasedField.isConditional, unsetTypes);
72
+ const name = this.config.formatNamedField({
73
+ name: aliasedField.alias,
74
+ isOptional: aliasedField.isConditional || unsetTypes,
75
+ });
72
76
  if (unsetTypes) {
73
77
  return {
74
78
  type: 'never',
@@ -262,6 +262,7 @@ export class SelectionSetToObject {
262
262
  mustAddEmptyObject = true;
263
263
  }
264
264
  for (const incrementalNode of incrementalNodes) {
265
+ // 1. fragment masking
265
266
  if (this._config.inlineFragmentTypes === 'mask' && 'fragmentName' in incrementalNode) {
266
267
  const { fields: incrementalFields, dependentTypes: incrementalDependentTypes } = this.buildSelectionSet(schemaType, [incrementalNode], { unsetTypes: true, parentFieldName: parentName });
267
268
  const incrementalSet = this.selectionSetStringFromFields(incrementalFields);
@@ -269,6 +270,7 @@ export class SelectionSetToObject {
269
270
  dependentTypes.push(...incrementalDependentTypes);
270
271
  continue;
271
272
  }
273
+ // 2. @defer
272
274
  const { fields: initialFields, dependentTypes: initialDependentTypes } = this.buildSelectionSet(schemaType, [incrementalNode], { parentFieldName: parentName });
273
275
  const { fields: subsequentFields, dependentTypes: subsequentDependentTypes } = this.buildSelectionSet(schemaType, [incrementalNode], { unsetTypes: true, parentFieldName: parentName });
274
276
  const initialSet = this.selectionSetStringFromFields(initialFields);
@@ -462,12 +464,17 @@ export class SelectionSetToObject {
462
464
  const selectionSetObjects = selectionSet.transformSelectionSet(options.parentFieldName ? `${options.parentFieldName}_${fieldName}` : fieldName);
463
465
  linkFieldsInterfaces.push(...selectionSetObjects.dependentTypes);
464
466
  const isConditional = hasConditionalDirectives(field) || inlineFragmentConditional;
465
- const isOptional = options.unsetTypes;
466
467
  linkFields.push({
467
468
  alias: field.alias
468
- ? this._processor.config.formatNamedField(field.alias.value, selectedFieldType, isConditional, isOptional)
469
+ ? this._processor.config.formatNamedField({
470
+ name: field.alias.value,
471
+ isOptional: isConditional || options.unsetTypes,
472
+ })
469
473
  : undefined,
470
- name: this._processor.config.formatNamedField(field.name.value, selectedFieldType, isConditional, isOptional),
474
+ name: this._processor.config.formatNamedField({
475
+ name: field.name.value,
476
+ isOptional: isConditional || options.unsetTypes,
477
+ }),
471
478
  type: realSelectedFieldType.name,
472
479
  selectionSet: this._processor.config.wrapTypeWithModifiers(selectionSetObjects.mergedTypeString.split(`\n`).join(`\n `), selectedFieldType),
473
480
  });
@@ -520,7 +527,7 @@ export class SelectionSetToObject {
520
527
  if (nonOptionalTypename || addTypename || queriedForTypename) {
521
528
  const optionalTypename = !queriedForTypename && !nonOptionalTypename;
522
529
  return {
523
- name: `${this._processor.config.formatNamedField('__typename')}${optionalTypename ? '?' : ''}`,
530
+ name: this._processor.config.formatNamedField({ name: '__typename', isOptional: optionalTypename }),
524
531
  type: `'${type.name}'`,
525
532
  };
526
533
  }
@@ -679,20 +686,7 @@ export class SelectionSetToObject {
679
686
  buildParentFieldName(typeName, parentName) {
680
687
  // queries/mutations/fragments are guaranteed to be unique type names,
681
688
  // so we can skip affixing the field names with typeName
682
- if (operationTypes.includes(typeName)) {
683
- return parentName;
684
- }
685
- const schemaType = this._schema.getType(typeName);
686
- // Check if current selection set has fragments (e.g., "... AppNotificationFragment" or "... on AppNotification")
687
- const hasFragment = this._selectionSet?.selections?.some(selection => selection.kind === Kind.INLINE_FRAGMENT || selection.kind === Kind.FRAGMENT_SPREAD) ?? false;
688
- // When the parent schema type is an interface:
689
- // - If we're processing inline fragments, use the concrete type name
690
- // - If we're processing the interface directly, use the interface name
691
- // - If we're in a named fragment, always use the concrete type name
692
- if (isObjectType(schemaType) && this._parentSchemaType && isInterfaceType(this._parentSchemaType) && !hasFragment) {
693
- return `${parentName}_${this._parentSchemaType.name}`;
694
- }
695
- return `${parentName}_${typeName}`;
689
+ return operationTypes.includes(typeName) ? parentName : `${parentName}_${typeName}`;
696
690
  }
697
691
  }
698
692
  function formatUnion(members) {
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.2",
3
+ "version": "7.0.0-alpha-20251224115216-0c4a535bdb152e75b9296d4c259f7dad0a13158f",
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",
@@ -19,6 +19,8 @@ export interface ParsedDocumentsConfig extends ParsedTypesConfig {
19
19
  experimentalFragmentVariables: boolean;
20
20
  mergeFragmentTypes: boolean;
21
21
  customDirectives: CustomDirectivesConfig;
22
+ generatesOperationTypes: boolean;
23
+ importSchemaTypesFrom: string;
22
24
  }
23
25
  export interface RawDocumentsConfig extends RawTypesConfig {
24
26
  /**
@@ -149,6 +151,52 @@ export interface RawDocumentsConfig extends RawTypesConfig {
149
151
  * ```
150
152
  */
151
153
  customDirectives?: CustomDirectivesConfig;
154
+ /**
155
+ * @description Whether to generate operation types such as Variables, Query/Mutation/Subscription selection set, and Fragment types
156
+ * This can be used with `importSchemaTypesFrom` to generate shared used Enums and Input.
157
+ * @default true
158
+ * @exampleMarkdown
159
+ * ```ts filename="codegen.ts"
160
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
161
+ *
162
+ * const config: CodegenConfig = {
163
+ * // ...
164
+ * generates: {
165
+ * 'path/to/file.ts': {
166
+ * plugins: ['typescript-operations'],
167
+ * config: {
168
+ * generatesOperationTypes: false,
169
+ * },
170
+ * },
171
+ * },
172
+ * };
173
+ * export default config;
174
+ * ```
175
+ */
176
+ generatesOperationTypes?: boolean;
177
+ /**
178
+ * @description The absolute (prefixed with `~`) or relative path from `cwd` to the shared used Enums and Input (See `generatesOperationTypes`).
179
+ * @default true
180
+ * @exampleMarkdown
181
+ * ```ts filename="codegen.ts"
182
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
183
+ *
184
+ * const config: CodegenConfig = {
185
+ * // ...
186
+ * generates: {
187
+ * 'path/to/file.ts': {
188
+ * plugins: ['typescript-operations'],
189
+ * config: {
190
+ * importSchemaTypesFrom: './path/to/shared-types.ts', // relative
191
+ * importSchemaTypesFrom: '~@my-org/package' // absolute
192
+ * },
193
+ * },
194
+ * },
195
+ * };
196
+ * export default config;
197
+ * ```
198
+ */
199
+ importSchemaTypesFrom?: string;
152
200
  }
153
201
  export declare class BaseDocumentsVisitor<TRawConfig extends RawDocumentsConfig = RawDocumentsConfig, TPluginConfig extends ParsedDocumentsConfig = ParsedDocumentsConfig> extends BaseVisitor<TRawConfig, TPluginConfig> {
154
202
  protected _schema: GraphQLSchema;
@@ -166,5 +214,5 @@ export declare class BaseDocumentsVisitor<TRawConfig extends RawDocumentsConfig
166
214
  private handleAnonymousOperation;
167
215
  FragmentDefinition(node: FragmentDefinitionNode): string;
168
216
  protected applyVariablesWrapper(variablesBlock: string, _operationType?: string): string;
169
- OperationDefinition(node: OperationDefinitionNode): string;
217
+ OperationDefinition(node: OperationDefinitionNode): string | null;
170
218
  }
@@ -19,6 +19,8 @@ export interface ParsedDocumentsConfig extends ParsedTypesConfig {
19
19
  experimentalFragmentVariables: boolean;
20
20
  mergeFragmentTypes: boolean;
21
21
  customDirectives: CustomDirectivesConfig;
22
+ generatesOperationTypes: boolean;
23
+ importSchemaTypesFrom: string;
22
24
  }
23
25
  export interface RawDocumentsConfig extends RawTypesConfig {
24
26
  /**
@@ -149,6 +151,52 @@ export interface RawDocumentsConfig extends RawTypesConfig {
149
151
  * ```
150
152
  */
151
153
  customDirectives?: CustomDirectivesConfig;
154
+ /**
155
+ * @description Whether to generate operation types such as Variables, Query/Mutation/Subscription selection set, and Fragment types
156
+ * This can be used with `importSchemaTypesFrom` to generate shared used Enums and Input.
157
+ * @default true
158
+ * @exampleMarkdown
159
+ * ```ts filename="codegen.ts"
160
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
161
+ *
162
+ * const config: CodegenConfig = {
163
+ * // ...
164
+ * generates: {
165
+ * 'path/to/file.ts': {
166
+ * plugins: ['typescript-operations'],
167
+ * config: {
168
+ * generatesOperationTypes: false,
169
+ * },
170
+ * },
171
+ * },
172
+ * };
173
+ * export default config;
174
+ * ```
175
+ */
176
+ generatesOperationTypes?: boolean;
177
+ /**
178
+ * @description The absolute (prefixed with `~`) or relative path from `cwd` to the shared used Enums and Input (See `generatesOperationTypes`).
179
+ * @default true
180
+ * @exampleMarkdown
181
+ * ```ts filename="codegen.ts"
182
+ * import type { CodegenConfig } from '@graphql-codegen/cli';
183
+ *
184
+ * const config: CodegenConfig = {
185
+ * // ...
186
+ * generates: {
187
+ * 'path/to/file.ts': {
188
+ * plugins: ['typescript-operations'],
189
+ * config: {
190
+ * importSchemaTypesFrom: './path/to/shared-types.ts', // relative
191
+ * importSchemaTypesFrom: '~@my-org/package' // absolute
192
+ * },
193
+ * },
194
+ * },
195
+ * };
196
+ * export default config;
197
+ * ```
198
+ */
199
+ importSchemaTypesFrom?: string;
152
200
  }
153
201
  export declare class BaseDocumentsVisitor<TRawConfig extends RawDocumentsConfig = RawDocumentsConfig, TPluginConfig extends ParsedDocumentsConfig = ParsedDocumentsConfig> extends BaseVisitor<TRawConfig, TPluginConfig> {
154
202
  protected _schema: GraphQLSchema;
@@ -166,5 +214,5 @@ export declare class BaseDocumentsVisitor<TRawConfig extends RawDocumentsConfig
166
214
  private handleAnonymousOperation;
167
215
  FragmentDefinition(node: FragmentDefinitionNode): string;
168
216
  protected applyVariablesWrapper(variablesBlock: string, _operationType?: string): string;
169
- OperationDefinition(node: OperationDefinitionNode): string;
217
+ OperationDefinition(node: OperationDefinitionNode): string | null;
170
218
  }
@@ -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';
@@ -478,12 +478,9 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
478
478
  getInterfaceTypeDeclarationBlock(node: InterfaceTypeDefinitionNode, _originalNode: InterfaceTypeDefinitionNode): DeclarationBlock;
479
479
  InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode, key: number | string, parent: any): string;
480
480
  ScalarTypeDefinition(_node: ScalarTypeDefinitionNode): string;
481
- protected _buildTypeImport(identifier: string, source: string, asDefault?: boolean): string;
482
- protected handleEnumValueMapper(typeIdentifier: string, importIdentifier: string | null, sourceIdentifier: string | null, sourceFile: string | null): string[];
483
481
  getEnumsImports(): string[];
484
482
  EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
485
483
  protected makeValidEnumIdentifier(identifier: string): string;
486
- protected buildEnumValuesBlock(typeName: string, values: ReadonlyArray<EnumValueDefinitionNode>): string;
487
484
  DirectiveDefinition(_node: DirectiveDefinitionNode): string;
488
485
  getArgumentsObjectDeclarationBlock(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode, name: string, field: FieldDefinitionNode): DeclarationBlock;
489
486
  getArgumentsObjectTypeDefinition(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode, name: string, field: FieldDefinitionNode): string;
@@ -496,7 +493,5 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
496
493
  ListType(node: ListTypeNode, _key: any, _parent: any, _path: any, _ancestors: any): string;
497
494
  SchemaDefinition(): any;
498
495
  SchemaExtension(): any;
499
- getNodeComment(node: FieldDefinitionNode | EnumValueDefinitionNode | InputValueDefinitionNode): string;
500
- protected getDeprecationReason(directive: DirectiveNode): string | void;
501
496
  protected wrapWithListType(str: string): string;
502
497
  }
@@ -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';
@@ -478,12 +478,9 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
478
478
  getInterfaceTypeDeclarationBlock(node: InterfaceTypeDefinitionNode, _originalNode: InterfaceTypeDefinitionNode): DeclarationBlock;
479
479
  InterfaceTypeDefinition(node: InterfaceTypeDefinitionNode, key: number | string, parent: any): string;
480
480
  ScalarTypeDefinition(_node: ScalarTypeDefinitionNode): string;
481
- protected _buildTypeImport(identifier: string, source: string, asDefault?: boolean): string;
482
- protected handleEnumValueMapper(typeIdentifier: string, importIdentifier: string | null, sourceIdentifier: string | null, sourceFile: string | null): string[];
483
481
  getEnumsImports(): string[];
484
482
  EnumTypeDefinition(node: EnumTypeDefinitionNode): string;
485
483
  protected makeValidEnumIdentifier(identifier: string): string;
486
- protected buildEnumValuesBlock(typeName: string, values: ReadonlyArray<EnumValueDefinitionNode>): string;
487
484
  DirectiveDefinition(_node: DirectiveDefinitionNode): string;
488
485
  getArgumentsObjectDeclarationBlock(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode, name: string, field: FieldDefinitionNode): DeclarationBlock;
489
486
  getArgumentsObjectTypeDefinition(node: InterfaceTypeDefinitionNode | ObjectTypeDefinitionNode, name: string, field: FieldDefinitionNode): string;
@@ -496,7 +493,5 @@ export declare class BaseTypesVisitor<TRawConfig extends RawTypesConfig = RawTyp
496
493
  ListType(node: ListTypeNode, _key: any, _parent: any, _path: any, _ancestors: any): string;
497
494
  SchemaDefinition(): any;
498
495
  SchemaExtension(): any;
499
- getNodeComment(node: FieldDefinitionNode | EnumValueDefinitionNode | InputValueDefinitionNode): string;
500
- protected getDeprecationReason(directive: DirectiveNode): string | void;
501
496
  protected wrapWithListType(str: string): string;
502
497
  }
@@ -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,25 @@
1
+ import type { EnumTypeDefinitionNode, EnumValueDefinitionNode, GraphQLSchema } from 'graphql';
2
+ import type { ConvertFn, ParsedEnumValuesMap } from './types.cjs';
3
+ import { type DeclarationBlockConfig } from './utils.cjs';
4
+ export 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;
@@ -0,0 +1,25 @@
1
+ import type { EnumTypeDefinitionNode, EnumValueDefinitionNode, GraphQLSchema } from 'graphql';
2
+ import type { ConvertFn, ParsedEnumValuesMap } from './types.js';
3
+ import { type DeclarationBlockConfig } from './utils.js';
4
+ export 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;
@@ -0,0 +1,2 @@
1
+ import { type GraphQLNamedType } from 'graphql';
2
+ export declare const isNativeNamedType: (namedType: GraphQLNamedType) => boolean;
@@ -0,0 +1,2 @@
1
+ import { type GraphQLNamedType } from 'graphql';
2
+ export declare const isNativeNamedType: (namedType: GraphQLNamedType) => boolean;
@@ -1,11 +1,11 @@
1
+ import type { ParsedEnumValuesMap } from './types';
1
2
  export type ImportDeclaration<T = string> = {
2
3
  outputPath: string;
3
4
  importSource: ImportSource<T>;
4
5
  baseOutputDir: string;
5
6
  baseDir: string;
6
7
  typesImport: boolean;
7
- emitLegacyCommonJSImports?: boolean;
8
- importExtension: '' | `.${string}`;
8
+ emitLegacyCommonJSImports: boolean;
9
9
  };
10
10
  export type ImportSource<T = string> = {
11
11
  /**
@@ -31,3 +31,13 @@ export declare function resolveRelativeImport(from: string, to: string): string;
31
31
  export declare function resolveImportSource<T>(source: string | ImportSource<T>): ImportSource<T>;
32
32
  export declare function clearExtension(path: string): string;
33
33
  export declare function fixLocalFilePath(path: string): string;
34
+ export declare function getEnumsImports({ enumValues, useTypeImports, }: {
35
+ enumValues: ParsedEnumValuesMap;
36
+ useTypeImports: boolean;
37
+ }): string[];
38
+ export declare function buildTypeImport({ identifier, source, useTypeImports, asDefault, }: {
39
+ identifier: string;
40
+ source: string;
41
+ useTypeImports: boolean;
42
+ asDefault?: boolean;
43
+ }): string;
@@ -1,11 +1,11 @@
1
+ import type { ParsedEnumValuesMap } from './types';
1
2
  export type ImportDeclaration<T = string> = {
2
3
  outputPath: string;
3
4
  importSource: ImportSource<T>;
4
5
  baseOutputDir: string;
5
6
  baseDir: string;
6
7
  typesImport: boolean;
7
- emitLegacyCommonJSImports?: boolean;
8
- importExtension: '' | `.${string}`;
8
+ emitLegacyCommonJSImports: boolean;
9
9
  };
10
10
  export type ImportSource<T = string> = {
11
11
  /**
@@ -31,3 +31,13 @@ export declare function resolveRelativeImport(from: string, to: string): string;
31
31
  export declare function resolveImportSource<T>(source: string | ImportSource<T>): ImportSource<T>;
32
32
  export declare function clearExtension(path: string): string;
33
33
  export declare function fixLocalFilePath(path: string): string;
34
+ export declare function getEnumsImports({ enumValues, useTypeImports, }: {
35
+ enumValues: ParsedEnumValuesMap;
36
+ useTypeImports: boolean;
37
+ }): string[];
38
+ export declare function buildTypeImport({ identifier, source, useTypeImports, asDefault, }: {
39
+ identifier: string;
40
+ source: string;
41
+ useTypeImports: boolean;
42
+ asDefault?: boolean;
43
+ }): string;
@@ -17,3 +17,5 @@ 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';
21
+ export * from './graphql-type-utils.cjs';
@@ -17,3 +17,5 @@ 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';
21
+ export * from './graphql-type-utils.js';
@@ -1,5 +1,5 @@
1
1
  import { GraphQLInterfaceType, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, Location } from 'graphql';
2
- import { AvoidOptionalsConfig, ConvertNameFn, NormalizedScalarsMap } from '../types.cjs';
2
+ import { ConvertNameFn, NormalizedScalarsMap } from '../types.cjs';
3
3
  export type PrimitiveField = {
4
4
  isConditional: boolean;
5
5
  fieldName: string;
@@ -26,9 +26,11 @@ export type SelectionSetProcessorConfig = {
26
26
  enumPrefix: boolean | null;
27
27
  enumSuffix: boolean | null;
28
28
  scalars: NormalizedScalarsMap;
29
- formatNamedField(name: string, type?: GraphQLOutputType | GraphQLNamedType | null, isConditional?: boolean, isOptional?: boolean): string;
29
+ formatNamedField(params: {
30
+ name: string;
31
+ isOptional?: boolean;
32
+ }): string;
30
33
  wrapTypeWithModifiers(baseType: string, type: GraphQLOutputType | GraphQLNamedType): string;
31
- avoidOptionals?: AvoidOptionalsConfig | boolean;
32
34
  printFieldsOnNewLines?: boolean;
33
35
  };
34
36
  export declare class BaseSelectionSetProcessor<Config extends SelectionSetProcessorConfig> {