@graphitation/graphql-codegen-supermassive-typed-document-node-plugin 1.0.20 → 1.1.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 +19 -2
- package/lib/index.js +2 -22
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +2 -23
- package/lib/index.mjs.map +1 -1
- package/lib/visitor.js +7 -22
- package/lib/visitor.js.map +1 -1
- package/lib/visitor.mjs +7 -25
- package/lib/visitor.mjs.map +1 -1
- package/package.json +2 -2
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/utils/__tests__/print.test.ts":"2","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/block-string.ts":"3","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/print-string.ts":"4","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/print.ts":"5","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/types.ts":"6","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/visitor.ts":"7"},{"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/utils/__tests__/print.test.ts":"2","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/block-string.ts":"3","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/print-string.ts":"4","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/print.ts":"5","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/types.ts":"6","/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/visitor.ts":"7"},{"size":2430,"mtime":1743593505142,"results":"8","hashOfConfig":"9"},{"size":4080,"mtime":1743593505142,"results":"10","hashOfConfig":"9"},{"size":2227,"mtime":1743593505142,"results":"11","hashOfConfig":"9"},{"size":1775,"mtime":1743593505142,"results":"12","hashOfConfig":"9"},{"size":9094,"mtime":1743593505142,"results":"13","hashOfConfig":"9"},{"size":2180,"mtime":1743593505142,"results":"14","hashOfConfig":"9"},{"size":7562,"mtime":1743593505142,"results":"15","hashOfConfig":"9"},{"filePath":"16","messages":"17","suppressedMessages":"18","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1d0uu8i",{"filePath":"19","messages":"20","suppressedMessages":"21","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"22","messages":"23","suppressedMessages":"24","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"25","messages":"26","suppressedMessages":"27","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"28","messages":"29","suppressedMessages":"30","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"31","messages":"32","suppressedMessages":"33","errorCount":0,"fatalErrorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"34","messages":"35","suppressedMessages":"36","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/utils/__tests__/print.test.ts",[],[],"/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/block-string.ts",[],[],"/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/print-string.ts",[],["37"],"/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/print.ts",[],[],"/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/utils/types.ts",["38","39"],[],"/mnt/vss/_work/1/s/packages/graphql-codegen-supermassive-typed-document-node-plugin/src/visitor.ts",[],[],{"ruleId":"40","severity":2,"message":"41","line":14,"column":23,"nodeType":"42","messageId":"43","endLine":14,"endColumn":54,"suppressions":"44"},{"ruleId":"45","severity":1,"message":"46","line":26,"column":6,"nodeType":"47","messageId":"48","endLine":26,"endColumn":9,"suggestions":"49"},{"ruleId":"45","severity":1,"message":"46","line":58,"column":29,"nodeType":"47","messageId":"48","endLine":58,"endColumn":32,"suggestions":"50"},"no-control-regex","Unexpected control character(s) in regular expression: \\x00, \\x1f.","Literal","unexpected",["51"],"@typescript-eslint/no-explicit-any","Unexpected any. Specify a different type.","TSAnyKeyword","unexpectedAny",["52","53"],["54","55"],{"kind":"56","justification":"57"},{"messageId":"58","fix":"59","desc":"60"},{"messageId":"61","fix":"62","desc":"63"},{"messageId":"58","fix":"64","desc":"60"},{"messageId":"61","fix":"65","desc":"63"},"directive","","suggestUnknown",{"range":"66","text":"67"},"Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct.","suggestNever",{"range":"66","text":"68"},"Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of.",{"range":"69","text":"67"},{"range":"69","text":"68"},[990,993],"unknown","never",[2147,2150]]
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
# Change Log - @graphitation/graphql-codegen-supermassive-typed-document-node-plugin
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on
|
|
3
|
+
<!-- This log was last generated on Wed, 02 Apr 2025 11:41:54 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.1.0
|
|
8
|
+
|
|
9
|
+
Wed, 02 Apr 2025 11:41:54 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Changed build target from ES6 to ES2018 (vrazuvaev@microsoft.com_msteamsmdb)
|
|
14
|
+
- Bump @graphitation/supermassive to v3.10.0
|
|
15
|
+
|
|
16
|
+
## 1.0.21
|
|
17
|
+
|
|
18
|
+
Fri, 28 Mar 2025 09:57:05 GMT
|
|
19
|
+
|
|
20
|
+
### Patches
|
|
21
|
+
|
|
22
|
+
- Bump @graphitation/supermassive to v3.9.0
|
|
23
|
+
|
|
7
24
|
## 1.0.20
|
|
8
25
|
|
|
9
|
-
Mon, 24 Mar 2025
|
|
26
|
+
Mon, 24 Mar 2025 11:24:11 GMT
|
|
10
27
|
|
|
11
28
|
### Patches
|
|
12
29
|
|
package/lib/index.js
CHANGED
|
@@ -16,26 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __async = (__this, __arguments, generator) => {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
var fulfilled = (value) => {
|
|
22
|
-
try {
|
|
23
|
-
step(generator.next(value));
|
|
24
|
-
} catch (e) {
|
|
25
|
-
reject(e);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var rejected = (value) => {
|
|
29
|
-
try {
|
|
30
|
-
step(generator.throw(value));
|
|
31
|
-
} catch (e) {
|
|
32
|
-
reject(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
19
|
var src_exports = {};
|
|
40
20
|
__export(src_exports, {
|
|
41
21
|
plugin: () => plugin,
|
|
@@ -76,7 +56,7 @@ const plugin = (schema, documents, config) => {
|
|
|
76
56
|
].join("\n")
|
|
77
57
|
};
|
|
78
58
|
};
|
|
79
|
-
const validate = (schema, documents, config, outputFile) =>
|
|
59
|
+
const validate = async (schema, documents, config, outputFile) => {
|
|
80
60
|
if (config && config.documentMode === import_visitor_plugin_common.DocumentMode.string) {
|
|
81
61
|
throw new Error(
|
|
82
62
|
`Plugin "supermassive-typed-document-node" does not allow using 'documentMode: string' configuration!`
|
|
@@ -87,4 +67,4 @@ const validate = (schema, documents, config, outputFile) => __async(void 0, null
|
|
|
87
67
|
`Plugin "supermassive-typed-document-node" requires extension to be ".ts" or ".tsx"!`
|
|
88
68
|
);
|
|
89
69
|
}
|
|
90
|
-
}
|
|
70
|
+
};
|
package/lib/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["/*\n * Taken from https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/packages/plugins/typescript/typed-document-node/src/index.ts\n * MIT license https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/LICENSE\n */\n\nimport {\n Types,\n PluginValidateFn,\n PluginFunction,\n} from \"@graphql-codegen/plugin-helpers\";\nimport {\n visit,\n concatAST,\n GraphQLSchema,\n Kind,\n FragmentDefinitionNode,\n DocumentNode,\n DefinitionNode,\n} from \"graphql\";\nimport { extname } from \"path\";\nimport {\n LoadedFragment,\n RawClientSideBasePluginConfig,\n DocumentMode,\n} from \"@graphql-codegen/visitor-plugin-common\";\nimport { TypeScriptDocumentNodesVisitor } from \"./visitor\";\n\nexport const plugin: PluginFunction<RawClientSideBasePluginConfig> = (\n schema: GraphQLSchema,\n documents: Types.DocumentFile[],\n config: RawClientSideBasePluginConfig,\n) => {\n const allAst = concatAST(documents.map((v) => v.document as DocumentNode));\n\n const allFragments: LoadedFragment[] = [\n ...(\n allAst.definitions.filter(\n (d) => d.kind === Kind.FRAGMENT_DEFINITION,\n ) as FragmentDefinitionNode[]\n ).map((fragmentDef) => ({\n node: fragmentDef,\n name: fragmentDef.name.value,\n onType: fragmentDef.typeCondition.name.value,\n isExternal: false,\n })),\n ...(config.externalFragments || []),\n ];\n\n const visitor = new TypeScriptDocumentNodesVisitor(\n schema,\n allFragments,\n config,\n documents,\n );\n const visitorResult = visit(allAst, { leave: visitor });\n\n return {\n prepend: allAst.definitions.length === 0 ? [] : visitor.getImports(),\n content: [\n visitor.fragments,\n ...visitorResult.definitions.filter(\n (t: DefinitionNode) => typeof t === \"string\",\n ),\n ].join(\"\\n\"),\n };\n};\n\nexport const validate: PluginValidateFn<RawClientSideBasePluginConfig> = async (\n schema: GraphQLSchema,\n documents: Types.DocumentFile[],\n config,\n outputFile: string,\n) => {\n if (config && config.documentMode === DocumentMode.string) {\n throw new Error(\n `Plugin \"supermassive-typed-document-node\" does not allow using 'documentMode: string' configuration!`,\n );\n }\n\n if (extname(outputFile) !== \".ts\" && extname(outputFile) !== \".tsx\") {\n throw new Error(\n `Plugin \"supermassive-typed-document-node\" requires extension to be \".ts\" or \".tsx\"!`,\n );\n }\n};\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,qBAQO;AACP,kBAAwB;AACxB,mCAIO;AACP,qBAA+C;AAExC,MAAM,SAAwD,CACnE,QACA,WACA,WACG;AACH,QAAM,aAAS,0BAAU,UAAU,IAAI,CAAC,MAAM,EAAE,QAAwB,CAAC;AAEzE,QAAM,eAAiC;AAAA,IACrC,GACE,OAAO,YAAY;AAAA,MACjB,CAAC,MAAM,EAAE,SAAS,oBAAK;AAAA,IACzB,EACA,IAAI,CAAC,iBAAiB;AAAA,MACtB,MAAM;AAAA,MACN,MAAM,YAAY,KAAK;AAAA,MACvB,QAAQ,YAAY,cAAc,KAAK;AAAA,MACvC,YAAY;AAAA,IACd,EAAE;AAAA,IACF,GAAI,OAAO,qBAAqB,CAAC;AAAA,EACnC;AAEA,QAAM,UAAU,IAAI;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,oBAAgB,sBAAM,QAAQ,EAAE,OAAO,QAAQ,CAAC;AAEtD,SAAO;AAAA,IACL,SAAS,OAAO,YAAY,WAAW,IAAI,CAAC,IAAI,QAAQ,WAAW;AAAA,IACnE,SAAS;AAAA,MACP,QAAQ;AAAA,MACR,GAAG,cAAc,YAAY;AAAA,QAC3B,CAAC,MAAsB,OAAO,MAAM;AAAA,MACtC;AAAA,IACF,EAAE,KAAK,IAAI;AAAA,EACb;AACF;AAEO,MAAM,WAA4D,OACvE,QACA,WACA,QACA,eACG;AACH,MAAI,UAAU,OAAO,iBAAiB,0CAAa,QAAQ;AACzD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,UAAI,qBAAQ,UAAU,MAAM,aAAS,qBAAQ,UAAU,MAAM,QAAQ;AACnE,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/index.mjs
CHANGED
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
1
|
// src/index.ts
|
|
23
2
|
import {
|
|
24
3
|
visit,
|
|
@@ -60,7 +39,7 @@ var plugin = (schema, documents, config) => {
|
|
|
60
39
|
].join("\n")
|
|
61
40
|
};
|
|
62
41
|
};
|
|
63
|
-
var validate = (schema, documents, config, outputFile) =>
|
|
42
|
+
var validate = async (schema, documents, config, outputFile) => {
|
|
64
43
|
if (config && config.documentMode === DocumentMode.string) {
|
|
65
44
|
throw new Error(
|
|
66
45
|
`Plugin "supermassive-typed-document-node" does not allow using 'documentMode: string' configuration!`
|
|
@@ -71,7 +50,7 @@ var validate = (schema, documents, config, outputFile) => __async(void 0, null,
|
|
|
71
50
|
`Plugin "supermassive-typed-document-node" requires extension to be ".ts" or ".tsx"!`
|
|
72
51
|
);
|
|
73
52
|
}
|
|
74
|
-
}
|
|
53
|
+
};
|
|
75
54
|
export {
|
|
76
55
|
plugin,
|
|
77
56
|
validate
|
package/lib/index.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["/*\n * Taken from https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/packages/plugins/typescript/typed-document-node/src/index.ts\n * MIT license https://github.com/dotansimha/graphql-code-generator/blob/4fee8c8c523b30163e913438b85a064c58e39087/LICENSE\n */\n\nimport {\n Types,\n PluginValidateFn,\n PluginFunction,\n} from \"@graphql-codegen/plugin-helpers\";\nimport {\n visit,\n concatAST,\n GraphQLSchema,\n Kind,\n FragmentDefinitionNode,\n DocumentNode,\n DefinitionNode,\n} from \"graphql\";\nimport { extname } from \"path\";\nimport {\n LoadedFragment,\n RawClientSideBasePluginConfig,\n DocumentMode,\n} from \"@graphql-codegen/visitor-plugin-common\";\nimport { TypeScriptDocumentNodesVisitor } from \"./visitor\";\n\nexport const plugin: PluginFunction<RawClientSideBasePluginConfig> = (\n schema: GraphQLSchema,\n documents: Types.DocumentFile[],\n config: RawClientSideBasePluginConfig,\n) => {\n const allAst = concatAST(documents.map((v) => v.document as DocumentNode));\n\n const allFragments: LoadedFragment[] = [\n ...(\n allAst.definitions.filter(\n (d) => d.kind === Kind.FRAGMENT_DEFINITION,\n ) as FragmentDefinitionNode[]\n ).map((fragmentDef) => ({\n node: fragmentDef,\n name: fragmentDef.name.value,\n onType: fragmentDef.typeCondition.name.value,\n isExternal: false,\n })),\n ...(config.externalFragments || []),\n ];\n\n const visitor = new TypeScriptDocumentNodesVisitor(\n schema,\n allFragments,\n config,\n documents,\n );\n const visitorResult = visit(allAst, { leave: visitor });\n\n return {\n prepend: allAst.definitions.length === 0 ? [] : visitor.getImports(),\n content: [\n visitor.fragments,\n ...visitorResult.definitions.filter(\n (t: DefinitionNode) => typeof t === \"string\",\n ),\n ].join(\"\\n\"),\n };\n};\n\nexport const validate: PluginValidateFn<RawClientSideBasePluginConfig> = async (\n schema: GraphQLSchema,\n documents: Types.DocumentFile[],\n config,\n outputFile: string,\n) => {\n if (config && config.documentMode === DocumentMode.string) {\n throw new Error(\n `Plugin \"supermassive-typed-document-node\" does not allow using 'documentMode: string' configuration!`,\n );\n }\n\n if (extname(outputFile) !== \".ts\" && extname(outputFile) !== \".tsx\") {\n throw new Error(\n `Plugin \"supermassive-typed-document-node\" requires extension to be \".ts\" or \".tsx\"!`,\n );\n }\n};\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";AAUA;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OAIK;AACP,SAAS,eAAe;AACxB;AAAA,EAGE;AAAA,OACK;AACP,SAAS,sCAAsC;AAExC,IAAM,SAAwD,CACnE,QACA,WACA,WACG;AACH,QAAM,SAAS,UAAU,UAAU,IAAI,CAAC,MAAM,EAAE,QAAwB,CAAC;AAEzE,QAAM,eAAiC;AAAA,IACrC,GACE,OAAO,YAAY;AAAA,MACjB,CAAC,MAAM,EAAE,SAAS,KAAK;AAAA,IACzB,EACA,IAAI,CAAC,iBAAiB;AAAA,MACtB,MAAM;AAAA,MACN,MAAM,YAAY,KAAK;AAAA,MACvB,QAAQ,YAAY,cAAc,KAAK;AAAA,MACvC,YAAY;AAAA,IACd,EAAE;AAAA,IACF,GAAI,OAAO,qBAAqB,CAAC;AAAA,EACnC;AAEA,QAAM,UAAU,IAAI;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,gBAAgB,MAAM,QAAQ,EAAE,OAAO,QAAQ,CAAC;AAEtD,SAAO;AAAA,IACL,SAAS,OAAO,YAAY,WAAW,IAAI,CAAC,IAAI,QAAQ,WAAW;AAAA,IACnE,SAAS;AAAA,MACP,QAAQ;AAAA,MACR,GAAG,cAAc,YAAY;AAAA,QAC3B,CAAC,MAAsB,OAAO,MAAM;AAAA,MACtC;AAAA,IACF,EAAE,KAAK,IAAI;AAAA,EACb;AACF;AAEO,IAAM,WAA4D,OACvE,QACA,WACA,QACA,eACG;AACH,MAAI,UAAU,OAAO,iBAAiB,aAAa,QAAQ;AACzD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI,QAAQ,UAAU,MAAM,SAAS,QAAQ,UAAU,MAAM,QAAQ;AACnE,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/visitor.js
CHANGED
|
@@ -1,27 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
8
|
var __export = (target, all) => {
|
|
26
9
|
for (var name in all)
|
|
27
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -61,10 +44,11 @@ class TypeScriptDocumentNodesVisitor extends import_visitor_plugin_common.Client
|
|
|
61
44
|
super(
|
|
62
45
|
schema,
|
|
63
46
|
fragments,
|
|
64
|
-
|
|
47
|
+
{
|
|
65
48
|
documentMode: import_visitor_plugin_common.DocumentMode.documentNodeImportFragments,
|
|
66
|
-
documentNodeImport: "@graphql-typed-document-node/core#TypedDocumentNode"
|
|
67
|
-
|
|
49
|
+
documentNodeImport: "@graphql-typed-document-node/core#TypedDocumentNode",
|
|
50
|
+
...rawConfig
|
|
51
|
+
},
|
|
68
52
|
{
|
|
69
53
|
astType: (_a = rawConfig.astType) != null ? _a : "SupermassiveV3"
|
|
70
54
|
},
|
|
@@ -182,14 +166,15 @@ class TypeScriptDocumentNodesVisitor extends import_visitor_plugin_common.Client
|
|
|
182
166
|
return (gqlImport.propName || "gql") + "`" + doc + "`";
|
|
183
167
|
}
|
|
184
168
|
_transformDocumentNodeToSupermassive(document) {
|
|
185
|
-
return
|
|
169
|
+
return {
|
|
170
|
+
...document,
|
|
186
171
|
definitions: document.definitions.map(
|
|
187
172
|
(t) => this.addTypesToRequestDocument(this._schema, {
|
|
188
173
|
kind: import_graphql.Kind.DOCUMENT,
|
|
189
174
|
definitions: [t]
|
|
190
175
|
}).definitions[0]
|
|
191
176
|
)
|
|
192
|
-
}
|
|
177
|
+
};
|
|
193
178
|
}
|
|
194
179
|
addTypesToRequestDocument(schema, document) {
|
|
195
180
|
let finalDocument = document;
|
package/lib/visitor.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/visitor.ts"],
|
|
4
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 Kind,\n OperationDefinitionNode,\n parse,\n} from \"graphql\";\nimport { addMinimalViableSchemaToRequestDocument } from \"@graphitation/supermassive\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport gqlTag from \"graphql-tag\";\nimport { print } from \"./utils/print\";\n\nexport type SupermassiveAstType = \"SupermassiveV3\" | \"Lazy\" | \"Standard\";\nexport type RuntimeParseImport = { moduleName: string; propName: string };\n\ntype RawClientSidePluginConfig = RawClientSideBasePluginConfig & {\n runtimeParseImport?: RuntimeParseImport;\n astType?: SupermassiveAstType;\n};\ntype ClientSidePluginConfig = ClientSideBasePluginConfig & {\n astType?: SupermassiveAstType;\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 astType: rawConfig.astType ?? \"SupermassiveV3\",\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 if (this.config.astType === \"Lazy\") {\n const { runtimeParseImport } = rawConfig;\n if (!validateRuntimeParseImport(runtimeParseImport)) {\n throw new Error(\n `graphql-codegen-supermassive-typed-document-node-plugin: astType=\"Lazy\" requires valid runtimeParseImport in the config`,\n );\n }\n\n const tagImport = this._generateImport(\n runtimeParseImport,\n \"runtimeParse\",\n false,\n ) as string;\n this._imports.add(tagImport);\n }\n }\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 protected _gql(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ): string {\n switch (this.config.astType) {\n case \"Lazy\":\n return this._renderLazy(node);\n\n case \"SupermassiveV3\":\n return this._render(node, true);\n\n case \"Standard\":\n default:\n return this._render(node, false);\n }\n }\n\n private _renderLazy(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ): string {\n const fragments = this._transformFragments(node);\n const doc = this._prepareDocument(`\n ${print(node)}\n ${this._includeFragments(fragments)}\n `);\n\n const gqlObj = parse(doc, { noLocation: true });\n return `\n{\n kind: \"Document\",\n get definitions() {\n const document = runtimeParse('${print(gqlObj)}');\n delete this.definitions;\n return (this.definitions = ${\n !fragments.length\n ? \"document.definitions\"\n : `[${[\n \"...document.definitions\",\n ...fragments.map((name) => `...${name}.definitions`),\n ].join(\",\")}]`\n });\n }\n}`;\n }\n\n private _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 ${print(supermassiveNode)}\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\n private addTypesToRequestDocument(\n schema: GraphQLSchema,\n document: DocumentNode,\n ) {\n let finalDocument = document;\n if (this.config.astType === \"SupermassiveV3\") {\n finalDocument = addMinimalViableSchemaToRequestDocument(\n schema,\n finalDocument,\n {\n addTo: \"PROPERTY\",\n },\n );\n }\n return finalDocument;\n }\n}\n\nfunction validateRuntimeParseImport(\n input: unknown,\n): input is RuntimeParseImport {\n const parseImport = input as RuntimeParseImport;\n return (\n typeof parseImport === \"object\" &&\n !!parseImport.moduleName &&\n !!parseImport.propName\n );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,uBAAqB;AAErB,mCAMO;AACP,qBAOO;AACP,0BAAwD;AACxD,sBAAqC;AACrC,yBAAmB;AACnB,mBAAsB;AAaf,MAAM,uCAAuC,mDAGlD;AAAA,EACA,YACE,QACA,W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YAAY,cACd,CAAC,CAAC,YAAY;AAElB;",
|
|
6
6
|
"names": ["autoBind", "gqlTag"]
|
|
7
7
|
}
|
package/lib/visitor.mjs
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
1
|
// src/visitor.ts
|
|
22
2
|
import autoBind from "auto-bind";
|
|
23
3
|
import {
|
|
@@ -38,10 +18,11 @@ var TypeScriptDocumentNodesVisitor = class extends ClientSideBaseVisitor {
|
|
|
38
18
|
super(
|
|
39
19
|
schema,
|
|
40
20
|
fragments,
|
|
41
|
-
|
|
21
|
+
{
|
|
42
22
|
documentMode: DocumentMode.documentNodeImportFragments,
|
|
43
|
-
documentNodeImport: "@graphql-typed-document-node/core#TypedDocumentNode"
|
|
44
|
-
|
|
23
|
+
documentNodeImport: "@graphql-typed-document-node/core#TypedDocumentNode",
|
|
24
|
+
...rawConfig
|
|
25
|
+
},
|
|
45
26
|
{
|
|
46
27
|
astType: (_a = rawConfig.astType) != null ? _a : "SupermassiveV3"
|
|
47
28
|
},
|
|
@@ -159,14 +140,15 @@ var TypeScriptDocumentNodesVisitor = class extends ClientSideBaseVisitor {
|
|
|
159
140
|
return (gqlImport.propName || "gql") + "`" + doc + "`";
|
|
160
141
|
}
|
|
161
142
|
_transformDocumentNodeToSupermassive(document) {
|
|
162
|
-
return
|
|
143
|
+
return {
|
|
144
|
+
...document,
|
|
163
145
|
definitions: document.definitions.map(
|
|
164
146
|
(t) => this.addTypesToRequestDocument(this._schema, {
|
|
165
147
|
kind: Kind.DOCUMENT,
|
|
166
148
|
definitions: [t]
|
|
167
149
|
}).definitions[0]
|
|
168
150
|
)
|
|
169
|
-
}
|
|
151
|
+
};
|
|
170
152
|
}
|
|
171
153
|
addTypesToRequestDocument(schema, document) {
|
|
172
154
|
let finalDocument = document;
|
package/lib/visitor.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/visitor.ts"],
|
|
4
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 Kind,\n OperationDefinitionNode,\n parse,\n} from \"graphql\";\nimport { addMinimalViableSchemaToRequestDocument } from \"@graphitation/supermassive\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport gqlTag from \"graphql-tag\";\nimport { print } from \"./utils/print\";\n\nexport type SupermassiveAstType = \"SupermassiveV3\" | \"Lazy\" | \"Standard\";\nexport type RuntimeParseImport = { moduleName: string; propName: string };\n\ntype RawClientSidePluginConfig = RawClientSideBasePluginConfig & {\n runtimeParseImport?: RuntimeParseImport;\n astType?: SupermassiveAstType;\n};\ntype ClientSidePluginConfig = ClientSideBasePluginConfig & {\n astType?: SupermassiveAstType;\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 astType: rawConfig.astType ?? \"SupermassiveV3\",\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 if (this.config.astType === \"Lazy\") {\n const { runtimeParseImport } = rawConfig;\n if (!validateRuntimeParseImport(runtimeParseImport)) {\n throw new Error(\n `graphql-codegen-supermassive-typed-document-node-plugin: astType=\"Lazy\" requires valid runtimeParseImport in the config`,\n );\n }\n\n const tagImport = this._generateImport(\n runtimeParseImport,\n \"runtimeParse\",\n false,\n ) as string;\n this._imports.add(tagImport);\n }\n }\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 protected _gql(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ): string {\n switch (this.config.astType) {\n case \"Lazy\":\n return this._renderLazy(node);\n\n case \"SupermassiveV3\":\n return this._render(node, true);\n\n case \"Standard\":\n default:\n return this._render(node, false);\n }\n }\n\n private _renderLazy(\n node: FragmentDefinitionNode | OperationDefinitionNode,\n ): string {\n const fragments = this._transformFragments(node);\n const doc = this._prepareDocument(`\n ${print(node)}\n ${this._includeFragments(fragments)}\n `);\n\n const gqlObj = parse(doc, { noLocation: true });\n return `\n{\n kind: \"Document\",\n get definitions() {\n const document = runtimeParse('${print(gqlObj)}');\n delete this.definitions;\n return (this.definitions = ${\n !fragments.length\n ? \"document.definitions\"\n : `[${[\n \"...document.definitions\",\n ...fragments.map((name) => `...${name}.definitions`),\n ].join(\",\")}]`\n });\n }\n}`;\n }\n\n private _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 ${print(supermassiveNode)}\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\n private addTypesToRequestDocument(\n schema: GraphQLSchema,\n document: DocumentNode,\n ) {\n let finalDocument = document;\n if (this.config.astType === \"SupermassiveV3\") {\n finalDocument = addMinimalViableSchemaToRequestDocument(\n schema,\n finalDocument,\n {\n addTo: \"PROPERTY\",\n },\n );\n }\n return finalDocument;\n }\n}\n\nfunction validateRuntimeParseImport(\n input: unknown,\n): input is RuntimeParseImport {\n const parseImport = input as RuntimeParseImport;\n return (\n typeof parseImport === \"object\" &&\n !!parseImport.moduleName &&\n !!parseImport.propName\n );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";AAKA,OAAO,cAAc;AAErB;AAAA,EAEE;AAAA,EAEA;AAAA,OAEK;AACP;AAAA,EAIE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,+CAA+C;AACxD,SAAS,4BAA4B;AACrC,OAAO,YAAY;AACnB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BAAgB,YACvB,CAAC,CAAC,YAAY,cACd,CAAC,CAAC,YAAY;AAElB;",
|
|
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": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"main": "./lib/index",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@graphql-codegen/visitor-plugin-common": ">= ^1.17.0 < 2",
|
|
30
30
|
"graphql-tag": ">= 2.11.0 < 3",
|
|
31
31
|
"@graphql-tools/optimize": "^1.0.1",
|
|
32
|
-
"@graphitation/supermassive": "^3.
|
|
32
|
+
"@graphitation/supermassive": "^3.10.0"
|
|
33
33
|
},
|
|
34
34
|
"sideEffects": false,
|
|
35
35
|
"access": "public",
|