@graphitation/graphql-codegen-supermassive-typed-document-node-plugin 0.6.13 → 0.7.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 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":1705341061846,"results":"3","hashOfConfig":"4"},{"size":6828,"mtime":1705341061846,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","suppressedMessages":"8","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"u5n8sq",{"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":1715761937760,"results":"3","hashOfConfig":"4"},{"size":6909,"mtime":1715761937760,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","suppressedMessages":"8","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"aufvfz",{"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,28 @@
1
1
  # Change Log - @graphitation/graphql-codegen-supermassive-typed-document-node-plugin
2
2
 
3
- This log was last generated on Mon, 15 Jan 2024 17:55:22 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 15 May 2024 08:37:47 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.7.0
8
+
9
+ Wed, 15 May 2024 08:37:47 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - Add NONE option to not output any supermassive stuff (mnovikov@microsoft.com)
14
+
15
+ ## 0.6.14
16
+
17
+ Thu, 07 Mar 2024 13:08:30 GMT
18
+
19
+ ### Patches
20
+
21
+ - Bump @graphitation/supermassive to v3.5.0
22
+
7
23
  ## 0.6.13
8
24
 
9
- Mon, 15 Jan 2024 17:55:22 GMT
25
+ Mon, 15 Jan 2024 17:55:46 GMT
10
26
 
11
27
  ### Patches
12
28
 
package/lib/visitor.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Types } from "@graphql-codegen/plugin-helpers";
2
2
  import { LoadedFragment, ClientSideBaseVisitor, ClientSideBasePluginConfig, RawClientSideBasePluginConfig } from "@graphql-codegen/visitor-plugin-common";
3
3
  import { GraphQLSchema, FragmentDefinitionNode, OperationDefinitionNode } from "graphql";
4
- export type SupermassiveOutputType = "V3" | "V2" | "BOTH";
4
+ export type SupermassiveOutputType = "V3" | "V2" | "BOTH" | "NONE";
5
5
  type RawClientSidePluginConfig = RawClientSideBasePluginConfig & {
6
6
  supermassiveDocumentNodeConditional?: string;
7
7
  supermassiveDocumentNodeOutputType?: SupermassiveOutputType;
@@ -1 +1 @@
1
- {"version":3,"file":"visitor.d.ts","sourceRoot":"","sources":["../src/visitor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AACxD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB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C;AAChD,OAAO,EACL,aAAa,EACb,sBAAsB,EAItB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAQjB,MAAM,MAAM,sBAAsB,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnE,KAAK,yBAAyB,GAAG,6BAA6B,GAAG;IAC/D,mCAAmC,CAAC,EAAE,MAAM,CAAC;IAC7C,kCAAkC,CAAC,EAAE,sBAAsB,CAAC;CAC7D,CAAC;AACF,KAAK,sBAAsB,GAAG,0BAA0B,GAAG;IACzD,mCAAmC,CAAC,EAAE,MAAM,CAAC;IAC7C,kCAAkC,CAAC,EAAE,sBAAsB,CAAC;CAC7D,CAAC;AAEF,qBAAa,8BAA+B,SAAQ,qBAAqB,CACvE,yBAAyB,EACzB,sBAAsB,CACvB;gBAEG,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,cAAc,EAAE,EAC3B,SAAS,EAAE,yBAAyB,EACpC,SAAS,EAAE,KAAK,CAAC,YAAY,EAAE;IAoCjC,SAAS,CAAC,IAAI,CACZ,IAAI,EAAE,sBAAsB,GAAG,uBAAuB,GACrD,MAAM;IAYT,SAAS,CAAC,OAAO,CACf,IAAI,EAAE,sBAAsB,GAAG,uBAAuB,EACtD,QAAQ,UAAQ,GACf,MAAM;IAmET,OAAO,CAAC,oCAAoC;IAY5C,SAAS,CAAC,wBAAwB,CAChC,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,sBAAsB,GAAG,uBAAuB;IAaxD,OAAO,CAAC,yBAAyB;CA6BlC"}
package/lib/visitor.js CHANGED
@@ -90,7 +90,10 @@ class TypeScriptDocumentNodesVisitor extends import_visitor_plugin_common.Client
90
90
  ? ${supermassive}
91
91
  : ${standard})`;
92
92
  }
93
- return this._render(node, true);
93
+ return this._render(
94
+ node,
95
+ this.config.supermassiveDocumentNodeOutputType !== "NONE"
96
+ );
94
97
  }
95
98
  _render(node, annotate = false) {
96
99
  const supermassiveNode = this.addTypesToRequestDocument(this._schema, {
@@ -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 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
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,uBAAqB;AAErB,mCAMO;AACP,qBAOO;AACP,0BAGO;AACP,sBAAqC;AACrC,yBAAmB;AAaZ,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,QACZ,oCACE,UAAU,sCAAsC;AAAA,MACpD;AAAA,MACA;AAAA,IACF;AAEA,yBAAAA,SAAS,IAAI;AAGb,QAAI,KAAK,OAAO,iBAAiB,0CAAa,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,oBAAK;AAAA,MACX,aAAa,CAAC,IAAI;AAAA,IACpB,CAAC,EAAE,YAAY,CAAC;AAEhB,UAA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,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,KAAK,0BAA0B,KAAK,SAAS;AAAA,UAC3C,MAAM,oBAAK;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;",
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\" | \"NONE\";\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(\n node,\n this.config.supermassiveDocumentNodeOutputType !== \"NONE\",\n );\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
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,uBAAqB;AAErB,mCAMO;AACP,qBAOO;AACP,0BAGO;AACP,sBAAqC;AACrC,yBAAmB;AAaZ,MAAM,uCAAuC,mDAGlD;AAAA,EACA,YACE,QACA,WACA,WACA,WACA;AACA;AAAA,MAC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AAA,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
@@ -70,7 +70,10 @@ var TypeScriptDocumentNodesVisitor = class extends ClientSideBaseVisitor {
70
70
  ? ${supermassive}
71
71
  : ${standard})`;
72
72
  }
73
- return this._render(node, true);
73
+ return this._render(
74
+ node,
75
+ this.config.supermassiveDocumentNodeOutputType !== "NONE"
76
+ );
74
77
  }
75
78
  _render(node, annotate = false) {
76
79
  const supermassiveNode = this.addTypesToRequestDocument(this._schema, {
@@ -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 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
- "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,cA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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;",
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\" | \"NONE\";\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(\n node,\n this.config.supermassiveDocumentNodeOutputType !== \"NONE\",\n );\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
+ "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,O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AAuC,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.13",
4
+ "version": "0.7.0",
5
5
  "main": "./lib/index",
6
6
  "repository": {
7
7
  "type": "git",
@@ -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": "^3.4.2"
31
+ "@graphitation/supermassive": "^3.5.0"
32
32
  },
33
33
  "sideEffects": false,
34
34
  "access": "public",