@graphitation/apollo-react-relay-duct-tape-compiler 1.8.4 → 1.8.6
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/CHANGELOG.md +18 -2
- package/lib/formatModule.d.ts.map +1 -1
- package/lib/formatModule.js +7 -6
- package/lib/formatModule.js.map +2 -2
- package/lib/formatModule.mjs +7 -6
- package/lib/formatModule.mjs.map +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
# Change Log - @graphitation/apollo-react-relay-duct-tape-compiler
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on
|
|
3
|
+
<!-- This log was last generated on Thu, 06 Nov 2025 11:01:46 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.8.6
|
|
8
|
+
|
|
9
|
+
Thu, 06 Nov 2025 11:01:46 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- Bump @graphitation/supermassive to v3.11.12
|
|
14
|
+
|
|
15
|
+
## 1.8.5
|
|
16
|
+
|
|
17
|
+
Fri, 24 Oct 2025 13:30:18 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- fix(apollo-react-relay-duct-tape-compiler): strip fragment refs from emitted source text when emitNarrowObservables=true (vrazuvaev@microsoft.com_msteamsmdb)
|
|
22
|
+
|
|
7
23
|
## 1.8.4
|
|
8
24
|
|
|
9
|
-
Fri, 24 Oct 2025 10:48:
|
|
25
|
+
Fri, 24 Oct 2025 10:48:23 GMT
|
|
10
26
|
|
|
11
27
|
### Patches
|
|
12
28
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatModule.d.ts","sourceRoot":"","sources":["../src/formatModule.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AAI7F,MAAM,MAAM,sBAAsB,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;AAE1D,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,OAAO,CAAC;IACvB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,sBAAsB,EAAE,OAAO,CAAC;IAChC,yBAAyB,EAAE,OAAO,CAAC;IACnC,kCAAkC,EAAE,sBAAsB,CAAC;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC,EAAE,OAAO,CAAC;CAC7C;AAaD,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"formatModule.d.ts","sourceRoot":"","sources":["../src/formatModule.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AAI7F,MAAM,MAAM,sBAAsB,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;AAE1D,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,OAAO,CAAC;IACvB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,sBAAsB,EAAE,OAAO,CAAC;IAChC,yBAAyB,EAAE,OAAO,CAAC;IACnC,kCAAkC,EAAE,sBAAsB,CAAC;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC,EAAE,OAAO,CAAC;CAC7C;AAaD,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,YAAY,CAAC,CAsGvB"}
|
package/lib/formatModule.js
CHANGED
|
@@ -63,8 +63,10 @@ async function formatModuleFactory(options) {
|
|
|
63
63
|
addMinimalViableSchemaToRequestDocument
|
|
64
64
|
} = await import("@graphitation/supermassive"));
|
|
65
65
|
}
|
|
66
|
-
function generateExports(moduleName,
|
|
66
|
+
function generateExports(moduleName, docText, emitNarrowObservables) {
|
|
67
67
|
const exports = {};
|
|
68
|
+
const originalDocument = (0, import_graphql.parse)(docText, { noLocation: true });
|
|
69
|
+
const optimizedDocument = (0, import_optimize.optimizeDocumentNode)(originalDocument);
|
|
68
70
|
if (!emitNarrowObservables) {
|
|
69
71
|
exports.executionQueryDocument = optimizedDocument;
|
|
70
72
|
} else {
|
|
@@ -91,19 +93,18 @@ async function formatModuleFactory(options) {
|
|
|
91
93
|
return exports;
|
|
92
94
|
}
|
|
93
95
|
return ({ docText, hash, moduleName, typeText, definition }) => {
|
|
94
|
-
const
|
|
95
|
-
const exports = options.emitDocuments ? optimizedDocument && generateExports(
|
|
96
|
+
const exports = options.emitDocuments || options.unstable_emitExecutionDocumentText ? docText && generateExports(
|
|
96
97
|
moduleName,
|
|
97
|
-
|
|
98
|
+
docText,
|
|
98
99
|
options.emitNarrowObservables && definition.kind === "Request" && definition.root.operation === "query"
|
|
99
100
|
) : null;
|
|
100
101
|
const reExportWatchNodeQuery = options.emitDocuments && definition.kind === "Fragment";
|
|
101
102
|
const components = [
|
|
102
103
|
typeText,
|
|
103
|
-
options.unstable_emitExecutionDocumentText &&
|
|
104
|
+
exports && options.unstable_emitExecutionDocumentText && exports.executionQueryDocument && printDocument(exports.executionQueryDocument),
|
|
104
105
|
exports && options.emitQueryDebugComments && !options.unstable_emitExecutionDocumentText && exports.executionQueryDocument && printDocumentComment(exports.executionQueryDocument),
|
|
105
106
|
exports && options.emitQueryDebugComments && exports.watchQueryDocument && printDocumentComment(exports.watchQueryDocument),
|
|
106
|
-
exports && printExports(exports),
|
|
107
|
+
exports && options.emitDocuments && printExports(exports),
|
|
107
108
|
reExportWatchNodeQuery && printWatchNodeQueryReExport(definition)
|
|
108
109
|
].filter(Boolean);
|
|
109
110
|
return `// @apollo-react-relay-duct-tape
|
package/lib/formatModule.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/formatModule.ts"],
|
|
4
|
-
"sourcesContent": ["import { parse, print } from \"graphql\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport { reduceNodeWatchQueryTransform } from \"./formatModuleTransforms/reduceNodeWatchQueryTransform\";\nimport invariant from \"invariant\";\nimport { stripFragmentReferenceFieldSelectionTransform } from \"./formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform\";\nimport { extractMetadataTransform } from \"./formatModuleTransforms/extractMetadataTransform\";\nimport { buildSchema, Source } from \"graphql\";\nimport { readFileSync } from \"fs\";\nimport dedupeJSONStringify from \"relay-compiler/lib/util/dedupeJSONStringify\";\n\nimport type { DocumentNode, GraphQLSchema } from \"graphql\";\nimport type { FormatModule } from \"relay-compiler/lib/language/RelayLanguagePluginInterface\";\nimport type { CompiledArtefactModule } from \"./types\";\nimport { Fragment } from \"relay-compiler\";\n\nexport type SupermassiveOutputType = \"V3\" | \"V2\" | \"BOTH\";\n\nexport interface FormatModuleOptions {\n emitDocuments: boolean;\n emitNarrowObservables: boolean;\n emitQueryDebugComments: boolean;\n emitSupermassiveDocuments: boolean;\n supermassiveDocumentNodeOutputType: SupermassiveOutputType;\n schema: string;\n unstable_emitExecutionDocumentText: boolean;\n}\n\nfunction printDocumentComment(document: DocumentNode) {\n return `/*\\n${print(document).trim()}\\n*/`;\n}\n\nfunction printDocument(document: DocumentNode) {\n return `\n// Note: executionDocumentText is necessary for Lazy AST and build-time operations analysis\nconst executionDocumentText = \\`${print(document).trim()}\\`;\n`;\n}\n\nexport async function formatModuleFactory(\n options: FormatModuleOptions,\n): Promise<FormatModule> {\n const schema =\n options.emitNarrowObservables || options.emitSupermassiveDocuments\n ? buildSchema(\n new Source(readFileSync(options.schema, \"utf-8\"), options.schema),\n )\n : null;\n\n let addSupermassiveLegacyTypesToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive\").addSupermassiveLegacyTypesToRequestDocument;\n let addMinimalViableSchemaToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive\").addMinimalViableSchemaToRequestDocument;\n if (options.emitSupermassiveDocuments) {\n ({\n addSupermassiveLegacyTypesToRequestDocument,\n addMinimalViableSchemaToRequestDocument,\n } = await import(\"@graphitation/supermassive\"));\n }\n\n function generateExports(\n moduleName: string,\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,sBAAqC;AACrC,2CAA8C;AAC9C,uBAAsB;AACtB,2DAA8D;AAC9D,sCAAyC;AACzC,IAAAA,kBAAoC;AACpC,gBAA6B;AAC7B,iCAAgC;AAmBhC,SAAS,qBAAqB,UAAwB;AACpD,SAAO;AAAA,MAAO,sBAAM,QAAQ,EAAE,KAAK;AAAA;AACrC;AAEA,SAAS,cAAc,UAAwB;AAC7C,SAAO;AAAA;AAAA,sCAEyB,sBAAM,QAAQ,EAAE,KAAK;AAAA;AAEvD;AAEA,eAAsB,oBACpB,SACuB;AACvB,QAAM,SACJ,QAAQ,yBAAyB,QAAQ,gCACrC;AAAA,IACE,IAAI,2BAAO,wBAAa,QAAQ,QAAQ,OAAO,GAAG,QAAQ,MAAM;AAAA,EAClE,IACA;AAEN,MAAI;AAGJ,MAAI;AAGJ,MAAI,QAAQ,2BAA2B;AACrC,KAAC;AAAA,MACC;AAAA,MACA;AAAA,IACF,IAAI,MAAM,OAAO,4BAA4B;AAAA,EAC/C;AAEA,WAAS,gBACP,YACA,
|
|
4
|
+
"sourcesContent": ["import { parse, print } from \"graphql\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport { reduceNodeWatchQueryTransform } from \"./formatModuleTransforms/reduceNodeWatchQueryTransform\";\nimport invariant from \"invariant\";\nimport { stripFragmentReferenceFieldSelectionTransform } from \"./formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform\";\nimport { extractMetadataTransform } from \"./formatModuleTransforms/extractMetadataTransform\";\nimport { buildSchema, Source } from \"graphql\";\nimport { readFileSync } from \"fs\";\nimport dedupeJSONStringify from \"relay-compiler/lib/util/dedupeJSONStringify\";\n\nimport type { DocumentNode, GraphQLSchema } from \"graphql\";\nimport type { FormatModule } from \"relay-compiler/lib/language/RelayLanguagePluginInterface\";\nimport type { CompiledArtefactModule } from \"./types\";\nimport { Fragment } from \"relay-compiler\";\n\nexport type SupermassiveOutputType = \"V3\" | \"V2\" | \"BOTH\";\n\nexport interface FormatModuleOptions {\n emitDocuments: boolean;\n emitNarrowObservables: boolean;\n emitQueryDebugComments: boolean;\n emitSupermassiveDocuments: boolean;\n supermassiveDocumentNodeOutputType: SupermassiveOutputType;\n schema: string;\n unstable_emitExecutionDocumentText: boolean;\n}\n\nfunction printDocumentComment(document: DocumentNode) {\n return `/*\\n${print(document).trim()}\\n*/`;\n}\n\nfunction printDocument(document: DocumentNode) {\n return `\n// Note: executionDocumentText is necessary for Lazy AST and build-time operations analysis\nconst executionDocumentText = \\`${print(document).trim()}\\`;\n`;\n}\n\nexport async function formatModuleFactory(\n options: FormatModuleOptions,\n): Promise<FormatModule> {\n const schema =\n options.emitNarrowObservables || options.emitSupermassiveDocuments\n ? buildSchema(\n new Source(readFileSync(options.schema, \"utf-8\"), options.schema),\n )\n : null;\n\n let addSupermassiveLegacyTypesToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive\").addSupermassiveLegacyTypesToRequestDocument;\n let addMinimalViableSchemaToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive\").addMinimalViableSchemaToRequestDocument;\n if (options.emitSupermassiveDocuments) {\n ({\n addSupermassiveLegacyTypesToRequestDocument,\n addMinimalViableSchemaToRequestDocument,\n } = await import(\"@graphitation/supermassive\"));\n }\n\n function generateExports(\n moduleName: string,\n docText: string,\n emitNarrowObservables: boolean,\n ) {\n const exports: CompiledArtefactModule = {};\n const originalDocument = parse(docText, { noLocation: true });\n const optimizedDocument = optimizeDocumentNode(originalDocument);\n\n if (!emitNarrowObservables) {\n exports.executionQueryDocument = optimizedDocument;\n } else {\n if (!moduleName.endsWith(\"WatchNodeQuery.graphql\")) {\n exports.executionQueryDocument =\n stripFragmentReferenceFieldSelectionTransform(optimizedDocument);\n }\n\n invariant(schema, \"Expected a schema instance\");\n exports.watchQueryDocument = reduceNodeWatchQueryTransform(\n schema,\n optimizedDocument,\n );\n\n exports.metadata = extractMetadataTransform(exports.watchQueryDocument);\n }\n\n if (options.emitSupermassiveDocuments && exports.executionQueryDocument) {\n invariant(schema, \"Expected a schema instance\");\n exports.executionQueryDocument = addTypesToRequestDocument(\n schema,\n exports.executionQueryDocument,\n options.supermassiveDocumentNodeOutputType,\n addMinimalViableSchemaToRequestDocument,\n addSupermassiveLegacyTypesToRequestDocument,\n ) as DocumentNode;\n }\n\n return exports;\n }\n\n return ({ docText, hash, moduleName, typeText, definition }) => {\n const exports =\n options.emitDocuments || options.unstable_emitExecutionDocumentText\n ? docText &&\n generateExports(\n moduleName,\n docText,\n options.emitNarrowObservables &&\n definition.kind === \"Request\" &&\n definition.root.operation === \"query\",\n )\n : null;\n const reExportWatchNodeQuery =\n options.emitDocuments && definition.kind === \"Fragment\";\n\n const components = [\n typeText,\n exports &&\n options.unstable_emitExecutionDocumentText &&\n exports.executionQueryDocument &&\n printDocument(exports.executionQueryDocument),\n exports &&\n options.emitQueryDebugComments &&\n !options.unstable_emitExecutionDocumentText &&\n exports.executionQueryDocument &&\n printDocumentComment(exports.executionQueryDocument),\n exports &&\n options.emitQueryDebugComments &&\n exports.watchQueryDocument &&\n printDocumentComment(exports.watchQueryDocument),\n exports && options.emitDocuments && printExports(exports),\n reExportWatchNodeQuery && printWatchNodeQueryReExport(definition),\n ].filter(Boolean) as string[];\n\n return `// @apollo-react-relay-duct-tape\n/* tslint:disable */\n/* eslint-disable */\n// @ts-nocheck\n${hash ? `/* ${hash} */\\n` : \"\"}\n${components.join(\"\\n\\n\")}`;\n };\n}\n\n// TODO: hould simply not emit a WatchNodeQuery refetchable directive when there already is a @refetchable directive\nfunction printWatchNodeQueryReExport(definition: Fragment) {\n const refetchable =\n definition.directives.find(\n (d) => d.name === \"refetchable\" && d.loc.kind === \"Source\",\n ) ||\n definition.directives.find(\n (d) => d.name === \"refetchable\" && d.loc.kind === \"Generated\",\n );\n if (!refetchable) {\n return undefined;\n }\n const queryNameArg = refetchable.args[0];\n invariant(\n queryNameArg.name === \"queryName\" && queryNameArg.value.kind === \"Literal\",\n \"Expected a @refetchable(queryName:) argument\",\n );\n\n return `import { documents } from \"./${queryNameArg.value.value}.graphql\";\\nexport default documents;`;\n}\n\nfunction printExports(exports: CompiledArtefactModule) {\n return `export const documents: import(\"@graphitation/apollo-react-relay-duct-tape-compiler\").CompiledArtefactModule = ${dedupeJSONStringify(\n exports,\n )};\\n\\nexport default documents;`;\n}\n\nfunction addTypesToRequestDocument(\n schema: GraphQLSchema,\n document: DocumentNode,\n supermassiveDocumentNodeOutputType: SupermassiveOutputType,\n addMinimalViableSchemaToRequestDocument: any,\n addSupermassiveLegacyTypesToRequestDocument: any,\n) {\n let finalDocument = document;\n if (\n supermassiveDocumentNodeOutputType === \"V3\" ||\n supermassiveDocumentNodeOutputType === \"BOTH\"\n ) {\n finalDocument = addMinimalViableSchemaToRequestDocument(\n schema,\n finalDocument,\n {\n addTo: \"PROPERTY\",\n },\n );\n }\n\n if (\n supermassiveDocumentNodeOutputType === \"V2\" ||\n supermassiveDocumentNodeOutputType === \"BOTH\" ||\n !supermassiveDocumentNodeOutputType\n ) {\n finalDocument = addSupermassiveLegacyTypesToRequestDocument(\n schema,\n finalDocument,\n ) as unknown as DocumentNode;\n }\n return finalDocument;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,sBAAqC;AACrC,2CAA8C;AAC9C,uBAAsB;AACtB,2DAA8D;AAC9D,sCAAyC;AACzC,IAAAA,kBAAoC;AACpC,gBAA6B;AAC7B,iCAAgC;AAmBhC,SAAS,qBAAqB,UAAwB;AACpD,SAAO;AAAA,MAAO,sBAA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QACvC,uCAAuC,QACvC;AACA,oBAAgB;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,MACE,uCAAuC,QACvC,uCAAuC,UACvC,CAAC,oCACD;AACA,oBAAgB;AAAA,MACd;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["import_graphql", "invariant", "dedupeJSONStringify"]
|
|
7
7
|
}
|
package/lib/formatModule.mjs
CHANGED
|
@@ -31,8 +31,10 @@ async function formatModuleFactory(options) {
|
|
|
31
31
|
addMinimalViableSchemaToRequestDocument
|
|
32
32
|
} = await import("@graphitation/supermassive"));
|
|
33
33
|
}
|
|
34
|
-
function generateExports(moduleName,
|
|
34
|
+
function generateExports(moduleName, docText, emitNarrowObservables) {
|
|
35
35
|
const exports = {};
|
|
36
|
+
const originalDocument = parse(docText, { noLocation: true });
|
|
37
|
+
const optimizedDocument = optimizeDocumentNode(originalDocument);
|
|
36
38
|
if (!emitNarrowObservables) {
|
|
37
39
|
exports.executionQueryDocument = optimizedDocument;
|
|
38
40
|
} else {
|
|
@@ -59,19 +61,18 @@ async function formatModuleFactory(options) {
|
|
|
59
61
|
return exports;
|
|
60
62
|
}
|
|
61
63
|
return ({ docText, hash, moduleName, typeText, definition }) => {
|
|
62
|
-
const
|
|
63
|
-
const exports = options.emitDocuments ? optimizedDocument && generateExports(
|
|
64
|
+
const exports = options.emitDocuments || options.unstable_emitExecutionDocumentText ? docText && generateExports(
|
|
64
65
|
moduleName,
|
|
65
|
-
|
|
66
|
+
docText,
|
|
66
67
|
options.emitNarrowObservables && definition.kind === "Request" && definition.root.operation === "query"
|
|
67
68
|
) : null;
|
|
68
69
|
const reExportWatchNodeQuery = options.emitDocuments && definition.kind === "Fragment";
|
|
69
70
|
const components = [
|
|
70
71
|
typeText,
|
|
71
|
-
options.unstable_emitExecutionDocumentText &&
|
|
72
|
+
exports && options.unstable_emitExecutionDocumentText && exports.executionQueryDocument && printDocument(exports.executionQueryDocument),
|
|
72
73
|
exports && options.emitQueryDebugComments && !options.unstable_emitExecutionDocumentText && exports.executionQueryDocument && printDocumentComment(exports.executionQueryDocument),
|
|
73
74
|
exports && options.emitQueryDebugComments && exports.watchQueryDocument && printDocumentComment(exports.watchQueryDocument),
|
|
74
|
-
exports && printExports(exports),
|
|
75
|
+
exports && options.emitDocuments && printExports(exports),
|
|
75
76
|
reExportWatchNodeQuery && printWatchNodeQueryReExport(definition)
|
|
76
77
|
].filter(Boolean);
|
|
77
78
|
return `// @apollo-react-relay-duct-tape
|
package/lib/formatModule.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/formatModule.ts"],
|
|
4
|
-
"sourcesContent": ["import { parse, print } from \"graphql\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport { reduceNodeWatchQueryTransform } from \"./formatModuleTransforms/reduceNodeWatchQueryTransform\";\nimport invariant from \"invariant\";\nimport { stripFragmentReferenceFieldSelectionTransform } from \"./formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform\";\nimport { extractMetadataTransform } from \"./formatModuleTransforms/extractMetadataTransform\";\nimport { buildSchema, Source } from \"graphql\";\nimport { readFileSync } from \"fs\";\nimport dedupeJSONStringify from \"relay-compiler/lib/util/dedupeJSONStringify\";\n\nimport type { DocumentNode, GraphQLSchema } from \"graphql\";\nimport type { FormatModule } from \"relay-compiler/lib/language/RelayLanguagePluginInterface\";\nimport type { CompiledArtefactModule } from \"./types\";\nimport { Fragment } from \"relay-compiler\";\n\nexport type SupermassiveOutputType = \"V3\" | \"V2\" | \"BOTH\";\n\nexport interface FormatModuleOptions {\n emitDocuments: boolean;\n emitNarrowObservables: boolean;\n emitQueryDebugComments: boolean;\n emitSupermassiveDocuments: boolean;\n supermassiveDocumentNodeOutputType: SupermassiveOutputType;\n schema: string;\n unstable_emitExecutionDocumentText: boolean;\n}\n\nfunction printDocumentComment(document: DocumentNode) {\n return `/*\\n${print(document).trim()}\\n*/`;\n}\n\nfunction printDocument(document: DocumentNode) {\n return `\n// Note: executionDocumentText is necessary for Lazy AST and build-time operations analysis\nconst executionDocumentText = \\`${print(document).trim()}\\`;\n`;\n}\n\nexport async function formatModuleFactory(\n options: FormatModuleOptions,\n): Promise<FormatModule> {\n const schema =\n options.emitNarrowObservables || options.emitSupermassiveDocuments\n ? buildSchema(\n new Source(readFileSync(options.schema, \"utf-8\"), options.schema),\n )\n : null;\n\n let addSupermassiveLegacyTypesToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive\").addSupermassiveLegacyTypesToRequestDocument;\n let addMinimalViableSchemaToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive\").addMinimalViableSchemaToRequestDocument;\n if (options.emitSupermassiveDocuments) {\n ({\n addSupermassiveLegacyTypesToRequestDocument,\n addMinimalViableSchemaToRequestDocument,\n } = await import(\"@graphitation/supermassive\"));\n }\n\n function generateExports(\n moduleName: string,\n
|
|
5
|
-
"mappings": ";AAAA,SAAS,OAAO,aAAa;AAC7B,SAAS,4BAA4B;AACrC,SAAS,qCAAqC;AAC9C,OAAO,eAAe;AACtB,SAAS,qDAAqD;AAC9D,SAAS,gCAAgC;AACzC,SAAS,aAAa,cAAc;AACpC,SAAS,oBAAoB;AAC7B,OAAO,yBAAyB;AAmBhC,SAAS,qBAAqB,UAAwB;AACpD,SAAO;AAAA,EAAO,MAAM,QAAQ,EAAE,KAAK;AAAA;AACrC;AAEA,SAAS,cAAc,UAAwB;AAC7C,SAAO;AAAA;AAAA,kCAEyB,MAAM,QAAQ,EAAE,KAAK;AAAA;AAEvD;AAEA,eAAsB,oBACpB,SACuB;AACvB,QAAM,SACJ,QAAQ,yBAAyB,QAAQ,4BACrC;AAAA,IACE,IAAI,OAAO,aAAa,QAAQ,QAAQ,OAAO,GAAG,QAAQ,MAAM;AAAA,EAClE,IACA;AAEN,MAAI;AAGJ,MAAI;AAGJ,MAAI,QAAQ,2BAA2B;AACrC,KAAC;AAAA,MACC;AAAA,MACA;AAAA,IACF,IAAI,MAAM,OAAO,4BAA4B;AAAA,EAC/C;AAEA,WAAS,gBACP,YACA,
|
|
4
|
+
"sourcesContent": ["import { parse, print } from \"graphql\";\nimport { optimizeDocumentNode } from \"@graphql-tools/optimize\";\nimport { reduceNodeWatchQueryTransform } from \"./formatModuleTransforms/reduceNodeWatchQueryTransform\";\nimport invariant from \"invariant\";\nimport { stripFragmentReferenceFieldSelectionTransform } from \"./formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform\";\nimport { extractMetadataTransform } from \"./formatModuleTransforms/extractMetadataTransform\";\nimport { buildSchema, Source } from \"graphql\";\nimport { readFileSync } from \"fs\";\nimport dedupeJSONStringify from \"relay-compiler/lib/util/dedupeJSONStringify\";\n\nimport type { DocumentNode, GraphQLSchema } from \"graphql\";\nimport type { FormatModule } from \"relay-compiler/lib/language/RelayLanguagePluginInterface\";\nimport type { CompiledArtefactModule } from \"./types\";\nimport { Fragment } from \"relay-compiler\";\n\nexport type SupermassiveOutputType = \"V3\" | \"V2\" | \"BOTH\";\n\nexport interface FormatModuleOptions {\n emitDocuments: boolean;\n emitNarrowObservables: boolean;\n emitQueryDebugComments: boolean;\n emitSupermassiveDocuments: boolean;\n supermassiveDocumentNodeOutputType: SupermassiveOutputType;\n schema: string;\n unstable_emitExecutionDocumentText: boolean;\n}\n\nfunction printDocumentComment(document: DocumentNode) {\n return `/*\\n${print(document).trim()}\\n*/`;\n}\n\nfunction printDocument(document: DocumentNode) {\n return `\n// Note: executionDocumentText is necessary for Lazy AST and build-time operations analysis\nconst executionDocumentText = \\`${print(document).trim()}\\`;\n`;\n}\n\nexport async function formatModuleFactory(\n options: FormatModuleOptions,\n): Promise<FormatModule> {\n const schema =\n options.emitNarrowObservables || options.emitSupermassiveDocuments\n ? buildSchema(\n new Source(readFileSync(options.schema, \"utf-8\"), options.schema),\n )\n : null;\n\n let addSupermassiveLegacyTypesToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive\").addSupermassiveLegacyTypesToRequestDocument;\n let addMinimalViableSchemaToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive\").addMinimalViableSchemaToRequestDocument;\n if (options.emitSupermassiveDocuments) {\n ({\n addSupermassiveLegacyTypesToRequestDocument,\n addMinimalViableSchemaToRequestDocument,\n } = await import(\"@graphitation/supermassive\"));\n }\n\n function generateExports(\n moduleName: string,\n docText: string,\n emitNarrowObservables: boolean,\n ) {\n const exports: CompiledArtefactModule = {};\n const originalDocument = parse(docText, { noLocation: true });\n const optimizedDocument = optimizeDocumentNode(originalDocument);\n\n if (!emitNarrowObservables) {\n exports.executionQueryDocument = optimizedDocument;\n } else {\n if (!moduleName.endsWith(\"WatchNodeQuery.graphql\")) {\n exports.executionQueryDocument =\n stripFragmentReferenceFieldSelectionTransform(optimizedDocument);\n }\n\n invariant(schema, \"Expected a schema instance\");\n exports.watchQueryDocument = reduceNodeWatchQueryTransform(\n schema,\n optimizedDocument,\n );\n\n exports.metadata = extractMetadataTransform(exports.watchQueryDocument);\n }\n\n if (options.emitSupermassiveDocuments && exports.executionQueryDocument) {\n invariant(schema, \"Expected a schema instance\");\n exports.executionQueryDocument = addTypesToRequestDocument(\n schema,\n exports.executionQueryDocument,\n options.supermassiveDocumentNodeOutputType,\n addMinimalViableSchemaToRequestDocument,\n addSupermassiveLegacyTypesToRequestDocument,\n ) as DocumentNode;\n }\n\n return exports;\n }\n\n return ({ docText, hash, moduleName, typeText, definition }) => {\n const exports =\n options.emitDocuments || options.unstable_emitExecutionDocumentText\n ? docText &&\n generateExports(\n moduleName,\n docText,\n options.emitNarrowObservables &&\n definition.kind === \"Request\" &&\n definition.root.operation === \"query\",\n )\n : null;\n const reExportWatchNodeQuery =\n options.emitDocuments && definition.kind === \"Fragment\";\n\n const components = [\n typeText,\n exports &&\n options.unstable_emitExecutionDocumentText &&\n exports.executionQueryDocument &&\n printDocument(exports.executionQueryDocument),\n exports &&\n options.emitQueryDebugComments &&\n !options.unstable_emitExecutionDocumentText &&\n exports.executionQueryDocument &&\n printDocumentComment(exports.executionQueryDocument),\n exports &&\n options.emitQueryDebugComments &&\n exports.watchQueryDocument &&\n printDocumentComment(exports.watchQueryDocument),\n exports && options.emitDocuments && printExports(exports),\n reExportWatchNodeQuery && printWatchNodeQueryReExport(definition),\n ].filter(Boolean) as string[];\n\n return `// @apollo-react-relay-duct-tape\n/* tslint:disable */\n/* eslint-disable */\n// @ts-nocheck\n${hash ? `/* ${hash} */\\n` : \"\"}\n${components.join(\"\\n\\n\")}`;\n };\n}\n\n// TODO: hould simply not emit a WatchNodeQuery refetchable directive when there already is a @refetchable directive\nfunction printWatchNodeQueryReExport(definition: Fragment) {\n const refetchable =\n definition.directives.find(\n (d) => d.name === \"refetchable\" && d.loc.kind === \"Source\",\n ) ||\n definition.directives.find(\n (d) => d.name === \"refetchable\" && d.loc.kind === \"Generated\",\n );\n if (!refetchable) {\n return undefined;\n }\n const queryNameArg = refetchable.args[0];\n invariant(\n queryNameArg.name === \"queryName\" && queryNameArg.value.kind === \"Literal\",\n \"Expected a @refetchable(queryName:) argument\",\n );\n\n return `import { documents } from \"./${queryNameArg.value.value}.graphql\";\\nexport default documents;`;\n}\n\nfunction printExports(exports: CompiledArtefactModule) {\n return `export const documents: import(\"@graphitation/apollo-react-relay-duct-tape-compiler\").CompiledArtefactModule = ${dedupeJSONStringify(\n exports,\n )};\\n\\nexport default documents;`;\n}\n\nfunction addTypesToRequestDocument(\n schema: GraphQLSchema,\n document: DocumentNode,\n supermassiveDocumentNodeOutputType: SupermassiveOutputType,\n addMinimalViableSchemaToRequestDocument: any,\n addSupermassiveLegacyTypesToRequestDocument: any,\n) {\n let finalDocument = document;\n if (\n supermassiveDocumentNodeOutputType === \"V3\" ||\n supermassiveDocumentNodeOutputType === \"BOTH\"\n ) {\n finalDocument = addMinimalViableSchemaToRequestDocument(\n schema,\n finalDocument,\n {\n addTo: \"PROPERTY\",\n },\n );\n }\n\n if (\n supermassiveDocumentNodeOutputType === \"V2\" ||\n supermassiveDocumentNodeOutputType === \"BOTH\" ||\n !supermassiveDocumentNodeOutputType\n ) {\n finalDocument = addSupermassiveLegacyTypesToRequestDocument(\n schema,\n finalDocument,\n ) as unknown as DocumentNode;\n }\n return finalDocument;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,OAAO,aAAa;AAC7B,SAAS,4BAA4B;AACrC,SAAS,qCAAqC;AAC9C,OAAO,eAAe;AACtB,SAAS,qDAAqD;AAC9D,SAAS,gCAAgC;AACzC,SAAS,aAAa,cAAc;AACpC,SAAS,oBAAoB;AAC7B,OAAO,yBAAyB;AAmBhC,SAAS,qBAAqB,UAAwB;AACpD,SAAO;AAAA,EAAO,MAAM,QAAQ,EAAE,KAAK;AAAA;AACrC;AAEA,SAAS,cAAc,UAAwB;AAC7C,SAAO;AAAA;AAAA,kCAEyB,MAAM,QAAQ,EAAE,KAAK;AAAA;AAEvD;AAEA,eAAsB,oBACpB,SACuB;AACvB,QAAM,SACJ,QAAQ,yBAAyB,QAAQ,4BACrC;AAAA,IACE,IAAI,OAAO,aAAa,QAAQ,QAAQ,OAAO,GAAG,QAAQ,MAAM;AAAA,EAClE,IACA;AAEN,MAAI;AAGJ,MAAI;AAGJ,MAAI,QAAQ,2BAA2B;AACrC,KAAC;AAAA,MACC;AAAA,MACA;AAAA,IACF,IAAI,MAAM,OAAO,4BAA4B;AAAA,EAC/C;AAEA,WAAS,gBACP,YACA,SACA,uBACA;AACA,UAAM,UAAkC,CAAC;AACzC,UAAM,mBAAmB,MAAM,SAAS,EAAE,YAAY,KAAK,CAAC;AAC5D,UAAM,oBAAoB,qBAAqB,gBAAgB;AAE/D,QAAI,CAAC,uBAAuB;AAC1B,cAAQ,yBAAyB;AAAA,IACnC,OAAO;AACL,UAAI,CAAC,WAAW,SAAS,wBAAwB,GAAG;AAClD,gBAAQ,yBACN,8CAA8C,iB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,EACpD,KACA,WAAW,WAAW;AAAA,IACpB,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,IAAI,SAAS;AAAA,EACpD;AACF,MAAI,CAAC,aAAa;AAChB,WAAO;AAAA,EACT;AACA,QAAM,eAAe,YAAY,KAAK,CAAC;AACvC;AAAA,IACE,aAAa,SAAS,eAAe,aAAa,MAAM,SAAS;AAAA,IACjE;AAAA,EACF;AAEA,SAAO,gCAAgC,aAAa,MAAM;AAAA;AAC5D;AAEA,SAAS,aAAa,SAAiC;AACrD,SAAO,kHAAkH;AAAA,IACvH;AAAA,EACF;AAAA;AAAA;AACF;AAEA,SAAS,0BACP,QACA,UACA,oCACA,yCACA,6CACA;AACA,MAAI,gBAAgB;AACpB,MACE,uCAAuC,QACvC,uCAAuC,QACvC;AACA,oBAAgB;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,MACE,uCAAuC,QACvC,uCAAuC,UACvC,CAAC,oCACD;AACA,oBAAgB;AAAA,MACd;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphitation/apollo-react-relay-duct-tape-compiler",
|
|
3
3
|
"description": "The build tools to cater to @graphitation/apollo-react-relay-duct-tape's needs.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.8.
|
|
5
|
+
"version": "1.8.6",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"duct-tape-compiler": "./lib/cli.js"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"graphql": "^15.0.0",
|
|
45
|
-
"@graphitation/supermassive": "^3.11.
|
|
45
|
+
"@graphitation/supermassive": "^3.11.12",
|
|
46
46
|
"typescript": "^5.5.3"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|