@graphitation/apollo-react-relay-duct-tape-compiler 1.8.3 → 1.8.4
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 +10 -2
- package/lib/formatModule.d.ts.map +1 -1
- package/lib/formatModule.js +5 -6
- package/lib/formatModule.js.map +2 -2
- package/lib/formatModule.mjs +5 -6
- package/lib/formatModule.mjs.map +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
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 Fri, 24 Oct 2025 10:48:08 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.8.4
|
|
8
|
+
|
|
9
|
+
Fri, 24 Oct 2025 10:48:08 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- fix(apollo-react-relay-duct-tape-compiler): decouple emitExecutionDocumentText from emitDocument (vrazuvaev@microsoft.com_msteamsmdb)
|
|
14
|
+
|
|
7
15
|
## 1.8.3
|
|
8
16
|
|
|
9
|
-
Thu, 02 Oct 2025 09:46:
|
|
17
|
+
Thu, 02 Oct 2025 09:46:49 GMT
|
|
10
18
|
|
|
11
19
|
### Patches
|
|
12
20
|
|
|
@@ -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,CAuGvB"}
|
package/lib/formatModule.js
CHANGED
|
@@ -63,10 +63,8 @@ async function formatModuleFactory(options) {
|
|
|
63
63
|
addMinimalViableSchemaToRequestDocument
|
|
64
64
|
} = await import("@graphitation/supermassive"));
|
|
65
65
|
}
|
|
66
|
-
function generateExports(moduleName,
|
|
66
|
+
function generateExports(moduleName, optimizedDocument, emitNarrowObservables) {
|
|
67
67
|
const exports = {};
|
|
68
|
-
const originalDocument = (0, import_graphql.parse)(docText, { noLocation: true });
|
|
69
|
-
const optimizedDocument = (0, import_optimize.optimizeDocumentNode)(originalDocument);
|
|
70
68
|
if (!emitNarrowObservables) {
|
|
71
69
|
exports.executionQueryDocument = optimizedDocument;
|
|
72
70
|
} else {
|
|
@@ -93,15 +91,16 @@ async function formatModuleFactory(options) {
|
|
|
93
91
|
return exports;
|
|
94
92
|
}
|
|
95
93
|
return ({ docText, hash, moduleName, typeText, definition }) => {
|
|
96
|
-
const
|
|
94
|
+
const optimizedDocument = docText && (options.emitDocuments || options.unstable_emitExecutionDocumentText) ? (0, import_optimize.optimizeDocumentNode)((0, import_graphql.parse)(docText, { noLocation: true })) : null;
|
|
95
|
+
const exports = options.emitDocuments ? optimizedDocument && generateExports(
|
|
97
96
|
moduleName,
|
|
98
|
-
|
|
97
|
+
optimizedDocument,
|
|
99
98
|
options.emitNarrowObservables && definition.kind === "Request" && definition.root.operation === "query"
|
|
100
99
|
) : null;
|
|
101
100
|
const reExportWatchNodeQuery = options.emitDocuments && definition.kind === "Fragment";
|
|
102
101
|
const components = [
|
|
103
102
|
typeText,
|
|
104
|
-
|
|
103
|
+
options.unstable_emitExecutionDocumentText && optimizedDocument && printDocument(optimizedDocument),
|
|
105
104
|
exports && options.emitQueryDebugComments && !options.unstable_emitExecutionDocumentText && exports.executionQueryDocument && printDocumentComment(exports.executionQueryDocument),
|
|
106
105
|
exports && options.emitQueryDebugComments && exports.watchQueryDocument && printDocumentComment(exports.watchQueryDocument),
|
|
107
106
|
exports && printExports(exports),
|
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 optimizedDocument: DocumentNode,\n emitNarrowObservables: boolean,\n ) {\n const exports: CompiledArtefactModule = {};\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 optimizedDocument =\n docText &&\n (options.emitDocuments || options.unstable_emitExecutionDocumentText)\n ? optimizeDocumentNode(parse(docText, { noLocation: true }))\n : null;\n const exports = options.emitDocuments\n ? optimizedDocument &&\n generateExports(\n moduleName,\n optimizedDocument,\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 options.unstable_emitExecutionDocumentText &&\n optimizedDocument &&\n printDocument(optimizedDocument),\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 && 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,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,M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
package/lib/formatModule.mjs
CHANGED
|
@@ -31,10 +31,8 @@ async function formatModuleFactory(options) {
|
|
|
31
31
|
addMinimalViableSchemaToRequestDocument
|
|
32
32
|
} = await import("@graphitation/supermassive"));
|
|
33
33
|
}
|
|
34
|
-
function generateExports(moduleName,
|
|
34
|
+
function generateExports(moduleName, optimizedDocument, emitNarrowObservables) {
|
|
35
35
|
const exports = {};
|
|
36
|
-
const originalDocument = parse(docText, { noLocation: true });
|
|
37
|
-
const optimizedDocument = optimizeDocumentNode(originalDocument);
|
|
38
36
|
if (!emitNarrowObservables) {
|
|
39
37
|
exports.executionQueryDocument = optimizedDocument;
|
|
40
38
|
} else {
|
|
@@ -61,15 +59,16 @@ async function formatModuleFactory(options) {
|
|
|
61
59
|
return exports;
|
|
62
60
|
}
|
|
63
61
|
return ({ docText, hash, moduleName, typeText, definition }) => {
|
|
64
|
-
const
|
|
62
|
+
const optimizedDocument = docText && (options.emitDocuments || options.unstable_emitExecutionDocumentText) ? optimizeDocumentNode(parse(docText, { noLocation: true })) : null;
|
|
63
|
+
const exports = options.emitDocuments ? optimizedDocument && generateExports(
|
|
65
64
|
moduleName,
|
|
66
|
-
|
|
65
|
+
optimizedDocument,
|
|
67
66
|
options.emitNarrowObservables && definition.kind === "Request" && definition.root.operation === "query"
|
|
68
67
|
) : null;
|
|
69
68
|
const reExportWatchNodeQuery = options.emitDocuments && definition.kind === "Fragment";
|
|
70
69
|
const components = [
|
|
71
70
|
typeText,
|
|
72
|
-
|
|
71
|
+
options.unstable_emitExecutionDocumentText && optimizedDocument && printDocument(optimizedDocument),
|
|
73
72
|
exports && options.emitQueryDebugComments && !options.unstable_emitExecutionDocumentText && exports.executionQueryDocument && printDocumentComment(exports.executionQueryDocument),
|
|
74
73
|
exports && options.emitQueryDebugComments && exports.watchQueryDocument && printDocumentComment(exports.watchQueryDocument),
|
|
75
74
|
exports && printExports(exports),
|
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 optimizedDocument: DocumentNode,\n emitNarrowObservables: boolean,\n ) {\n const exports: CompiledArtefactModule = {};\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 optimizedDocument =\n docText &&\n (options.emitDocuments || options.unstable_emitExecutionDocumentText)\n ? optimizeDocumentNode(parse(docText, { noLocation: true }))\n : null;\n const exports = options.emitDocuments\n ? optimizedDocument &&\n generateExports(\n moduleName,\n optimizedDocument,\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 options.unstable_emitExecutionDocumentText &&\n optimizedDocument &&\n printDocument(optimizedDocument),\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 && 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;A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,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.4",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"duct-tape-compiler": "./lib/cli.js"
|