@graphitation/graphql-codegen-supermassive-typed-document-node-plugin 0.4.8 → 0.5.0
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/.eslintcache +1 -1
- package/CHANGELOG.md +11 -2
- package/lib/visitor.js +4 -4
- package/lib/visitor.js.map +2 -2
- package/lib/visitor.mjs +1 -1
- package/lib/visitor.mjs.map +1 -1
- package/package.json +3 -3
package/.eslintcache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/index.ts":"1","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/visitor.ts":"2"},{"size":2430,"mtime":
|
|
1
|
+
[{"/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/index.ts":"1","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/visitor.ts":"2"},{"size":2430,"mtime":1687177066340,"results":"3","hashOfConfig":"4"},{"size":5688,"mtime":1687177066340,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","suppressedMessages":"8","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1l9rojw",{"filePath":"9","messages":"10","suppressedMessages":"11","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/index.ts",[],[],"/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/visitor.ts",[],[]]
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# Change Log - @graphitation/graphql-codegen-supermassive-typed-document-node-plugin
|
|
2
2
|
|
|
3
|
-
This log was last generated on Mon,
|
|
3
|
+
This log was last generated on Mon, 19 Jun 2023 12:22:02 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.5.0
|
|
8
|
+
|
|
9
|
+
Mon, 19 Jun 2023 12:22:02 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Move to supermassive-ast package (mnovikov@microsoft.com)
|
|
14
|
+
- Bump @graphitation/supermassive-ast to v2.0.0
|
|
15
|
+
|
|
7
16
|
## 0.4.8
|
|
8
17
|
|
|
9
|
-
Mon, 12 Jun 2023 12:50:
|
|
18
|
+
Mon, 12 Jun 2023 12:50:51 GMT
|
|
10
19
|
|
|
11
20
|
### Patches
|
|
12
21
|
|
package/lib/visitor.js
CHANGED
|
@@ -51,7 +51,7 @@ module.exports = __toCommonJS(visitor_exports);
|
|
|
51
51
|
var import_auto_bind = __toESM(require("auto-bind"));
|
|
52
52
|
var import_visitor_plugin_common = require("@graphql-codegen/visitor-plugin-common");
|
|
53
53
|
var import_graphql = require("graphql");
|
|
54
|
-
var
|
|
54
|
+
var import_supermassive_ast = require("@graphitation/supermassive-ast");
|
|
55
55
|
var import_optimize = require("@graphql-tools/optimize");
|
|
56
56
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
|
57
57
|
class TypeScriptDocumentNodesVisitor extends import_visitor_plugin_common.ClientSideBaseVisitor {
|
|
@@ -92,7 +92,7 @@ class TypeScriptDocumentNodesVisitor extends import_visitor_plugin_common.Client
|
|
|
92
92
|
return this._render(node, true);
|
|
93
93
|
}
|
|
94
94
|
_render(node, annotate = false) {
|
|
95
|
-
const supermassiveNode = (0,
|
|
95
|
+
const supermassiveNode = (0, import_supermassive_ast.addTypesToRequestDocument)(this._schema, {
|
|
96
96
|
kind: import_graphql.Kind.DOCUMENT,
|
|
97
97
|
definitions: [node]
|
|
98
98
|
}).definitions[0];
|
|
@@ -118,7 +118,7 @@ class TypeScriptDocumentNodesVisitor extends import_visitor_plugin_common.Client
|
|
|
118
118
|
const definitions = [
|
|
119
119
|
...gqlObj.definitions.map(
|
|
120
120
|
(t) => JSON.stringify(
|
|
121
|
-
annotate ? (0,
|
|
121
|
+
annotate ? (0, import_supermassive_ast.addTypesToRequestDocument)(this._schema, {
|
|
122
122
|
kind: import_graphql.Kind.DOCUMENT,
|
|
123
123
|
definitions: [t]
|
|
124
124
|
}).definitions[0] : t
|
|
@@ -141,7 +141,7 @@ class TypeScriptDocumentNodesVisitor extends import_visitor_plugin_common.Client
|
|
|
141
141
|
_transformDocumentNodeToSupermassive(document) {
|
|
142
142
|
return __spreadProps(__spreadValues({}, document), {
|
|
143
143
|
definitions: document.definitions.map(
|
|
144
|
-
(t) => (0,
|
|
144
|
+
(t) => (0, import_supermassive_ast.addTypesToRequestDocument)(this._schema, {
|
|
145
145
|
kind: import_graphql.Kind.DOCUMENT,
|
|
146
146
|
definitions: [t]
|
|
147
147
|
}).definitions[0]
|
package/lib/visitor.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/visitor.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n * Taken from https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/packages/plugins/typescript/typed-document-node/src/visitor.ts\n * MIT license https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/LICENSE\n */\n\nimport autoBind from \"auto-bind\";\nimport { Types } from \"@graphql-codegen/plugin-helpers\";\nimport {\n LoadedFragment,\n ClientSideBaseVisitor,\n ClientSideBasePluginConfig,\n DocumentMode,\n RawClientSideBasePluginConfig,\n} from \"@graphql-codegen/visitor-plugin-common\";\nimport {\n GraphQLSchema,\n FragmentDefinitionNode,\n DocumentNode,\n print,\n Kind,\n OperationDefinitionNode,\n} from \"graphql\";\nimport { addTypesToRequestDocument } from \"@graphitation/supermassive\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport gqlTag from \"graphql-tag\";\n\ntype RawClientSidePluginConfig = RawClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n};\ntype ClientSidePluginConfig = ClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n};\n\nexport class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor<\n RawClientSidePluginConfig,\n ClientSidePluginConfig\n> {\n constructor(\n schema: GraphQLSchema,\n fragments: LoadedFragment[],\n rawConfig: RawClientSidePluginConfig,\n documents: Types.DocumentFile[],\n ) {\n super(\n schema,\n fragments,\n {\n documentMode: DocumentMode.documentNodeImportFragments,\n documentNodeImport:\n \"@graphql-typed-document-node/core#TypedDocumentNode\",\n ...rawConfig,\n },\n {\n supermassiveDocumentNodeConditional:\n rawConfig.supermassiveDocumentNodeConditional,\n },\n documents,\n );\n\n autoBind(this);\n\n // We need to make sure it's there because in this mode, the base plugin doesn't add the import\n if (this.config.documentMode === DocumentMode.graphQLTag) {\n const documentNodeImport = this._parseImport(\n this.config.documentNodeImport || \"graphql#DocumentNode\",\n );\n const tagImport = this._generateImport(\n documentNodeImport,\n \"DocumentNode\",\n true,\n ) as string;\n this._imports.add(tagImport);\n }\n }\n\n protected _gql(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ): string {\n if (this.config.supermassiveDocumentNodeConditional) {\n const supermassive = this._render(node, true);\n const standard = this._render(node, false);\n return `(${this.config.supermassiveDocumentNodeConditional}\\n? ${supermassive}\\n: ${standard})`;\n }\n return this._render(node, true);\n }\n\n protected _render(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n annotate = false,\n ): string {\n const supermassiveNode = addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [node],\n }).definitions[0] as FragmentDefinitionNode | OperationDefinitionNode;\n\n const fragments = this._transformFragments(supermassiveNode);\n\n const doc = this._prepareDocument(`\n ${\n print(supermassiveNode)\n .split(\"\\\\\")\n .join(\"\\\\\\\\\") /* Re-escape escaped values in GraphQL syntax */\n }\n ${this._includeFragments(fragments)}`);\n\n if (this.config.documentMode === DocumentMode.documentNode) {\n let gqlObj = gqlTag([doc]);\n\n if (this.config.optimizeDocumentNode) {\n gqlObj = optimizeDocumentNode(gqlObj);\n }\n if (annotate) {\n gqlObj = this._transformDocumentNodeToSupermassive(gqlObj);\n }\n\n return JSON.stringify(gqlObj);\n } else if (\n this.config.documentMode === DocumentMode.documentNodeImportFragments\n ) {\n let gqlObj = gqlTag([doc]);\n\n if (this.config.optimizeDocumentNode) {\n gqlObj = optimizeDocumentNode(gqlObj);\n }\n\n if (fragments.length > 0) {\n const definitions = [\n ...gqlObj.definitions.map((t) =>\n JSON.stringify(\n annotate\n ? addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [t],\n }).definitions[0]\n : t,\n ),\n ),\n ...fragments.map((name) => `...${name}.definitions`),\n ].join();\n\n return `{\"kind\":\"${Kind.DOCUMENT}\",\"definitions\":[${definitions}]}`;\n }\n if (annotate) {\n gqlObj = this._transformDocumentNodeToSupermassive(gqlObj);\n }\n\n return JSON.stringify(gqlObj);\n } else if (this.config.documentMode === DocumentMode.string) {\n return \"`\" + doc + \"`\";\n }\n\n const gqlImport = this._parseImport(this.config.gqlImport || \"graphql-tag\");\n\n return (gqlImport.propName || \"gql\") + \"`\" + doc + \"`\";\n }\n\n private _transformDocumentNodeToSupermassive(document: DocumentNode) {\n return {\n ...document,\n definitions: document.definitions.map(\n (t) =>\n addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [t],\n }).definitions[0],\n ),\n } as DocumentNode;\n }\n protected getDocumentNodeSignature(\n resultType: string,\n variablesTypes: string,\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ) {\n if (\n this.config.documentMode === DocumentMode.documentNode ||\n this.config.documentMode === DocumentMode.documentNodeImportFragments ||\n this.config.documentMode === DocumentMode.graphQLTag\n ) {\n return ` as unknown as DocumentNode<${resultType}, ${variablesTypes}>`;\n }\n\n return super.getDocumentNodeSignature(resultType, variablesTypes, node);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,uBAAqB;AAErB,mCAMO;AACP,qBAOO;AACP,
|
|
4
|
+
"sourcesContent": ["/*\n * Taken from https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/packages/plugins/typescript/typed-document-node/src/visitor.ts\n * MIT license https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/LICENSE\n */\n\nimport autoBind from \"auto-bind\";\nimport { Types } from \"@graphql-codegen/plugin-helpers\";\nimport {\n LoadedFragment,\n ClientSideBaseVisitor,\n ClientSideBasePluginConfig,\n DocumentMode,\n RawClientSideBasePluginConfig,\n} from \"@graphql-codegen/visitor-plugin-common\";\nimport {\n GraphQLSchema,\n FragmentDefinitionNode,\n DocumentNode,\n print,\n Kind,\n OperationDefinitionNode,\n} from \"graphql\";\nimport { addTypesToRequestDocument } from \"@graphitation/supermassive-ast\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport gqlTag from \"graphql-tag\";\n\ntype RawClientSidePluginConfig = RawClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n};\ntype ClientSidePluginConfig = ClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n};\n\nexport class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor<\n RawClientSidePluginConfig,\n ClientSidePluginConfig\n> {\n constructor(\n schema: GraphQLSchema,\n fragments: LoadedFragment[],\n rawConfig: RawClientSidePluginConfig,\n documents: Types.DocumentFile[],\n ) {\n super(\n schema,\n fragments,\n {\n documentMode: DocumentMode.documentNodeImportFragments,\n documentNodeImport:\n \"@graphql-typed-document-node/core#TypedDocumentNode\",\n ...rawConfig,\n },\n {\n supermassiveDocumentNodeConditional:\n rawConfig.supermassiveDocumentNodeConditional,\n },\n documents,\n );\n\n autoBind(this);\n\n // We need to make sure it's there because in this mode, the base plugin doesn't add the import\n if (this.config.documentMode === DocumentMode.graphQLTag) {\n const documentNodeImport = this._parseImport(\n this.config.documentNodeImport || \"graphql#DocumentNode\",\n );\n const tagImport = this._generateImport(\n documentNodeImport,\n \"DocumentNode\",\n true,\n ) as string;\n this._imports.add(tagImport);\n }\n }\n\n protected _gql(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ): string {\n if (this.config.supermassiveDocumentNodeConditional) {\n const supermassive = this._render(node, true);\n const standard = this._render(node, false);\n return `(${this.config.supermassiveDocumentNodeConditional}\\n? ${supermassive}\\n: ${standard})`;\n }\n return this._render(node, true);\n }\n\n protected _render(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n annotate = false,\n ): string {\n const supermassiveNode = addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [node],\n }).definitions[0] as FragmentDefinitionNode | OperationDefinitionNode;\n\n const fragments = this._transformFragments(supermassiveNode);\n\n const doc = this._prepareDocument(`\n ${\n print(supermassiveNode)\n .split(\"\\\\\")\n .join(\"\\\\\\\\\") /* Re-escape escaped values in GraphQL syntax */\n }\n ${this._includeFragments(fragments)}`);\n\n if (this.config.documentMode === DocumentMode.documentNode) {\n let gqlObj = gqlTag([doc]);\n\n if (this.config.optimizeDocumentNode) {\n gqlObj = optimizeDocumentNode(gqlObj);\n }\n if (annotate) {\n gqlObj = this._transformDocumentNodeToSupermassive(gqlObj);\n }\n\n return JSON.stringify(gqlObj);\n } else if (\n this.config.documentMode === DocumentMode.documentNodeImportFragments\n ) {\n let gqlObj = gqlTag([doc]);\n\n if (this.config.optimizeDocumentNode) {\n gqlObj = optimizeDocumentNode(gqlObj);\n }\n\n if (fragments.length > 0) {\n const definitions = [\n ...gqlObj.definitions.map((t) =>\n JSON.stringify(\n annotate\n ? addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [t],\n }).definitions[0]\n : t,\n ),\n ),\n ...fragments.map((name) => `...${name}.definitions`),\n ].join();\n\n return `{\"kind\":\"${Kind.DOCUMENT}\",\"definitions\":[${definitions}]}`;\n }\n if (annotate) {\n gqlObj = this._transformDocumentNodeToSupermassive(gqlObj);\n }\n\n return JSON.stringify(gqlObj);\n } else if (this.config.documentMode === DocumentMode.string) {\n return \"`\" + doc + \"`\";\n }\n\n const gqlImport = this._parseImport(this.config.gqlImport || \"graphql-tag\");\n\n return (gqlImport.propName || \"gql\") + \"`\" + doc + \"`\";\n }\n\n private _transformDocumentNodeToSupermassive(document: DocumentNode) {\n return {\n ...document,\n definitions: document.definitions.map(\n (t) =>\n addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [t],\n }).definitions[0],\n ),\n } as DocumentNode;\n }\n protected getDocumentNodeSignature(\n resultType: string,\n variablesTypes: string,\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ) {\n if (\n this.config.documentMode === DocumentMode.documentNode ||\n this.config.documentMode === DocumentMode.documentNodeImportFragments ||\n this.config.documentMode === DocumentMode.graphQLTag\n ) {\n return ` as unknown as DocumentNode<${resultType}, ${variablesTypes}>`;\n }\n\n return super.getDocumentNodeSignature(resultType, variablesTypes, node);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,uBAAqB;AAErB,mCAMO;AACP,qBAOO;AACP,8BAA0C;AAC1C,sBAAqC;AACrC,yBAAmB;AASZ,MAAM,uCAAuC,mDAGlD;AAAA,EACA,YACE,QACA,WACA,WACA,WACA;AACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,QACE,cAAc,0CAAa;AAAA,QAC3B,oBACE;AAAA,SACC;AAAA,MAEL;AAAA,QACE,qCACE,UAAU;AAAA,MACd;AAAA,MACA;AAAA,IACF;AAEA,yBAAAA,SAAS,IAAI;AAGb,QAAI,KAAK,OAA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autoBind", "gqlTag"]
|
|
7
7
|
}
|
package/lib/visitor.mjs
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
print,
|
|
29
29
|
Kind
|
|
30
30
|
} from "graphql";
|
|
31
|
-
import { addTypesToRequestDocument } from "@graphitation/supermassive";
|
|
31
|
+
import { addTypesToRequestDocument } from "@graphitation/supermassive-ast";
|
|
32
32
|
import { optimizeDocumentNode } from "@graphql-tools/optimize";
|
|
33
33
|
import gqlTag from "graphql-tag";
|
|
34
34
|
var TypeScriptDocumentNodesVisitor = class extends ClientSideBaseVisitor {
|
package/lib/visitor.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/visitor.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n * Taken from https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/packages/plugins/typescript/typed-document-node/src/visitor.ts\n * MIT license https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/LICENSE\n */\n\nimport autoBind from \"auto-bind\";\nimport { Types } from \"@graphql-codegen/plugin-helpers\";\nimport {\n LoadedFragment,\n ClientSideBaseVisitor,\n ClientSideBasePluginConfig,\n DocumentMode,\n RawClientSideBasePluginConfig,\n} from \"@graphql-codegen/visitor-plugin-common\";\nimport {\n GraphQLSchema,\n FragmentDefinitionNode,\n DocumentNode,\n print,\n Kind,\n OperationDefinitionNode,\n} from \"graphql\";\nimport { addTypesToRequestDocument } from \"@graphitation/supermassive\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport gqlTag from \"graphql-tag\";\n\ntype RawClientSidePluginConfig = RawClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n};\ntype ClientSidePluginConfig = ClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n};\n\nexport class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor<\n RawClientSidePluginConfig,\n ClientSidePluginConfig\n> {\n constructor(\n schema: GraphQLSchema,\n fragments: LoadedFragment[],\n rawConfig: RawClientSidePluginConfig,\n documents: Types.DocumentFile[],\n ) {\n super(\n schema,\n fragments,\n {\n documentMode: DocumentMode.documentNodeImportFragments,\n documentNodeImport:\n \"@graphql-typed-document-node/core#TypedDocumentNode\",\n ...rawConfig,\n },\n {\n supermassiveDocumentNodeConditional:\n rawConfig.supermassiveDocumentNodeConditional,\n },\n documents,\n );\n\n autoBind(this);\n\n // We need to make sure it's there because in this mode, the base plugin doesn't add the import\n if (this.config.documentMode === DocumentMode.graphQLTag) {\n const documentNodeImport = this._parseImport(\n this.config.documentNodeImport || \"graphql#DocumentNode\",\n );\n const tagImport = this._generateImport(\n documentNodeImport,\n \"DocumentNode\",\n true,\n ) as string;\n this._imports.add(tagImport);\n }\n }\n\n protected _gql(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ): string {\n if (this.config.supermassiveDocumentNodeConditional) {\n const supermassive = this._render(node, true);\n const standard = this._render(node, false);\n return `(${this.config.supermassiveDocumentNodeConditional}\\n? ${supermassive}\\n: ${standard})`;\n }\n return this._render(node, true);\n }\n\n protected _render(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n annotate = false,\n ): string {\n const supermassiveNode = addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [node],\n }).definitions[0] as FragmentDefinitionNode | OperationDefinitionNode;\n\n const fragments = this._transformFragments(supermassiveNode);\n\n const doc = this._prepareDocument(`\n ${\n print(supermassiveNode)\n .split(\"\\\\\")\n .join(\"\\\\\\\\\") /* Re-escape escaped values in GraphQL syntax */\n }\n ${this._includeFragments(fragments)}`);\n\n if (this.config.documentMode === DocumentMode.documentNode) {\n let gqlObj = gqlTag([doc]);\n\n if (this.config.optimizeDocumentNode) {\n gqlObj = optimizeDocumentNode(gqlObj);\n }\n if (annotate) {\n gqlObj = this._transformDocumentNodeToSupermassive(gqlObj);\n }\n\n return JSON.stringify(gqlObj);\n } else if (\n this.config.documentMode === DocumentMode.documentNodeImportFragments\n ) {\n let gqlObj = gqlTag([doc]);\n\n if (this.config.optimizeDocumentNode) {\n gqlObj = optimizeDocumentNode(gqlObj);\n }\n\n if (fragments.length > 0) {\n const definitions = [\n ...gqlObj.definitions.map((t) =>\n JSON.stringify(\n annotate\n ? addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [t],\n }).definitions[0]\n : t,\n ),\n ),\n ...fragments.map((name) => `...${name}.definitions`),\n ].join();\n\n return `{\"kind\":\"${Kind.DOCUMENT}\",\"definitions\":[${definitions}]}`;\n }\n if (annotate) {\n gqlObj = this._transformDocumentNodeToSupermassive(gqlObj);\n }\n\n return JSON.stringify(gqlObj);\n } else if (this.config.documentMode === DocumentMode.string) {\n return \"`\" + doc + \"`\";\n }\n\n const gqlImport = this._parseImport(this.config.gqlImport || \"graphql-tag\");\n\n return (gqlImport.propName || \"gql\") + \"`\" + doc + \"`\";\n }\n\n private _transformDocumentNodeToSupermassive(document: DocumentNode) {\n return {\n ...document,\n definitions: document.definitions.map(\n (t) =>\n addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [t],\n }).definitions[0],\n ),\n } as DocumentNode;\n }\n protected getDocumentNodeSignature(\n resultType: string,\n variablesTypes: string,\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ) {\n if (\n this.config.documentMode === DocumentMode.documentNode ||\n this.config.documentMode === DocumentMode.documentNodeImportFragments ||\n this.config.documentMode === DocumentMode.graphQLTag\n ) {\n return ` as unknown as DocumentNode<${resultType}, ${variablesTypes}>`;\n }\n\n return super.getDocumentNodeSignature(resultType, variablesTypes, node);\n }\n}\n"],
|
|
4
|
+
"sourcesContent": ["/*\n * Taken from https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/packages/plugins/typescript/typed-document-node/src/visitor.ts\n * MIT license https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/LICENSE\n */\n\nimport autoBind from \"auto-bind\";\nimport { Types } from \"@graphql-codegen/plugin-helpers\";\nimport {\n LoadedFragment,\n ClientSideBaseVisitor,\n ClientSideBasePluginConfig,\n DocumentMode,\n RawClientSideBasePluginConfig,\n} from \"@graphql-codegen/visitor-plugin-common\";\nimport {\n GraphQLSchema,\n FragmentDefinitionNode,\n DocumentNode,\n print,\n Kind,\n OperationDefinitionNode,\n} from \"graphql\";\nimport { addTypesToRequestDocument } from \"@graphitation/supermassive-ast\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport gqlTag from \"graphql-tag\";\n\ntype RawClientSidePluginConfig = RawClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n};\ntype ClientSidePluginConfig = ClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n};\n\nexport class TypeScriptDocumentNodesVisitor extends ClientSideBaseVisitor<\n RawClientSidePluginConfig,\n ClientSidePluginConfig\n> {\n constructor(\n schema: GraphQLSchema,\n fragments: LoadedFragment[],\n rawConfig: RawClientSidePluginConfig,\n documents: Types.DocumentFile[],\n ) {\n super(\n schema,\n fragments,\n {\n documentMode: DocumentMode.documentNodeImportFragments,\n documentNodeImport:\n \"@graphql-typed-document-node/core#TypedDocumentNode\",\n ...rawConfig,\n },\n {\n supermassiveDocumentNodeConditional:\n rawConfig.supermassiveDocumentNodeConditional,\n },\n documents,\n );\n\n autoBind(this);\n\n // We need to make sure it's there because in this mode, the base plugin doesn't add the import\n if (this.config.documentMode === DocumentMode.graphQLTag) {\n const documentNodeImport = this._parseImport(\n this.config.documentNodeImport || \"graphql#DocumentNode\",\n );\n const tagImport = this._generateImport(\n documentNodeImport,\n \"DocumentNode\",\n true,\n ) as string;\n this._imports.add(tagImport);\n }\n }\n\n protected _gql(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ): string {\n if (this.config.supermassiveDocumentNodeConditional) {\n const supermassive = this._render(node, true);\n const standard = this._render(node, false);\n return `(${this.config.supermassiveDocumentNodeConditional}\\n? ${supermassive}\\n: ${standard})`;\n }\n return this._render(node, true);\n }\n\n protected _render(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n annotate = false,\n ): string {\n const supermassiveNode = addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [node],\n }).definitions[0] as FragmentDefinitionNode | OperationDefinitionNode;\n\n const fragments = this._transformFragments(supermassiveNode);\n\n const doc = this._prepareDocument(`\n ${\n print(supermassiveNode)\n .split(\"\\\\\")\n .join(\"\\\\\\\\\") /* Re-escape escaped values in GraphQL syntax */\n }\n ${this._includeFragments(fragments)}`);\n\n if (this.config.documentMode === DocumentMode.documentNode) {\n let gqlObj = gqlTag([doc]);\n\n if (this.config.optimizeDocumentNode) {\n gqlObj = optimizeDocumentNode(gqlObj);\n }\n if (annotate) {\n gqlObj = this._transformDocumentNodeToSupermassive(gqlObj);\n }\n\n return JSON.stringify(gqlObj);\n } else if (\n this.config.documentMode === DocumentMode.documentNodeImportFragments\n ) {\n let gqlObj = gqlTag([doc]);\n\n if (this.config.optimizeDocumentNode) {\n gqlObj = optimizeDocumentNode(gqlObj);\n }\n\n if (fragments.length > 0) {\n const definitions = [\n ...gqlObj.definitions.map((t) =>\n JSON.stringify(\n annotate\n ? addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [t],\n }).definitions[0]\n : t,\n ),\n ),\n ...fragments.map((name) => `...${name}.definitions`),\n ].join();\n\n return `{\"kind\":\"${Kind.DOCUMENT}\",\"definitions\":[${definitions}]}`;\n }\n if (annotate) {\n gqlObj = this._transformDocumentNodeToSupermassive(gqlObj);\n }\n\n return JSON.stringify(gqlObj);\n } else if (this.config.documentMode === DocumentMode.string) {\n return \"`\" + doc + \"`\";\n }\n\n const gqlImport = this._parseImport(this.config.gqlImport || \"graphql-tag\");\n\n return (gqlImport.propName || \"gql\") + \"`\" + doc + \"`\";\n }\n\n private _transformDocumentNodeToSupermassive(document: DocumentNode) {\n return {\n ...document,\n definitions: document.definitions.map(\n (t) =>\n addTypesToRequestDocument(this._schema, {\n kind: Kind.DOCUMENT,\n definitions: [t],\n }).definitions[0],\n ),\n } as DocumentNode;\n }\n protected getDocumentNodeSignature(\n resultType: string,\n variablesTypes: string,\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ) {\n if (\n this.config.documentMode === DocumentMode.documentNode ||\n this.config.documentMode === DocumentMode.documentNodeImportFragments ||\n this.config.documentMode === DocumentMode.graphQLTag\n ) {\n return ` as unknown as DocumentNode<${resultType}, ${variablesTypes}>`;\n }\n\n return super.getDocumentNodeSignature(resultType, variablesTypes, node);\n }\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAKA,OAAO,cAAc;AAErB;AAAA,EAEE;AAAA,EAEA;AAAA,OAEK;AACP;AAAA,EAIE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,4BAA4B;AACrC,OAAO,YAAY;AASZ,IAAM,iCAAN,cAA6C,sBAGlD;AAAA,EACA,YACE,QACA,WACA,WACA,WACA;AACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,QACE,cAAc,aAAa;AAAA,QAC3B,oBACE;AAAA,SACC;AAAA,MAEL;AAAA,QACE,qCACE,UAAU;AAAA,MACd;AAAA,MACA;AAAA,IACF;AAEA,aAAS,IAAI;AAGb,QAAI,KAAK,OAAO,iBAAiB,aAAa,YAAY;AACxD,YAAM,qBAAqB,KAAK;AAAA,QAC9B,KAAK,OAAO,sBAAsB;AAAA,MACpC;AACA,YAAM,YAAY,KAAK;AAAA,QACrB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,WAAK,SAAS,IAAI,SAAS;AAAA,IAC7B;AAAA,EACF;AAAA,EAEU,KACR,MACQ;AACR,QAAI,KAAK,OAAO,qCAAqC;AACnD,YAAM,eAAe,KAAK,QAAQ,MAAM,IAAI;AAC5C,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B;AAAA,QACrD,EAAE,KAAK;AAEP,eAAO,YAAY,KAAK,4BAA4B;AAAA,MACtD;AACA,UAAI,UAAU;AACZ,iBAAS,KAAK,qCAAqC,MAAM;AAAA,MAC3D;AAEA,aAAO,KAAK,UAAU,MAAM;AAAA,IAC9B,WAAW,KAAK,OAAO,iBAAiB,aAAa,QAAQ;AAC3D,aAAO,MAAM,MAAM;AAAA,IACrB;AAEA,UAAM,YAAY,KAAK,aAAa,KAAK,OAAO,aAAa,aAAa;AAE1E,YAAQ,UAAU,YAAY,SAAS,MAAM,MAAM;AAAA,EACrD;AAAA,EAEQ,qCAAqC,UAAwB;AACnE,WAAO,iCACF,WADE;AAAA,MAEL,aAAa,SAAS,YAAY;AAAA,QAChC,CAAC,MACC,0BAA0B,KAAK,SAAS;AAAA,UACtC,MAAM,KAAK;AAAA,UACX,aAAa,CAAC,CAAC;AAAA,QACjB,CAAC,EAAE,YAAY,CAAC;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AAAA,EACU,yBACR,YACA,gBACA,MACA;AACA,QACE,KAAK,OAAO,iBAAiB,aAAa,gBAC1C,KAAK,OAAO,iBAAiB,aAAa,+BAC1C,KAAK,OAAO,iBAAiB,aAAa,YAC1C;AACA,aAAO,+BAA+B,eAAe;AAAA,IACvD;AAEA,WAAO,MAAM,yBAAyB,YAAY,gBAAgB,IAAI;AAAA,EACxE;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphitation/graphql-codegen-supermassive-typed-document-node-plugin",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"main": "./lib/index",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"just": "monorepo-scripts"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@graphitation/supermassive": "*",
|
|
18
|
+
"@graphitation/supermassive-ast": "*",
|
|
19
19
|
"@graphql-codegen/plugin-helpers": "^1.18.2",
|
|
20
20
|
"@graphql-codegen/visitor-plugin-common": "^1.17.20",
|
|
21
21
|
"@types/jest": "^26.0.22",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@graphql-codegen/visitor-plugin-common": ">= ^1.17.0 < 2",
|
|
29
29
|
"graphql-tag": ">= 2.11.0 < 3",
|
|
30
30
|
"@graphql-tools/optimize": "^1.0.1",
|
|
31
|
-
"@graphitation/supermassive": "^2.
|
|
31
|
+
"@graphitation/supermassive-ast": "^2.0.0"
|
|
32
32
|
},
|
|
33
33
|
"sideEffects": false,
|
|
34
34
|
"access": "public",
|