@graphql-codegen/gql-tag-operations 5.0.5 → 5.1.0-alpha-20251119131248-4aa0bce27decc294509fae591f5c2236858abdbb

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/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.plugin = void 0;
4
+ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
4
5
  const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
5
6
  const documentTypePartial = `
6
7
  export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode<
@@ -10,9 +11,13 @@ export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocume
10
11
  ? TType
11
12
  : never;
12
13
  `.split(`\n`);
13
- const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmentedModuleName, gqlTagName = 'gql', emitLegacyCommonJSImports, documentMode, }, _info) => {
14
+ const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmentedModuleName, gqlTagName = 'gql', emitLegacyCommonJSImports, importExtension, documentMode, }, _info) => {
15
+ const appendedImportExtension = (0, plugin_helpers_1.normalizeImportExtension)({
16
+ emitLegacyCommonJSImports,
17
+ importExtension,
18
+ });
14
19
  if (documentMode === visitor_plugin_common_1.DocumentMode.string) {
15
- const code = [`import * as types from './graphql${emitLegacyCommonJSImports ? '' : '.js'}';\n`, `\n`];
20
+ const code = [`import * as types from './graphql${appendedImportExtension}';\n`, `\n`];
16
21
  // We need the mapping from source as written to full document source to
17
22
  // handle fragments. An identity function would not suffice.
18
23
  if (sourcesWithOperations.length > 0) {
@@ -22,14 +27,14 @@ const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmentedModuleN
22
27
  code.push('const documents = {}');
23
28
  }
24
29
  if (sourcesWithOperations.length > 0) {
25
- code.push([...getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'augmented', emitLegacyCommonJSImports), `\n`].join(''));
30
+ code.push([...getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'augmented', appendedImportExtension), `\n`].join(''));
26
31
  }
27
32
  code.push([`export function ${gqlTagName}(source: string) {\n`, ` return (documents as any)[source] ?? {};\n`, `}\n`].join(''));
28
33
  return code.join('\n');
29
34
  }
30
35
  if (augmentedModuleName == null) {
31
36
  const code = [
32
- `import * as types from './graphql${emitLegacyCommonJSImports ? '' : '.js'}';\n`,
37
+ `import * as types from './graphql${appendedImportExtension}';\n`,
33
38
  `${useTypeImports ? 'import type' : 'import'} { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';\n`,
34
39
  `\n`,
35
40
  ];
@@ -53,7 +58,7 @@ const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmentedModuleN
53
58
  `\n`,
54
59
  ].join(''));
55
60
  if (sourcesWithOperations.length > 0) {
56
- code.push([...getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'lookup', emitLegacyCommonJSImports), `\n`].join(''));
61
+ code.push([...getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'lookup', appendedImportExtension), `\n`].join(''));
57
62
  }
58
63
  code.push([
59
64
  `export function ${gqlTagName}(source: string) {\n`,
@@ -70,7 +75,7 @@ const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmentedModuleN
70
75
  [
71
76
  `\n`,
72
77
  ...(sourcesWithOperations.length > 0
73
- ? getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'augmented', emitLegacyCommonJSImports)
78
+ ? getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'augmented', appendedImportExtension)
74
79
  : []),
75
80
  `export function ${gqlTagName}(source: string): unknown;\n`,
76
81
  `\n`,
@@ -109,7 +114,7 @@ function getDocumentRegistryChunk(sourcesWithOperations = []) {
109
114
  lines.push(`};\n`);
110
115
  return lines;
111
116
  }
112
- function getGqlOverloadChunk(sourcesWithOperations, gqlTagName, mode, emitLegacyCommonJSImports) {
117
+ function getGqlOverloadChunk(sourcesWithOperations, gqlTagName, mode, importExtension) {
113
118
  const lines = new Set();
114
119
  // We intentionally don't use a <T extends keyof typeof documents> generic, because TS
115
120
  // would print very long `gql` function signatures (duplicating the source).
@@ -117,9 +122,7 @@ function getGqlOverloadChunk(sourcesWithOperations, gqlTagName, mode, emitLegacy
117
122
  const originalString = rest.source.rawSDL;
118
123
  const returnType = mode === 'lookup'
119
124
  ? `(typeof documents)[${JSON.stringify(originalString)}]`
120
- : emitLegacyCommonJSImports
121
- ? `typeof import('./graphql').${operations[0].initialName}`
122
- : `typeof import('./graphql.js').${operations[0].initialName}`;
125
+ : `typeof import('./graphql${importExtension}').${operations[0].initialName}`;
123
126
  lines.add(`/**\n * The ${gqlTagName} function is used to parse GraphQL queries into a document that can be used by GraphQL clients.\n */\n` +
124
127
  `export function ${gqlTagName}(source: ${JSON.stringify(originalString)}): ${returnType};\n`);
125
128
  }
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { normalizeImportExtension } from '@graphql-codegen/plugin-helpers';
1
2
  import { DocumentMode } from '@graphql-codegen/visitor-plugin-common';
2
3
  const documentTypePartial = `
3
4
  export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode<
@@ -7,9 +8,13 @@ export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocume
7
8
  ? TType
8
9
  : never;
9
10
  `.split(`\n`);
10
- export const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmentedModuleName, gqlTagName = 'gql', emitLegacyCommonJSImports, documentMode, }, _info) => {
11
+ export const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmentedModuleName, gqlTagName = 'gql', emitLegacyCommonJSImports, importExtension, documentMode, }, _info) => {
12
+ const appendedImportExtension = normalizeImportExtension({
13
+ emitLegacyCommonJSImports,
14
+ importExtension,
15
+ });
11
16
  if (documentMode === DocumentMode.string) {
12
- const code = [`import * as types from './graphql${emitLegacyCommonJSImports ? '' : '.js'}';\n`, `\n`];
17
+ const code = [`import * as types from './graphql${appendedImportExtension}';\n`, `\n`];
13
18
  // We need the mapping from source as written to full document source to
14
19
  // handle fragments. An identity function would not suffice.
15
20
  if (sourcesWithOperations.length > 0) {
@@ -19,14 +24,14 @@ export const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmented
19
24
  code.push('const documents = {}');
20
25
  }
21
26
  if (sourcesWithOperations.length > 0) {
22
- code.push([...getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'augmented', emitLegacyCommonJSImports), `\n`].join(''));
27
+ code.push([...getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'augmented', appendedImportExtension), `\n`].join(''));
23
28
  }
