@graphitation/apollo-react-relay-duct-tape-compiler 1.2.1 → 1.2.2
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 +26 -6
- package/lib/formatModule.js.map +2 -2
- package/lib/formatModule.mjs +26 -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 Tue, 25 Jul 2023 08:17:55 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.2.2
|
|
8
|
+
|
|
9
|
+
Tue, 25 Jul 2023 08:17:55 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- Re-export the right docs for a fragment (eloy.de.enige@gmail.com)
|
|
14
|
+
|
|
7
15
|
## 1.2.1
|
|
8
16
|
|
|
9
|
-
Sat, 22 Jul 2023 07:35:
|
|
17
|
+
Sat, 22 Jul 2023 07:35:09 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;
|
|
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,WAAW,mBAAmB;IAClC,aAAa,EAAE,OAAO,CAAC;IACvB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,sBAAsB,EAAE,OAAO,CAAC;IAChC,yBAAyB,EAAE,OAAO,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC;CAChB;AAMD,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,YAAY,CAAC,CA6EvB"}
|
package/lib/formatModule.js
CHANGED
|
@@ -100,17 +100,15 @@ function formatModuleFactory(options) {
|
|
|
100
100
|
}
|
|
101
101
|
return exports;
|
|
102
102
|
}
|
|
103
|
-
return ({ docText, hash, moduleName, typeText }) => {
|
|
103
|
+
return ({ docText, hash, moduleName, typeText, definition }) => {
|
|
104
104
|
const exports = options.emitDocuments ? docText && generateExports(moduleName, docText) : null;
|
|
105
|
+
const reExportWatchNodeQuery = options.emitDocuments && definition.kind === "Fragment";
|
|
105
106
|
const components = [
|
|
106
107
|
typeText,
|
|
107
108
|
exports && options.emitQueryDebugComments && exports.executionQueryDocument && printDocumentComment(exports.executionQueryDocument),
|
|
108
109
|
exports && options.emitQueryDebugComments && exports.watchQueryDocument && printDocumentComment(exports.watchQueryDocument),
|
|
109
|
-
exports &&
|
|
110
|
-
|
|
111
|
-
)};
|
|
112
|
-
|
|
113
|
-
export default documents;`
|
|
110
|
+
exports && printExports(exports),
|
|
111
|
+
reExportWatchNodeQuery && printWatchNodeQueryReExport(definition)
|
|
114
112
|
].filter(Boolean);
|
|
115
113
|
return `/* tslint:disable */
|
|
116
114
|
/* eslint-disable */
|
|
@@ -121,3 +119,25 @@ ${components.join("\n\n")}`;
|
|
|
121
119
|
};
|
|
122
120
|
});
|
|
123
121
|
}
|
|
122
|
+
function printWatchNodeQueryReExport(definition) {
|
|
123
|
+
const refetchable = definition.directives.find(
|
|
124
|
+
(d) => d.name === "refetchable" && d.loc.kind === "Source"
|
|
125
|
+
) || definition.directives.find(
|
|
126
|
+
(d) => d.name === "refetchable" && d.loc.kind === "Generated"
|
|
127
|
+
);
|
|
128
|
+
(0, import_invariant.default)(refetchable, "Expected to find a @refetchable directive");
|
|
129
|
+
const queryNameArg = refetchable.args[0];
|
|
130
|
+
(0, import_invariant.default)(
|
|
131
|
+
queryNameArg.name === "queryName" && queryNameArg.value.kind === "Literal",
|
|
132
|
+
"Expected a @refetchable(queryName:) argument"
|
|
133
|
+
);
|
|
134
|
+
return `import { documents } from "./${queryNameArg.value.value}.graphql";
|
|
135
|
+
export default documents;`;
|
|
136
|
+
}
|
|
137
|
+
function printExports(exports) {
|
|
138
|
+
return `export const documents: import("@graphitation/apollo-react-relay-duct-tape-compiler").CompiledArtefactModule = ${(0, import_dedupeJSONStringify.default)(
|
|
139
|
+
exports
|
|
140
|
+
)};
|
|
141
|
+
|
|
142
|
+
export default documents;`;
|
|
143
|
+
}
|
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 } from \"graphql\";\nimport type { FormatModule } from \"relay-compiler/lib/language/RelayLanguagePluginInterface\";\nimport type { CompiledArtefactModule } from \"./types\";\n\nexport interface FormatModuleOptions {\n emitDocuments: boolean;\n emitNarrowObservables: boolean;\n emitQueryDebugComments: boolean;\n emitSupermassiveDocuments: boolean;\n schema: string;\n}\n\nfunction printDocumentComment(document: DocumentNode) {\n return `/*\\n${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 addTypesToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive-ast\").addTypesToRequestDocument;\n if (options.emitSupermassiveDocuments) {\n ({ addTypesToRequestDocument } = await import(\n \"@graphitation/supermassive-ast\"\n ));\n }\n\n function generateExports(moduleName: string, docText: string) {\n const exports: CompiledArtefactModule = {};\n const originalDocument = parse(docText, { noLocation: true });\n const optimizedDocument = optimizeDocumentNode(originalDocument);\n\n if (!options.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 (addTypesToRequestDocument && exports.executionQueryDocument) {\n invariant(schema, \"Expected a schema instance\");\n exports.executionQueryDocument = addTypesToRequestDocument(\n schema,\n exports.executionQueryDocument,\n ) as DocumentNode;\n }\n\n return exports;\n }\n\n return ({ docText, hash, moduleName, typeText }) => {\n const exports = options.emitDocuments\n ? docText && generateExports(moduleName, docText)\n : null;\n const components = [\n typeText,\n exports &&\n options.emitQueryDebugComments &&\n exports.executionQueryDocument &&\n printDocumentComment(exports.executionQueryDocument),\n exports &&\n options.emitQueryDebugComments &&\n exports.watchQueryDocument &&\n printDocumentComment(exports.watchQueryDocument),\n exports
|
|
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;
|
|
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 } from \"graphql\";\nimport type { FormatModule } from \"relay-compiler/lib/language/RelayLanguagePluginInterface\";\nimport type { CompiledArtefactModule } from \"./types\";\nimport { Definition, Fragment } from \"relay-compiler\";\n\nexport interface FormatModuleOptions {\n emitDocuments: boolean;\n emitNarrowObservables: boolean;\n emitQueryDebugComments: boolean;\n emitSupermassiveDocuments: boolean;\n schema: string;\n}\n\nfunction printDocumentComment(document: DocumentNode) {\n return `/*\\n${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 addTypesToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive-ast\").addTypesToRequestDocument;\n if (options.emitSupermassiveDocuments) {\n ({ addTypesToRequestDocument } = await import(\n \"@graphitation/supermassive-ast\"\n ));\n }\n\n function generateExports(moduleName: string, docText: string) {\n const exports: CompiledArtefactModule = {};\n const originalDocument = parse(docText, { noLocation: true });\n const optimizedDocument = optimizeDocumentNode(originalDocument);\n\n if (!options.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 (addTypesToRequestDocument && exports.executionQueryDocument) {\n invariant(schema, \"Expected a schema instance\");\n exports.executionQueryDocument = addTypesToRequestDocument(\n schema,\n exports.executionQueryDocument,\n ) as DocumentNode;\n }\n\n return exports;\n }\n\n return ({ docText, hash, moduleName, typeText, definition }) => {\n const exports = options.emitDocuments\n ? docText && generateExports(moduleName, docText)\n : null;\n const reExportWatchNodeQuery =\n options.emitDocuments && definition.kind === \"Fragment\";\n\n const components = [\n typeText,\n exports &&\n options.emitQueryDebugComments &&\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 `/* 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 invariant(refetchable, \"Expected to find a @refetchable directive\");\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"],
|
|
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;AAehC,SAAS,qBAAqB,UAAwB;AACpD,SAAO;AAAA,MAAO,sBAAM,QAAQ,EAAE,KAAK;AAAA;AACrC;AAEA,SAAsB,oBACpB,SACuB;AAAA;AACvB,UAAM,SACJ,QAAQ,yBAAyB,QAAQ,gCACrC;AAAA,MACE,IAAI,2BAAO,wBAAa,QAAQ,QAAQ,OAAO,GAAG,QAAQ,MAAM;AAAA,IAClE,IACA;AAEN,QAAI;AAGJ,QAAI,QAAQ,2BAA2B;AACrC,OAAC,EAAE,0BAA0B,IAAI,MAAM,OACrC,gCACF;AAAA,IACF;AAEA,aAAS,gBAAgB,YAAoB,SAAiB;AAC5D,YAAM,UAAkC,CAAC;AACzC,YAAM,uBAAmB,sBAAM,SAAS,EAAE,YAAY,KAAK,CAAC;AAC5D,YAAM,wBAAoB,sCAAqB,gBAAgB;AAE/D,UAAI,CAAC,QAAQ,uBAAuB;AAClC,gBAAQ,yBAAyB;AAAA,MACnC,OAAO;AACL,YAAI,CAAC,WAAW,SAAS,wBAAwB,GAAG;AAClD,kBAAQ,6BACN,oGAA8C,iBAAiB;AAAA,QACnE;AAEA,6BAAAC,SAAU,QAAQ,4BAA4B;AAC9C,gBAAQ,yBAAqB;AAAA,UAC3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D;AAEA,SAAS,aAAa,SAAiC;AACrD,SAAO,sHAAkH,2BAAAC;AAAA,IACvH;AAAA,EACF;AAAA;AAAA;AACF;",
|
|
6
6
|
"names": ["import_graphql", "invariant", "dedupeJSONStringify"]
|
|
7
7
|
}
|
package/lib/formatModule.mjs
CHANGED
|
@@ -69,17 +69,15 @@ function formatModuleFactory(options) {
|
|
|
69
69
|
}
|
|
70
70
|
return exports;
|
|
71
71
|
}
|
|
72
|
-
return ({ docText, hash, moduleName, typeText }) => {
|
|
72
|
+
return ({ docText, hash, moduleName, typeText, definition }) => {
|
|
73
73
|
const exports = options.emitDocuments ? docText && generateExports(moduleName, docText) : null;
|
|
74
|
+
const reExportWatchNodeQuery = options.emitDocuments && definition.kind === "Fragment";
|
|
74
75
|
const components = [
|
|
75
76
|
typeText,
|
|
76
77
|
exports && options.emitQueryDebugComments && exports.executionQueryDocument && printDocumentComment(exports.executionQueryDocument),
|
|
77
78
|
exports && options.emitQueryDebugComments && exports.watchQueryDocument && printDocumentComment(exports.watchQueryDocument),
|
|
78
|
-
exports &&
|
|
79
|
-
|
|
80
|
-
)};
|
|
81
|
-
|
|
82
|
-
export default documents;`
|
|
79
|
+
exports && printExports(exports),
|
|
80
|
+
reExportWatchNodeQuery && printWatchNodeQueryReExport(definition)
|
|
83
81
|
].filter(Boolean);
|
|
84
82
|
return `/* tslint:disable */
|
|
85
83
|
/* eslint-disable */
|
|
@@ -90,6 +88,28 @@ ${components.join("\n\n")}`;
|
|
|
90
88
|
};
|
|
91
89
|
});
|
|
92
90
|
}
|
|
91
|
+
function printWatchNodeQueryReExport(definition) {
|
|
92
|
+
const refetchable = definition.directives.find(
|
|
93
|
+
(d) => d.name === "refetchable" && d.loc.kind === "Source"
|
|
94
|
+
) || definition.directives.find(
|
|
95
|
+
(d) => d.name === "refetchable" && d.loc.kind === "Generated"
|
|
96
|
+
);
|
|
97
|
+
invariant(refetchable, "Expected to find a @refetchable directive");
|
|
98
|
+
const queryNameArg = refetchable.args[0];
|
|
99
|
+
invariant(
|
|
100
|
+
queryNameArg.name === "queryName" && queryNameArg.value.kind === "Literal",
|
|
101
|
+
"Expected a @refetchable(queryName:) argument"
|
|
102
|
+
);
|
|
103
|
+
return `import { documents } from "./${queryNameArg.value.value}.graphql";
|
|
104
|
+
export default documents;`;
|
|
105
|
+
}
|
|
106
|
+
function printExports(exports) {
|
|
107
|
+
return `export const documents: import("@graphitation/apollo-react-relay-duct-tape-compiler").CompiledArtefactModule = ${dedupeJSONStringify(
|
|
108
|
+
exports
|
|
109
|
+
)};
|
|
110
|
+
|
|
111
|
+
export default documents;`;
|
|
112
|
+
}
|
|
93
113
|
export {
|
|
94
114
|
formatModuleFactory
|
|
95
115
|
};
|
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 } from \"graphql\";\nimport type { FormatModule } from \"relay-compiler/lib/language/RelayLanguagePluginInterface\";\nimport type { CompiledArtefactModule } from \"./types\";\n\nexport interface FormatModuleOptions {\n emitDocuments: boolean;\n emitNarrowObservables: boolean;\n emitQueryDebugComments: boolean;\n emitSupermassiveDocuments: boolean;\n schema: string;\n}\n\nfunction printDocumentComment(document: DocumentNode) {\n return `/*\\n${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 addTypesToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive-ast\").addTypesToRequestDocument;\n if (options.emitSupermassiveDocuments) {\n ({ addTypesToRequestDocument } = await import(\n \"@graphitation/supermassive-ast\"\n ));\n }\n\n function generateExports(moduleName: string, docText: string) {\n const exports: CompiledArtefactModule = {};\n const originalDocument = parse(docText, { noLocation: true });\n const optimizedDocument = optimizeDocumentNode(originalDocument);\n\n if (!options.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 (addTypesToRequestDocument && exports.executionQueryDocument) {\n invariant(schema, \"Expected a schema instance\");\n exports.executionQueryDocument = addTypesToRequestDocument(\n schema,\n exports.executionQueryDocument,\n ) as DocumentNode;\n }\n\n return exports;\n }\n\n return ({ docText, hash, moduleName, typeText }) => {\n const exports = options.emitDocuments\n ? docText && generateExports(moduleName, docText)\n : null;\n const components = [\n typeText,\n exports &&\n options.emitQueryDebugComments &&\n exports.executionQueryDocument &&\n printDocumentComment(exports.executionQueryDocument),\n exports &&\n options.emitQueryDebugComments &&\n exports.watchQueryDocument &&\n printDocumentComment(exports.watchQueryDocument),\n exports
|
|
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;
|
|
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 } from \"graphql\";\nimport type { FormatModule } from \"relay-compiler/lib/language/RelayLanguagePluginInterface\";\nimport type { CompiledArtefactModule } from \"./types\";\nimport { Definition, Fragment } from \"relay-compiler\";\n\nexport interface FormatModuleOptions {\n emitDocuments: boolean;\n emitNarrowObservables: boolean;\n emitQueryDebugComments: boolean;\n emitSupermassiveDocuments: boolean;\n schema: string;\n}\n\nfunction printDocumentComment(document: DocumentNode) {\n return `/*\\n${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 addTypesToRequestDocument:\n | undefined\n | typeof import(\"@graphitation/supermassive-ast\").addTypesToRequestDocument;\n if (options.emitSupermassiveDocuments) {\n ({ addTypesToRequestDocument } = await import(\n \"@graphitation/supermassive-ast\"\n ));\n }\n\n function generateExports(moduleName: string, docText: string) {\n const exports: CompiledArtefactModule = {};\n const originalDocument = parse(docText, { noLocation: true });\n const optimizedDocument = optimizeDocumentNode(originalDocument);\n\n if (!options.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 (addTypesToRequestDocument && exports.executionQueryDocument) {\n invariant(schema, \"Expected a schema instance\");\n exports.executionQueryDocument = addTypesToRequestDocument(\n schema,\n exports.executionQueryDocument,\n ) as DocumentNode;\n }\n\n return exports;\n }\n\n return ({ docText, hash, moduleName, typeText, definition }) => {\n const exports = options.emitDocuments\n ? docText && generateExports(moduleName, docText)\n : null;\n const reExportWatchNodeQuery =\n options.emitDocuments && definition.kind === \"Fragment\";\n\n const components = [\n typeText,\n exports &&\n options.emitQueryDebugComments &&\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 `/* 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 invariant(refetchable, \"Expected to find a @refetchable directive\");\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"],
|
|
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;AAehC,SAAS,qBAAqB,UAAwB;AACpD,SAAO;AAAA,EAAO,MAAM,QAAQ,EAAE,KAAK;AAAA;AACrC;AAEA,SAAsB,oBACpB,SACuB;AAAA;AACvB,UAAM,SACJ,QAAQ,yBAAyB,QAAQ,4BACrC;AAAA,MACE,IAAI,OAAO,aAAa,QAAQ,QAAQ,OAAO,GAAG,QAAQ,MAAM;AAAA,IAClE,IACA;AAEN,QAAI;AAGJ,QAAI,QAAQ,2BAA2B;AACrC,OAAC,EAAE,0BAA0B,IAAI,MAAM,OACrC,gCACF;AAAA,IACF;AAEA,aAAS,gBAAgB,YAAoB,SAAiB;AAC5D,YAAM,UAAkC,CAAC;AACzC,YAAM,mBAAmB,MAAM,SAAS,EAAE,YAAY,KAAK,CAAC;AAC5D,YAAM,oBAAoB,qBAAqB,gBAAgB;AAE/D,UAAI,CAAC,QAAQ,uBAAuB;AAClC,gBAAQ,yBAAyB;AAAA,MACnC,OAAO;AACL,YAAI,CAAC,WAAW,SAAS,wBAAwB,GAAG;AAClD,kBAAQ,yBACN,8CAA8C,iBAAiB;AAAA,QACnE;AAEA,kBAAU,QAAQ,4BAA4B;AAC9C,gBAAQ,qBAAqB;AAAA,UAC3B;AAAA,UACA;AAAA,QACF;AAEA,gBAAQ,WAAW,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F;AAAA;AAAA;AACF;",
|
|
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.2.
|
|
5
|
+
"version": "1.2.2",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"duct-tape-compiler": "./lib/cli.js"
|