@graphql-codegen/typescript-operations 6.1.2 → 6.1.3-alpha-20260730134801-441aaf85f717acbb113e395fbac4c3d7863e7a42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/visitor.js CHANGED
@@ -10,6 +10,11 @@ const ts_operation_variables_to_object_js_1 = require("./ts-operation-variables-
10
10
  class TypeScriptDocumentsVisitor extends visitor_plugin_common_1.BaseDocumentsVisitor {
11
11
  _usedSchemaTypes = {};
12
12
  _needsExactUtilityType = false;
13
+ /**
14
+ * _externalImports is used to track imports from
15
+ * The key is the module and value is the named imports
16
+ */
17
+ _externalImports = { graphql: new Set() };
13
18
  _outputPath;
14
19
  constructor(schema, config, documentNode, outputPath) {
15
20
  super(config, {
@@ -85,7 +90,7 @@ class TypeScriptDocumentsVisitor extends visitor_plugin_common_1.BaseDocumentsVi
85
90
  },
86
91
  printFieldsOnNewLines: this.config.printFieldsOnNewLines,
87
92
  };
88
- this.setSelectionSetHandler(new visitor_plugin_common_1.SelectionSetToObject(new visitor_plugin_common_1.PreResolveTypesProcessor(processorConfig), this.scalars, this.schema, this.convertName.bind(this), this.getFragmentSuffix.bind(this), allFragments, this.config));
93
+ this.setSelectionSetHandler(new visitor_plugin_common_1.SelectionSetToObject(new visitor_plugin_common_1.PreResolveTypesProcessor(processorConfig), this.scalars, this.schema, this.convertName.bind(this), this.getFragmentSuffix.bind(this), allFragments, this.config, this._externalImports));
89
94
  const enumsNames = Object.keys(schema.getTypeMap()).filter(typeName => (0, graphql_1.isEnumType)(schema.getType(typeName)));
90
95
  this.setVariablesTransformer(new ts_operation_variables_to_object_js_1.TypeScriptOperationVariablesToObject({
91
96
  avoidOptionals: this.config.avoidOptionals,
@@ -245,10 +250,34 @@ class TypeScriptDocumentsVisitor extends visitor_plugin_common_1.BaseDocumentsVi
245
250
  return currentInputValue;
246
251
  }
247
252
  getImports() {
248
- return !this.config.globalNamespace &&
249
- (this.config.inlineFragmentTypes === 'combine' || this.config.inlineFragmentTypes === 'mask')
250
- ? this.config.fragmentImports.map(fragmentImport => (0, visitor_plugin_common_1.generateFragmentImportStatement)(fragmentImport, 'type'))
251
- : [];
253
+ if (this.config.globalNamespace) {
254
+ return [];
255
+ }
256
+ const result = [];
257
+ if (this._externalImports.graphql.size > 0) {
258
+ result.push((0, visitor_plugin_common_1.generateImportStatement)({
259
+ baseDir: process.cwd(),
260
+ baseOutputDir: '',
261
+ outputPath: this._outputPath,
262
+ importSource: {
263
+ path: '~graphql',
264
+ identifiers: [...this._externalImports.graphql],
265
+ },
266
+ typesImport: true,
267
+ emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
268
+ importExtension: (0, plugin_helpers_1.normalizeImportExtension)({
269
+ emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
270
+ importExtension: this.config.importExtension,
271
+ }),
272
+ }));
273
+ }
274
+ if (this.config.inlineFragmentTypes === 'combine' ||
275
+ this.config.inlineFragmentTypes === 'mask') {
276
+ for (const fragmentImport of this.config.fragmentImports) {
277
+ result.push((0, visitor_plugin_common_1.generateFragmentImportStatement)(fragmentImport, 'type'));
278
+ }
279
+ }
280
+ return result;
252
281
  }
253
282
  getExternalSchemaTypeImports() {
254
283
  if (!this.config.importSchemaTypesFrom) {
package/esm/visitor.js CHANGED
@@ -6,6 +6,11 @@ import { TypeScriptOperationVariablesToObject } from './ts-operation-variables-t
6
6
  export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor {
7
7
  _usedSchemaTypes = {};
8
8
  _needsExactUtilityType = false;
9
+ /**
10
+ * _externalImports is used to track imports from
11
+ * The key is the module and value is the named imports
12
+ */
13
+ _externalImports = { graphql: new Set() };
9
14
  _outputPath;
10
15
  constructor(schema, config, documentNode, outputPath) {
11
16
  super(config, {
@@ -81,7 +86,7 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor {
81
86
  },
82
87
  printFieldsOnNewLines: this.config.printFieldsOnNewLines,
83
88
  };
84
- this.setSelectionSetHandler(new SelectionSetToObject(new PreResolveTypesProcessor(processorConfig), this.scalars, this.schema, this.convertName.bind(this), this.getFragmentSuffix.bind(this), allFragments, this.config));
89
+ this.setSelectionSetHandler(new SelectionSetToObject(new PreResolveTypesProcessor(processorConfig), this.scalars, this.schema, this.convertName.bind(this), this.getFragmentSuffix.bind(this), allFragments, this.config, this._externalImports));
85
90
  const enumsNames = Object.keys(schema.getTypeMap()).filter(typeName => isEnumType(schema.getType(typeName)));
86
91
  this.setVariablesTransformer(new TypeScriptOperationVariablesToObject({
87
92
  avoidOptionals: this.config.avoidOptionals,
@@ -241,10 +246,34 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor {
241
246
  return currentInputValue;
242
247
  }
243
248
  getImports() {
244
- return !this.config.globalNamespace &&
245
- (this.config.inlineFragmentTypes === 'combine' || this.config.inlineFragmentTypes === 'mask')
246
- ? this.config.fragmentImports.map(fragmentImport => generateFragmentImportStatement(fragmentImport, 'type'))
247
- : [];
249
+ if (this.config.globalNamespace) {
250
+ return [];
251
+ }
252
+ const result = [];
253
+ if (this._externalImports.graphql.size > 0) {
254
+ result.push(generateImportStatement({
255
+ baseDir: process.cwd(),
256
+ baseOutputDir: '',
257
+ outputPath: this._outputPath,
258
+ importSource: {
259
+ path: '~graphql',
260
+ identifiers: [...this._externalImports.graphql],
261
+ },
262
+ typesImport: true,
263
+ emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
264
+ importExtension: normalizeImportExtension({
265
+ emitLegacyCommonJSImports: this.config.emitLegacyCommonJSImports,
266
+ importExtension: this.config.importExtension,
267
+ }),
268
+ }));
269
+ }
270
+ if (this.config.inlineFragmentTypes === 'combine' ||
271
+ this.config.inlineFragmentTypes === 'mask') {
272
+ for (const fragmentImport of this.config.fragmentImports) {
273
+ result.push(generateFragmentImportStatement(fragmentImport, 'type'));
274
+ }
275
+ }
276
+ return result;
248
277
  }
249
278
  getExternalSchemaTypeImports() {
250
279
  if (!this.config.importSchemaTypesFrom) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-operations",
3
- "version": "6.1.2",
3
+ "version": "6.1.3-alpha-20260730134801-441aaf85f717acbb113e395fbac4c3d7863e7a42",
4
4
  "description": "GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments",
5
5
  "peerDependenciesMeta": {
6
6
  "graphql-sock": {
@@ -14,9 +14,9 @@
14
14
  "dependencies": {
15
15
  "auto-bind": "^5.0.0",
16
16
  "tslib": "^2.8.0",
17
- "@graphql-codegen/plugin-helpers": "^7.1.0",
18
- "@graphql-codegen/visitor-plugin-common": "^7.2.2",
19
- "@graphql-codegen/schema-ast": "^6.1.0"
17
+ "@graphql-codegen/visitor-plugin-common": "^7.2.3-alpha-20260730134801-441aaf85f717acbb113e395fbac4c3d7863e7a42",
18
+ "@graphql-codegen/schema-ast": "^6.1.0",
19
+ "@graphql-codegen/plugin-helpers": "^7.1.0"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
@@ -34,6 +34,13 @@ type UsedSchemaTypes = Record<string, {
34
34
  export declare class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<TypeScriptDocumentsPluginConfig, TypeScriptDocumentsParsedConfig> {
35
35
  protected _usedSchemaTypes: UsedSchemaTypes;
36
36
  protected _needsExactUtilityType: boolean;
37
+ /**
38
+ * _externalImports is used to track imports from
39
+ * The key is the module and value is the named imports
40
+ */
41
+ protected _externalImports: {
42
+ graphql: Set<string>;
43
+ };
37
44
  private _outputPath;
38
45
  constructor(schema: GraphQLSchema, config: TypeScriptDocumentsPluginConfig, documentNode: DocumentNode, outputPath: string);
39
46
  EnumTypeDefinition(node: EnumTypeDefinitionNode): string | null;
@@ -34,6 +34,13 @@ type UsedSchemaTypes = Record<string, {
34
34
  export declare class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<TypeScriptDocumentsPluginConfig, TypeScriptDocumentsParsedConfig> {
35
35
  protected _usedSchemaTypes: UsedSchemaTypes;
36
36
  protected _needsExactUtilityType: boolean;
37
+ /**
38
+ * _externalImports is used to track imports from
39
+ * The key is the module and value is the named imports
40
+ */
41
+ protected _externalImports: {
42
+ graphql: Set<string>;
43
+ };
37
44
  private _outputPath;
38
45
  constructor(schema: GraphQLSchema, config: TypeScriptDocumentsPluginConfig, documentNode: DocumentNode, outputPath: string);
39
46
  EnumTypeDefinition(node: EnumTypeDefinitionNode): string | null;