24
29
  code.push([`export function ${gqlTagName}(source: string) {\n`, ` return (documents as any)[source] ?? {};\n`, `}\n`].join(''));
25
30
  return code.join('\n');
26
31
  }
27
32
  if (augmentedModuleName == null) {
28
33
  const code = [
29
- `import * as types from './graphql${emitLegacyCommonJSImports ? '' : '.js'}';\n`,
34
+ `import * as types from './graphql${appendedImportExtension}';\n`,
30
35
  `${useTypeImports ? 'import type' : 'import'} { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';\n`,
31
36
  `\n`,
32
37
  ];
@@ -50,7 +55,7 @@ export const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmented
50
55
  `\n`,
51
56
  ].join(''));
52
57
  if (sourcesWithOperations.length > 0) {
53
- code.push([...getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'lookup', emitLegacyCommonJSImports), `\n`].join(''));
58
+ code.push([...getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'lookup', appendedImportExtension), `\n`].join(''));
54
59
  }
55
60
  code.push([
56
61
  `export function ${gqlTagName}(source: string) {\n`,
@@ -67,7 +72,7 @@ export const plugin = (_, __, { sourcesWithOperations, useTypeImports, augmented
67
72
  [
68
73
  `\n`,
69
74
  ...(sourcesWithOperations.length > 0
70
- ? getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'augmented', emitLegacyCommonJSImports)
75
+ ? getGqlOverloadChunk(sourcesWithOperations, gqlTagName, 'augmented', appendedImportExtension)
71
76
  : []),
72
77
  `export function ${gqlTagName}(source: string): unknown;\n`,
73
78
  `\n`,
@@ -105,7 +110,7 @@ function getDocumentRegistryChunk(sourcesWithOperations = []) {
105
110
  lines.push(`};\n`);
106
111
  return lines;
107
112
  }
108
- function getGqlOverloadChunk(sourcesWithOperations, gqlTagName, mode, emitLegacyCommonJSImports) {
113
+ function getGqlOverloadChunk(sourcesWithOperations, gqlTagName, mode, importExtension) {
109
114
  const lines = new Set();
110
115
  // We intentionally don't use a <T extends keyof typeof documents> generic, because TS
111
116
  // would print very long `gql` function signatures (duplicating the source).
@@ -113,9 +118,7 @@ function getGqlOverloadChunk(sourcesWithOperations, gqlTagName, mode, emitLegacy
113
118
  const originalString = rest.source.rawSDL;
114
119
  const returnType = mode === 'lookup'
115
120
  ? `(typeof documents)[${JSON.stringify(originalString)}]`
116
- : emitLegacyCommonJSImports
117
- ? `typeof import('./graphql').${operations[0].initialName}`
118
- : `typeof import('./graphql.js').${operations[0].initialName}`;
121
+ : `typeof import('./graphql${importExtension}').${operations[0].initialName}`;
119
122
  lines.add(`/**\n * The ${gqlTagName} function is used to parse GraphQL queries into a document that can be used by GraphQL clients.\n */\n` +
120
123
  `export function ${gqlTagName}(source: ${JSON.stringify(originalString)}): ${returnType};\n`);
121
124
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-codegen/gql-tag-operations",
3
- "version": "5.0.5",
3
+ "version": "5.1.0-alpha-20251119131248-4aa0bce27decc294509fae591f5c2236858abdbb",
4
4
  "description": "GraphQL Code Generator plugin for generating a typed gql tag function",
5
5
  "peerDependencies": {
6
6
  "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"
7
7
  },
8
8
  "dependencies": {
9
9
  "@graphql-tools/utils": "^10.0.0",
10
- "@graphql-codegen/plugin-helpers": "^6.0.0",
11
- "@graphql-codegen/visitor-plugin-common": "6.1.2",
10
+ "@graphql-codegen/plugin-helpers": "6.1.0-alpha-20251119131248-4aa0bce27decc294509fae591f5c2236858abdbb",
11
+ "@graphql-codegen/visitor-plugin-common": "6.2.0-alpha-20251119131248-4aa0bce27decc294509fae591f5c2236858abdbb",
12
12
  "auto-bind": "~4.0.0",
13
13
  "tslib": "~2.6.0"
14
14
  },
@@ -16,5 +16,6 @@ export declare const plugin: PluginFunction<{
16
16
  augmentedModuleName?: string;
17
17
  gqlTagName?: string;
18
18
  emitLegacyCommonJSImports?: boolean;
19
+ importExtension?: '' | `.${string}`;
19
20
  documentMode?: DocumentMode;
20
21
  }>;
@@ -16,5 +16,6 @@ export declare const plugin: PluginFunction<{
16
16
  augmentedModuleName?: string;
17
17
  gqlTagName?: string;
18
18
  emitLegacyCommonJSImports?: boolean;
19
+ importExtension?: '' | `.${string}`;
19
20
  documentMode?: DocumentMode;
20
21
  }>;