@graphql-codegen/visitor-plugin-common 6.2.2 → 6.2.3-alpha-20251226140101-7572bb12f904056cb4f4e91c2244e9d893cfd9d2

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.
@@ -90,7 +90,7 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
90
90
  _transformFragments(fragmentNames) {
91
91
  return fragmentNames.map(document => this.getFragmentVariableName(document));
92
92
  }
93
- _includeFragments(fragments) {
93
+ _includeFragments(fragments, nodeKind) {
94
94
  if (fragments && fragments.length > 0) {
95
95
  if (this.config.documentMode === DocumentMode.documentNode || this.config.documentMode === DocumentMode.string) {
96
96
  return Array.from(this._fragments.values())
@@ -101,6 +101,9 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
101
101
  if (this.config.documentMode === DocumentMode.documentNodeImportFragments) {
102
102
  return '';
103
103
  }
104
+ if (nodeKind !== 'OperationDefinition') {
105
+ return '';
106
+ }
104
107
  return String(fragments.map(name => '${' + name + '}').join('\n'));
105
108
  }
106
109
  return '';
@@ -109,12 +112,14 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
109
112
  return documentStr;
110
113
  }
111
114
  _gql(node) {
112
- const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode || this.config.documentMode === DocumentMode.string;
115
+ const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode ||
116
+ this.config.documentMode === DocumentMode.string ||
117
+ node.kind === 'OperationDefinition';
113
118
  const fragmentNames = this._extractFragments(node, includeNestedFragments);
114
119
  const fragments = this._transformFragments(fragmentNames);
115
120
  const doc = this._prepareDocument(`
116
121
  ${(0, graphql_1.print)(node).split('\\').join('\\\\') /* Re-escape escaped values in GraphQL syntax */}
117
- ${this._includeFragments(fragments)}`);
122
+ ${this._includeFragments(fragments, node.kind)}`);
118
123
  if (this.config.documentMode === DocumentMode.documentNode) {
119
124
  let gqlObj = (0, graphql_tag_1.default)([doc]);
120
125
  if (this.config.optimizeDocumentNode) {
@@ -86,7 +86,7 @@ export class ClientSideBaseVisitor extends BaseVisitor {
86
86
  _transformFragments(fragmentNames) {
87
87
  return fragmentNames.map(document => this.getFragmentVariableName(document));
88
88
  }
89
- _includeFragments(fragments) {
89
+ _includeFragments(fragments, nodeKind) {
90
90
  if (fragments && fragments.length > 0) {
91
91
  if (this.config.documentMode === DocumentMode.documentNode || this.config.documentMode === DocumentMode.string) {
92
92
  return Array.from(this._fragments.values())
@@ -97,6 +97,9 @@ export class ClientSideBaseVisitor extends BaseVisitor {
97
97
  if (this.config.documentMode === DocumentMode.documentNodeImportFragments) {
98
98
  return '';
99
99
  }
100
+ if (nodeKind !== 'OperationDefinition') {
101
+ return '';
102
+ }
100
103
  return String(fragments.map(name => '${' + name + '}').join('\n'));
101
104
  }
102
105
  return '';
@@ -105,12 +108,14 @@ export class ClientSideBaseVisitor extends BaseVisitor {
105
108
  return documentStr;
106
109
  }
107
110
  _gql(node) {
108
- const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode || this.config.documentMode === DocumentMode.string;
111
+ const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode ||
112
+ this.config.documentMode === DocumentMode.string ||
113
+ node.kind === 'OperationDefinition';
109
114
  const fragmentNames = this._extractFragments(node, includeNestedFragments);
110
115
  const fragments = this._transformFragments(fragmentNames);
111
116
  const doc = this._prepareDocument(`
112
117
  ${print(node).split('\\').join('\\\\') /* Re-escape escaped values in GraphQL syntax */}
113
- ${this._includeFragments(fragments)}`);
118
+ ${this._includeFragments(fragments, node.kind)}`);
114
119
  if (this.config.documentMode === DocumentMode.documentNode) {
115
120
  let gqlObj = gqlTag([doc]);
116
121
  if (this.config.optimizeDocumentNode) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/visitor-plugin-common",
3
- "version": "6.2.2",
3
+ "version": "6.2.3-alpha-20251226140101-7572bb12f904056cb4f4e91c2244e9d893cfd9d2",
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
  },
@@ -219,7 +219,7 @@ export declare class ClientSideBaseVisitor<TRawConfig extends RawClientSideBaseP
219
219
  constructor(_schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: TRawConfig, additionalConfig: Partial<TPluginConfig>, documents?: Types.DocumentFile[]);
220
220
  protected _extractFragments(document: FragmentDefinitionNode | OperationDefinitionNode, withNested?: boolean): string[];
221
221
  protected _transformFragments(fragmentNames: Array<string>): string[];
222
- protected _includeFragments(fragments: string[]): string;
222
+ protected _includeFragments(fragments: string[], nodeKind: 'FragmentDefinition' | 'OperationDefinition'): string;
223
223
  protected _prepareDocument(documentStr: string): string;
224
224
  protected _gql(node: FragmentDefinitionNode | OperationDefinitionNode): string;
225
225
  protected _getGraphQLCodegenMetadata(node: OperationDefinitionNode | FragmentDefinitionNode, definitions?: ReadonlyArray<DefinitionNode>): Record<string, any> | void | undefined;
@@ -219,7 +219,7 @@ export declare class ClientSideBaseVisitor<TRawConfig extends RawClientSideBaseP
219
219
  constructor(_schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: TRawConfig, additionalConfig: Partial<TPluginConfig>, documents?: Types.DocumentFile[]);
220
220
  protected _extractFragments(document: FragmentDefinitionNode | OperationDefinitionNode, withNested?: boolean): string[];
221
221
  protected _transformFragments(fragmentNames: Array<string>): string[];
222
- protected _includeFragments(fragments: string[]): string;
222
+ protected _includeFragments(fragments: string[], nodeKind: 'FragmentDefinition' | 'OperationDefinition'): string;
223
223
  protected _prepareDocument(documentStr: string): string;
224
224
  protected _gql(node: FragmentDefinitionNode | OperationDefinitionNode): string;
225
225
  protected _getGraphQLCodegenMetadata(node: OperationDefinitionNode | FragmentDefinitionNode, definitions?: ReadonlyArray<DefinitionNode>): Record<string, any> | void | undefined;