@graphitation/graphql-codegen-supermassive-typed-document-node-plugin 0.6.0 → 0.6.1

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 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":1695804358407,"results":"3","hashOfConfig":"4"},{"size":6818,"mtime":1695804358411,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","suppressedMessages":"8","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"9ay76n",{"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",[],[]]
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":1695824968954,"results":"3","hashOfConfig":"4"},{"size":6828,"mtime":1695824968954,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","suppressedMessages":"8","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"9ay76n",{"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,20 @@
1
1
  # Change Log - @graphitation/graphql-codegen-supermassive-typed-document-node-plugin
2
2
 
3
- This log was last generated on Wed, 27 Sep 2023 08:50:15 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 27 Sep 2023 14:33:43 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.6.1
8
+
9
+ Wed, 27 Sep 2023 14:33:43 GMT
10
+
11
+ ### Patches
12
+
13
+ - Fix transforms to actually do both v3 and v2 (mnovikov@microsoft.com)
14
+
7
15
  ## 0.6.0
8
16
 
9
- Wed, 27 Sep 2023 08:50:15 GMT
17
+ Wed, 27 Sep 2023 08:50:33 GMT
10
18
 
11
19
  ### Minor changes
12
20
 
package/lib/visitor.js CHANGED
@@ -160,7 +160,7 @@ class TypeScriptDocumentNodesVisitor extends import_visitor_plugin_common.Client
160
160
  if (this.config.supermassiveDocumentNodeOutputType === "V3" || this.config.supermassiveDocumentNodeOutputType === "BOTH") {
161
161
  finalDocument = (0, import_supermassive.addMinimalViableSchemaToRequestDocument)(
162
162
  schema,
163
- document,
163
+ finalDocument,
164
164
  {
165
165
  addTo: "PROPERTY"
166
166
  }
@@ -169,7 +169,7 @@ class TypeScriptDocumentNodesVisitor extends import_visitor_plugin_common.Client
169
169
  if (this.config.supermassiveDocumentNodeOutputType === "V2" || this.config.supermassiveDocumentNodeOutputType === "BOTH") {
170
170
  finalDocument = (0, import_supermassive.addSupermassiveLegacyTypesToRequestDocument)(
171
171
  schema,
172
- document
172
+ finalDocument
173
173
  );
174
174
  }
175
175
  return finalDocument;
@@ -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 {\n addSupermassiveLegacyTypesToRequestDocument,\n addMinimalViableSchemaToRequestDocument,\n} from \"@graphitation/supermassive\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport gqlTag from \"graphql-tag\";\n\nexport type SupermassiveOutputType = \"V3\" | \"V2\" | \"BOTH\";\n\ntype RawClientSidePluginConfig = RawClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n supermassiveDocumentNodeOutputType?: SupermassiveOutputType;\n};\ntype ClientSidePluginConfig = ClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n supermassiveDocumentNodeOutputType?: SupermassiveOutputType;\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 supermassiveDocumentNodeOutputType:\n rawConfig.supermassiveDocumentNodeOutputType || \"V3\",\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 = this.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 ? this.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 this.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 private addTypesToRequestDocument(\n schema: GraphQLSchema,\n document: DocumentNode,\n ) {\n let finalDocument = document;\n if (\n this.config.supermassiveDocumentNodeOutputType === \"V3\" ||\n this.config.supermassiveDocumentNodeOutputType === \"BOTH\"\n ) {\n finalDocument = addMinimalViableSchemaToRequestDocument(\n schema,\n document,\n {\n addTo: \"PROPERTY\",\n },\n );\n }\n\n if (\n this.config.supermassiveDocumentNodeOutputType === \"V2\" ||\n this.config.supermassiveDocumentNodeOutputType === \"BOTH\"\n ) {\n finalDocument = addSupermassiveLegacyTypesToRequestDocument(\n schema,\n document,\n ) as unknown as DocumentNode;\n }\n return finalDocument;\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 {\n addSupermassiveLegacyTypesToRequestDocument,\n addMinimalViableSchemaToRequestDocument,\n} from \"@graphitation/supermassive\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport gqlTag from \"graphql-tag\";\n\nexport type SupermassiveOutputType = \"V3\" | \"V2\" | \"BOTH\";\n\ntype RawClientSidePluginConfig = RawClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n supermassiveDocumentNodeOutputType?: SupermassiveOutputType;\n};\ntype ClientSidePluginConfig = ClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n supermassiveDocumentNodeOutputType?: SupermassiveOutputType;\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 supermassiveDocumentNodeOutputType:\n rawConfig.supermassiveDocumentNodeOutputType || \"V3\",\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 = this.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 ? this.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 this.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 private addTypesToRequestDocument(\n schema: GraphQLSchema,\n document: DocumentNode,\n ) {\n let finalDocument = document;\n if (\n this.config.supermassiveDocumentNodeOutputType === \"V3\" ||\n this.config.supermassiveDocumentNodeOutputType === \"BOTH\"\n ) {\n finalDocument = addMinimalViableSchemaToRequestDocument(\n schema,\n finalDocument,\n {\n addTo: \"PROPERTY\",\n },\n );\n }\n\n if (\n this.config.supermassiveDocumentNodeOutputType === \"V2\" ||\n this.config.supermassiveDocumentNodeOutputType === \"BOTH\"\n ) {\n finalDocument = addSupermassiveLegacyTypesToRequestDocument(\n schema,\n finalDocument,\n ) as unknown as DocumentNode;\n }\n return finalDocument;\n }\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,uBAAqB;AAErB,mCAMO;AAC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AAK;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,0CAAa,gBAC1C,KAAK,OAAO,iBAAiB,0CAAa,+BAC1C,KAAK,OAAO,iBAAiB,0CAAa,YAC1C;AACA,aAAO,+BAA+B,eAAe;AAAA,IACvD;AAEA,WAAO,MAAM,yBAAyB,YAAY,gBAAgB,IAAI;AAAA,EACxE;AAAA,EAEQ,0BACN,QACA,UACA;AACA,QAAI,gBAAgB;AACpB,QACE,KAAK,OAAO,uCAAuC,QACnD,KAAK,OAAO,uCAAuC,QACnD;AACA,0BAAgB;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,UACE,OAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAEA,QACE,KAAK,OAAO,uCAAuC,QACnD,KAAK,OAAO,uCAAuC,QACnD;AACA,0BAAgB;AAAA,QACd;AAAA,QACA;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": ["autoBind", "gqlTag"]
7
7
  }
package/lib/visitor.mjs CHANGED
@@ -140,7 +140,7 @@ var TypeScriptDocumentNodesVisitor = class extends ClientSideBaseVisitor {
140
140
  if (this.config.supermassiveDocumentNodeOutputType === "V3" || this.config.supermassiveDocumentNodeOutputType === "BOTH") {
141
141
  finalDocument = addMinimalViableSchemaToRequestDocument(
142
142
  schema,
143
- document,
143
+ finalDocument,
144
144
  {
145
145
  addTo: "PROPERTY"
146
146
  }
@@ -149,7 +149,7 @@ var TypeScriptDocumentNodesVisitor = class extends ClientSideBaseVisitor {
149
149
  if (this.config.supermassiveDocumentNodeOutputType === "V2" || this.config.supermassiveDocumentNodeOutputType === "BOTH") {
150
150
  finalDocument = addSupermassiveLegacyTypesToRequestDocument(
151
151
  schema,
152
- document
152
+ finalDocument
153
153
  );
154
154
  }
155
155
  return finalDocument;
@@ -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 {\n addSupermassiveLegacyTypesToRequestDocument,\n addMinimalViableSchemaToRequestDocument,\n} from \"@graphitation/supermassive\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport gqlTag from \"graphql-tag\";\n\nexport type SupermassiveOutputType = \"V3\" | \"V2\" | \"BOTH\";\n\ntype RawClientSidePluginConfig = RawClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n supermassiveDocumentNodeOutputType?: SupermassiveOutputType;\n};\ntype ClientSidePluginConfig = ClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n supermassiveDocumentNodeOutputType?: SupermassiveOutputType;\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 supermassiveDocumentNodeOutputType:\n rawConfig.supermassiveDocumentNodeOutputType || \"V3\",\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 = this.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 ? this.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 this.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 private addTypesToRequestDocument(\n schema: GraphQLSchema,\n document: DocumentNode,\n ) {\n let finalDocument = document;\n if (\n this.config.supermassiveDocumentNodeOutputType === \"V3\" ||\n this.config.supermassiveDocumentNodeOutputType === \"BOTH\"\n ) {\n finalDocument = addMinimalViableSchemaToRequestDocument(\n schema,\n document,\n {\n addTo: \"PROPERTY\",\n },\n );\n }\n\n if (\n this.config.supermassiveDocumentNodeOutputType === \"V2\" ||\n this.config.supermassiveDocumentNodeOutputType === \"BOTH\"\n ) {\n finalDocument = addSupermassiveLegacyTypesToRequestDocument(\n schema,\n document,\n ) as unknown as DocumentNode;\n }\n return finalDocument;\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 {\n addSupermassiveLegacyTypesToRequestDocument,\n addMinimalViableSchemaToRequestDocument,\n} from \"@graphitation/supermassive\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport gqlTag from \"graphql-tag\";\n\nexport type SupermassiveOutputType = \"V3\" | \"V2\" | \"BOTH\";\n\ntype RawClientSidePluginConfig = RawClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n supermassiveDocumentNodeOutputType?: SupermassiveOutputType;\n};\ntype ClientSidePluginConfig = ClientSideBasePluginConfig & {\n supermassiveDocumentNodeConditional?: string;\n supermassiveDocumentNodeOutputType?: SupermassiveOutputType;\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 supermassiveDocumentNodeOutputType:\n rawConfig.supermassiveDocumentNodeOutputType || \"V3\",\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 = this.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 ? this.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 this.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 private addTypesToRequestDocument(\n schema: GraphQLSchema,\n document: DocumentNode,\n ) {\n let finalDocument = document;\n if (\n this.config.supermassiveDocumentNodeOutputType === \"V3\" ||\n this.config.supermassiveDocumentNodeOutputType === \"BOTH\"\n ) {\n finalDocument = addMinimalViableSchemaToRequestDocument(\n schema,\n finalDocument,\n {\n addTo: \"PROPERTY\",\n },\n );\n }\n\n if (\n this.config.supermassiveDocumentNodeOutputType === \"V2\" ||\n this.config.supermassiveDocumentNodeOutputType === \"BOTH\"\n ) {\n finalDocument = addSupermassiveLegacyTypesToRequestDocument(\n schema,\n finalDocument,\n ) as unknown as DocumentNode;\n }\n return finalDocument;\n }\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;AAKA,OAAO,cAAc;AAErB;AAAA,EAEE;AAAA,EAEA;AAAA,OAEK;AACP;AAAA,EAIE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AACrC,OAAO,YAAY;AAaZ,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,QACZ,oCACE,UAAU,sCAAsC;AAAA,MACpD;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,YAAM,WAAW,KAAK,QAAQ,MAAM,KAAK;AACzC,aAAO,IAAI,KAAK,OAAO;AAAA,IAA0C;AAAA,IAAmB;AAAA,IACtF;AACA,WAAO,KAAK,QAAQ,MAAM,IAAI;AAAA,EAChC;AAAA,EAEU,QACR,MACA,WAAW,OACH;AACR,UAAM,mBAAmB,KAAK,0BAA0B,KAAK,SAAS;AAAA,MACpE,MAAM,KAAK;AAAA,MACX,aAAa,CAAC,IAAI;AAAA,IACpB,CAAC,EAAE,YAAY,CAAC;A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AE1E,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,KAAK,0BAA0B,KAAK,SAAS;AAAA,UAC3C,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;AAAA,EAEQ,0BACN,QACA,UACA;AACA,QAAI,gBAAgB;AACpB,QACE,KAAK,OAAO,uCAAuC,QACnD,KAAK,OAAO,uCAAuC,QACnD;AACA,sBAAgB;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,UACE,OAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAEA,QACE,KAAK,OAAO,uCAAuC,QACnD,KAAK,OAAO,uCAAuC,QACnD;AACA,sBAAgB;AAAA,QACd;AAAA,QACA;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;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.6.0",
4
+ "version": "0.6.1",
5
5
  "main": "./lib/index",
6
6
  "repository": {
7
7
  "type": "git",