@graphql-codegen/visitor-plugin-common 7.0.3 → 7.0.4

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 ||
96
96
  this.config.documentMode === DocumentMode.string) {
@@ -102,6 +102,9 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
102
102
  if (this.config.documentMode === DocumentMode.documentNodeImportFragments) {
103
103
  return '';
104
104
  }
105
+ if (nodeKind !== 'OperationDefinition') {
106
+ return '';
107
+ }
105
108
  return String(fragments.map(name => '${' + name + '}').join('\n'));
106
109
  }
107
110
  return '';
@@ -111,12 +114,13 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
111
114
  }
112
115
  _gql(node) {
113
116
  const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode ||
114
- this.config.documentMode === DocumentMode.string;
117
+ this.config.documentMode === DocumentMode.string ||
118
+ node.kind === 'OperationDefinition';
115
119
  const fragmentNames = this._extractFragments(node, includeNestedFragments);
116
120
  const fragments = this._transformFragments(fragmentNames);
117
121
  const doc = this._prepareDocument(`
118
122
  ${(0, graphql_1.print)(node).split('\\').join('\\\\') /* Re-escape escaped values in GraphQL syntax */}
119
- ${this._includeFragments(fragments)}`);
123
+ ${this._includeFragments(fragments, node.kind)}`);
120
124
  if (this.config.documentMode === DocumentMode.documentNode) {
121
125
  let gqlObj = (0, graphql_tag_1.default)([doc]);
122
126
  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 ||
92
92
  this.config.documentMode === DocumentMode.string) {
@@ -98,6 +98,9 @@ export class ClientSideBaseVisitor extends BaseVisitor {
98
98
  if (this.config.documentMode === DocumentMode.documentNodeImportFragments) {
99
99
  return '';
100
100
  }
101
+ if (nodeKind !== 'OperationDefinition') {
102
+ return '';
103
+ }
101
104
  return String(fragments.map(name => '${' + name + '}').join('\n'));
102
105
  }
103
106
  return '';
@@ -107,12 +110,13 @@ export class ClientSideBaseVisitor extends BaseVisitor {
107
110
  }
108
111
  _gql(node) {
109
112
  const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode ||
110
- this.config.documentMode === DocumentMode.string;
113
+ this.config.documentMode === DocumentMode.string ||
114
+ node.kind === 'OperationDefinition';
111
115
  const fragmentNames = this._extractFragments(node, includeNestedFragments);
112
116
  const fragments = this._transformFragments(fragmentNames);
113
117
  const doc = this._prepareDocument(`
114
118
  ${print(node).split('\\').join('\\\\') /* Re-escape escaped values in GraphQL syntax */}
115
- ${this._includeFragments(fragments)}`);
119
+ ${this._includeFragments(fragments, node.kind)}`);
116
120
  if (this.config.documentMode === DocumentMode.documentNode) {
117
121
  let gqlObj = gqlTag([doc]);
118
122
  if (this.config.optimizeDocumentNode) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/visitor-plugin-common",
3
- "version": "7.0.3",
3
+ "version": "7.0.4",
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;