@graphql-codegen/visitor-plugin-common 3.1.0-alpha-20230320094222-69e0fe22f → 3.1.0-alpha-20230320114137-e954beaff

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.
@@ -91,7 +91,7 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
91
91
  }
92
92
  _includeFragments(fragments, nodeKind) {
93
93
  if (fragments && fragments.length > 0) {
94
- if (this.config.documentMode === DocumentMode.documentNode) {
94
+ if (this.config.documentMode === DocumentMode.documentNode || this.config.documentMode === DocumentMode.string) {
95
95
  return Array.from(this._fragments.values())
96
96
  .filter(f => fragments.includes(this.getFragmentVariableName(f.name)))
97
97
  .map(fragment => (0, graphql_1.print)(fragment.node))
@@ -164,7 +164,20 @@ class ClientSideBaseVisitor extends base_visitor_js_1.BaseVisitor {
164
164
  return `{${metaString}"kind":"${graphql_1.Kind.DOCUMENT}","definitions":${jsonStringify(definitions)}}`;
165
165
  }
166
166
  if (this.config.documentMode === DocumentMode.string) {
167
- return '`' + doc + '`';
167
+ let meta;
168
+ if (this._onExecutableDocumentNode && node.kind === graphql_1.Kind.OPERATION_DEFINITION) {
169
+ meta = this._onExecutableDocumentNode({
170
+ kind: graphql_1.Kind.DOCUMENT,
171
+ definitions: (0, graphql_tag_1.default)([doc]).definitions,
172
+ });
173
+ if (meta && this._omitDefinitions === true) {
174
+ return `{${`"__meta__":${JSON.stringify(meta)},`.slice(0, -1)}}`;
175
+ }
176
+ }
177
+ if (meta) {
178
+ return `new TypedDocumentString(\`${doc}\`, ${JSON.stringify(meta)})`;
179
+ }
180
+ return `new TypedDocumentString(\`${doc}\`)`;
168
181
  }
169
182
  const gqlImport = this._parseImport(this.config.gqlImport || 'graphql-tag');
170
183
  return (gqlImport.propName || 'gql') + '`' + doc + '`';
@@ -87,7 +87,7 @@ export class ClientSideBaseVisitor extends BaseVisitor {
87
87
  }
88
88
  _includeFragments(fragments, nodeKind) {
89
89
  if (fragments && fragments.length > 0) {
90
- if (this.config.documentMode === DocumentMode.documentNode) {
90
+ if (this.config.documentMode === DocumentMode.documentNode || this.config.documentMode === DocumentMode.string) {
91
91
  return Array.from(this._fragments.values())
92
92
  .filter(f => fragments.includes(this.getFragmentVariableName(f.name)))
93
93
  .map(fragment => print(fragment.node))
@@ -160,7 +160,20 @@ export class ClientSideBaseVisitor extends BaseVisitor {
160
160
  return `{${metaString}"kind":"${Kind.DOCUMENT}","definitions":${jsonStringify(definitions)}}`;
161
161
  }
162
162
  if (this.config.documentMode === DocumentMode.string) {
163
- return '`' + doc + '`';
163
+ let meta;
164
+ if (this._onExecutableDocumentNode && node.kind === Kind.OPERATION_DEFINITION) {
165
+ meta = this._onExecutableDocumentNode({
166
+ kind: Kind.DOCUMENT,
167
+ definitions: gqlTag([doc]).definitions,
168
+ });
169
+ if (meta && this._omitDefinitions === true) {
170
+ return `{${`"__meta__":${JSON.stringify(meta)},`.slice(0, -1)}}`;
171
+ }
172
+ }
173
+ if (meta) {
174
+ return `new TypedDocumentString(\`${doc}\`, ${JSON.stringify(meta)})`;
175
+ }
176
+ return `new TypedDocumentString(\`${doc}\`)`;
164
177
  }
165
178
  const gqlImport = this._parseImport(this.config.gqlImport || 'graphql-tag');
166
179
  return (gqlImport.propName || 'gql') + '`' + doc + '`';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@graphql-codegen/visitor-plugin-common",
3
- "version": "3.1.0-alpha-20230320094222-69e0fe22f",
3
+ "version": "3.1.0-alpha-20230320114137-e954beaff",
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": "^1.3.0",
9
- "@graphql-codegen/plugin-helpers": "4.2.0-alpha-20230320094222-69e0fe22f",
9
+ "@graphql-codegen/plugin-helpers": "4.2.0-alpha-20230320114137-e954beaff",
10
10
  "@graphql-tools/relay-operation-optimizer": "^6.5.0",
11
11
  "@graphql-tools/utils": "^9.0.0",
12
12
  "auto-bind": "~4.0.0",