@graphql-codegen/typed-document-node 7.1.0 → 7.1.1-alpha-20260927031954-000584fcd017ac5ee28b5fa0291f26a21da4bdce
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 +2 -2
- package/cjs/visitor.js +10 -6
- package/esm/index.js +2 -2
- package/esm/visitor.js +10 -6
- package/package.json +4 -4
- package/typings/visitor.d.cts +13 -3
- package/typings/visitor.d.ts +13 -3
package/cjs/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const plugin = (schema, rawDocuments, config) => {
|
|
|
10
10
|
const documents = config.flattenGeneratedTypes
|
|
11
11
|
? (0, visitor_plugin_common_1.optimizeOperations)(schema, rawDocuments)
|
|
12
12
|
: rawDocuments;
|
|
13
|
-
const allAst = (0, graphql_1.concatAST)(documents.
|
|
13
|
+
const allAst = (0, graphql_1.concatAST)(documents.flatMap(v => (v.document ? [v.document] : [])));
|
|
14
14
|
const allFragments = [
|
|
15
15
|
...allAst.definitions.filter(d => d.kind === graphql_1.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
|
|
16
16
|
node: fragmentDef,
|
|
@@ -31,7 +31,7 @@ const plugin = (schema, rawDocuments, config) => {
|
|
|
31
31
|
content: [
|
|
32
32
|
...content,
|
|
33
33
|
visitor.fragments,
|
|
34
|
-
...visitorResult.definitions.filter(t => typeof t === 'string'),
|
|
34
|
+
...visitorResult.definitions.filter((t) => typeof t === 'string'),
|
|
35
35
|
].join('\n'),
|
|
36
36
|
};
|
|
37
37
|
};
|
package/cjs/visitor.js
CHANGED
|
@@ -18,31 +18,35 @@ class TypeScriptDocumentNodesVisitor extends visitor_plugin_common_1.ClientSideB
|
|
|
18
18
|
if (this.config.documentMode === visitor_plugin_common_1.DocumentMode.graphQLTag) {
|
|
19
19
|
const documentNodeImport = this._parseImport(this.config.documentNodeImport || 'graphql#DocumentNode');
|
|
20
20
|
const tagImport = this._generateImport(documentNodeImport, 'DocumentNode', true);
|
|
21
|
-
|
|
21
|
+
if (tagImport) {
|
|
22
|
+
this._imports.add(tagImport);
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
else if (this.config.documentMode === visitor_plugin_common_1.DocumentMode.string) {
|
|
24
26
|
const tagImport = this._generateImport(visitor_plugin_common_1.typedDocumentString.import, visitor_plugin_common_1.typedDocumentString.import.propName, true);
|
|
25
|
-
|
|
27
|
+
if (tagImport) {
|
|
28
|
+
this._imports.add(tagImport);
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
SelectionSet(node, _, parent) {
|
|
29
33
|
if (!this.pluginConfig.addTypenameToSelectionSets) {
|
|
30
|
-
return;
|
|
34
|
+
return undefined;
|
|
31
35
|
}
|
|
32
36
|
// Don't add __typename to OperationDefinitions.
|
|
33
37
|
if (parent && parent.kind === 'OperationDefinition') {
|
|
34
|
-
return;
|
|
38
|
+
return undefined;
|
|
35
39
|
}
|
|
36
40
|
// No changes if no selections.
|
|
37
41
|
const { selections } = node;
|
|
38
42
|
if (!selections) {
|
|
39
|
-
return;
|
|
43
|
+
return undefined;
|
|
40
44
|
}
|
|
41
45
|
// If selections already have a __typename or is introspection do nothing.
|
|
42
46
|
const hasTypename = selections.some(selection => selection.kind === 'Field' &&
|
|
43
47
|
(selection.name.value === '__typename' || selection.name.value.lastIndexOf('__', 0) === 0));
|
|
44
48
|
if (hasTypename) {
|
|
45
|
-
return;
|
|
49
|
+
return undefined;
|
|
46
50
|
}
|
|
47
51
|
return {
|
|
48
52
|
...node,
|
package/esm/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export const plugin = (schema, rawDocuments, config) => {
|
|
|
7
7
|
const documents = config.flattenGeneratedTypes
|
|
8
8
|
? optimizeOperations(schema, rawDocuments)
|
|
9
9
|
: rawDocuments;
|
|
10
|
-
const allAst = concatAST(documents.
|
|
10
|
+
const allAst = concatAST(documents.flatMap(v => (v.document ? [v.document] : [])));
|
|
11
11
|
const allFragments = [
|
|
12
12
|
...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
|
|
13
13
|
node: fragmentDef,
|
|
@@ -28,7 +28,7 @@ export const plugin = (schema, rawDocuments, config) => {
|
|
|
28
28
|
content: [
|
|
29
29
|
...content,
|
|
30
30
|
visitor.fragments,
|
|
31
|
-
...visitorResult.definitions.filter(t => typeof t === 'string'),
|
|
31
|
+
...visitorResult.definitions.filter((t) => typeof t === 'string'),
|
|
32
32
|
].join('\n'),
|
|
33
33
|
};
|
|
34
34
|
};
|
package/esm/visitor.js
CHANGED
|
@@ -14,31 +14,35 @@ export class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor {
|
|
|
14
14
|
if (this.config.documentMode === DocumentMode.graphQLTag) {
|
|
15
15
|
const documentNodeImport = this._parseImport(this.config.documentNodeImport || 'graphql#DocumentNode');
|
|
16
16
|
const tagImport = this._generateImport(documentNodeImport, 'DocumentNode', true);
|
|
17
|
-
|
|
17
|
+
if (tagImport) {
|
|
18
|
+
this._imports.add(tagImport);
|
|
19
|
+
}
|
|
18
20
|
}
|
|
19
21
|
else if (this.config.documentMode === DocumentMode.string) {
|
|
20
22
|
const tagImport = this._generateImport(typedDocumentString.import, typedDocumentString.import.propName, true);
|
|
21
|
-
|
|
23
|
+
if (tagImport) {
|
|
24
|
+
this._imports.add(tagImport);
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
SelectionSet(node, _, parent) {
|
|
25
29
|
if (!this.pluginConfig.addTypenameToSelectionSets) {
|
|
26
|
-
return;
|
|
30
|
+
return undefined;
|
|
27
31
|
}
|
|
28
32
|
// Don't add __typename to OperationDefinitions.
|
|
29
33
|
if (parent && parent.kind === 'OperationDefinition') {
|
|
30
|
-
return;
|
|
34
|
+
return undefined;
|
|
31
35
|
}
|
|
32
36
|
// No changes if no selections.
|
|
33
37
|
const { selections } = node;
|
|
34
38
|
if (!selections) {
|
|
35
|
-
return;
|
|
39
|
+
return undefined;
|
|
36
40
|
}
|
|
37
41
|
// If selections already have a __typename or is introspection do nothing.
|
|
38
42
|
const hasTypename = selections.some(selection => selection.kind === 'Field' &&
|
|
39
43
|
(selection.name.value === '__typename' || selection.name.value.lastIndexOf('__', 0) === 0));
|
|
40
44
|
if (hasTypename) {
|
|
41
|
-
return;
|
|
45
|
+
return undefined;
|
|
42
46
|
}
|
|
43
47
|
return {
|
|
44
48
|
...node,
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typed-document-node",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.1-alpha-20260927031954-000584fcd017ac5ee28b5fa0291f26a21da4bdce",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating ready-to-use TypedDocumentNode based on GraphQL operations",
|
|
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 || ^17.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^7.4.0-alpha-20260927031954-000584fcd017ac5ee28b5fa0291f26a21da4bdce",
|
|
10
|
+
"@graphql-codegen/visitor-plugin-common": "^7.2.6-alpha-20260927031954-000584fcd017ac5ee28b5fa0291f26a21da4bdce",
|
|
9
11
|
"auto-bind": "^5.0.0",
|
|
10
12
|
"change-case-all": "^2.1.0",
|
|
11
|
-
"tslib": "^2.8.0"
|
|
12
|
-
"@graphql-codegen/plugin-helpers": "^7.1.0",
|
|
13
|
-
"@graphql-codegen/visitor-plugin-common": "^7.2.0"
|
|
13
|
+
"tslib": "^2.8.0"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
package/typings/visitor.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphQLSchema } from 'graphql';
|
|
1
|
+
import { ASTNode, FragmentDefinitionNode, GraphQLSchema, OperationDefinitionNode, SelectionSetNode } from 'graphql';
|
|
2
2
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
3
3
|
import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment, RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
4
4
|
interface TypeScriptDocumentNodesVisitorPluginConfig extends RawClientSideBasePluginConfig {
|
|
@@ -7,7 +7,17 @@ interface TypeScriptDocumentNodesVisitorPluginConfig extends RawClientSideBasePl
|
|
|
7
7
|
export declare class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor<TypeScriptDocumentNodesVisitorPluginConfig, ClientSideBasePluginConfig> {
|
|
8
8
|
private pluginConfig;
|
|
9
9
|
constructor(schema: GraphQLSchema, fragments: LoadedFragment[], config: TypeScriptDocumentNodesVisitorPluginConfig, documents: Types.DocumentFile[]);
|
|
10
|
-
SelectionSet(node:
|
|
11
|
-
|
|
10
|
+
SelectionSet(node: SelectionSetNode, _: unknown, parent?: ASTNode): {
|
|
11
|
+
selections: (import("graphql").FieldNode | import("graphql").FragmentSpreadNode | import("graphql").InlineFragmentNode | {
|
|
12
|
+
kind: string;
|
|
13
|
+
name: {
|
|
14
|
+
kind: string;
|
|
15
|
+
value: string;
|
|
16
|
+
};
|
|
17
|
+
})[];
|
|
18
|
+
kind: import("graphql/language/KindTypeMap").KindTypeMap["SELECTION_SET"];
|
|
19
|
+
loc?: import("graphql").Location | undefined;
|
|
20
|
+
};
|
|
21
|
+
protected getDocumentNodeSignature(resultType: string, variablesTypes: string, node: FragmentDefinitionNode | OperationDefinitionNode): string;
|
|
12
22
|
}
|
|
13
23
|
export {};
|
package/typings/visitor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphQLSchema } from 'graphql';
|
|
1
|
+
import { ASTNode, FragmentDefinitionNode, GraphQLSchema, OperationDefinitionNode, SelectionSetNode } from 'graphql';
|
|
2
2
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
3
3
|
import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment, RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
4
4
|
interface TypeScriptDocumentNodesVisitorPluginConfig extends RawClientSideBasePluginConfig {
|
|
@@ -7,7 +7,17 @@ interface TypeScriptDocumentNodesVisitorPluginConfig extends RawClientSideBasePl
|
|
|
7
7
|
export declare class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor<TypeScriptDocumentNodesVisitorPluginConfig, ClientSideBasePluginConfig> {
|
|
8
8
|
private pluginConfig;
|
|
9
9
|
constructor(schema: GraphQLSchema, fragments: LoadedFragment[], config: TypeScriptDocumentNodesVisitorPluginConfig, documents: Types.DocumentFile[]);
|
|
10
|
-
SelectionSet(node:
|
|
11
|
-
|
|
10
|
+
SelectionSet(node: SelectionSetNode, _: unknown, parent?: ASTNode): {
|
|
11
|
+
selections: (import("graphql").FieldNode | import("graphql").FragmentSpreadNode | import("graphql").InlineFragmentNode | {
|
|
12
|
+
kind: string;
|
|
13
|
+
name: {
|
|
14
|
+
kind: string;
|
|
15
|
+
value: string;
|
|
16
|
+
};
|
|
17
|
+
})[];
|
|
18
|
+
kind: import("graphql/language/KindTypeMap").KindTypeMap["SELECTION_SET"];
|
|
19
|
+
loc?: import("graphql").Location | undefined;
|
|
20
|
+
};
|
|
21
|
+
protected getDocumentNodeSignature(resultType: string, variablesTypes: string, node: FragmentDefinitionNode | OperationDefinitionNode): string;
|
|
12
22
|
}
|
|
13
23
|
export {};
|