@graphitation/apollo-react-relay-duct-tape-compiler 1.2.1 → 1.2.3
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/compilerTransforms/utils.js +1 -1
- package/lib/compilerTransforms/utils.js.map +2 -2
- package/lib/compilerTransforms/utils.mjs +1 -1
- package/lib/compilerTransforms/utils.mjs.map +2 -2
- package/lib/formatModule.d.ts.map +1 -1
- package/lib/formatModule.js +35 -9
- package/lib/formatModule.js.map +2 -2
- package/lib/formatModule.mjs +35 -9
- package/lib/formatModule.mjs.map +2 -2
- package/package.json +1 -1
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 Wed, 16 Aug 2023 06:30:58 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.2.3
|
|
8
|
+
|
|
9
|
+
Wed, 16 Aug 2023 06:30:58 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- Various PeopleApp fixes (eloy.de.enige@gmail.com)
|
|
14
|
+
|
|
15
|
+
## 1.2.2
|
|
16
|
+
|
|
17
|
+
Tue, 25 Jul 2023 08:18:03 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- Re-export the right docs for a fragment (eloy.de.enige@gmail.com)
|
|
22
|
+
|
|
7
23
|
## 1.2.1
|
|
8
24
|
|
|
9
|
-
Sat, 22 Jul 2023 07:35:
|
|
25
|
+
Sat, 22 Jul 2023 07:35:09 GMT
|
|
10
26
|
|
|
11
27
|
### Patches
|
|
12
28
|
|
|
@@ -39,5 +39,5 @@ function implementsNodeInterface(context, fragmentDefinition) {
|
|
|
39
39
|
nodeType && schema.isInterface(nodeType),
|
|
40
40
|
"Expected schema to define a Node interface in order to support narrow observables."
|
|
41
41
|
);
|
|
42
|
-
return schema.
|
|
42
|
+
return schema.mayImplement(fragmentDefinition.type, nodeType);
|
|
43
43
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/compilerTransforms/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import invariant from \"invariant\";\nimport { CompilerContext, Fragment } from \"relay-compiler\";\n\nexport function implementsNodeInterface(\n context: CompilerContext,\n fragmentDefinition: Fragment,\n) {\n const schema = context.getSchema();\n const nodeType = schema.getTypeFromString(\"Node\");\n invariant(\n nodeType && schema.isInterface(nodeType),\n \"Expected schema to define a Node interface in order to support narrow observables.\",\n );\n return schema.
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AAGf,SAAS,wBACd,SACA,oBACA;AACA,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,WAAW,OAAO,kBAAkB,MAAM;AAChD,uBAAAA;AAAA,IACE,YAAY,OAAO,YAAY,QAAQ;AAAA,IACvC;AAAA,EACF;AACA,SAAO,OAAO,
|
|
4
|
+
"sourcesContent": ["import invariant from \"invariant\";\nimport { CompilerContext, Fragment } from \"relay-compiler\";\n\nexport function implementsNodeInterface(\n context: CompilerContext,\n fragmentDefinition: Fragment,\n) {\n const schema = context.getSchema();\n const nodeType = schema.getTypeFromString(\"Node\");\n invariant(\n nodeType && schema.isInterface(nodeType),\n \"Expected schema to define a Node interface in order to support narrow observables.\",\n );\n return schema.mayImplement(fragmentDefinition.type, nodeType);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AAGf,SAAS,wBACd,SACA,oBACA;AACA,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,WAAW,OAAO,kBAAkB,MAAM;AAChD,uBAAAA;AAAA,IACE,YAAY,OAAO,YAAY,QAAQ;AAAA,IACvC;AAAA,EACF;AACA,SAAO,OAAO,aAAa,mBAAmB,MAAM,QAAQ;AAC9D;",
|
|
6
6
|
"names": ["invariant"]
|
|
7
7
|
}
|
|
@@ -7,7 +7,7 @@ function implementsNodeInterface(context, fragmentDefinition) {
|
|
|
7
7
|
nodeType && schema.isInterface(nodeType),
|
|
8
8
|
"Expected schema to define a Node interface in order to support narrow observables."
|
|
9
9
|
);
|
|
10
|
-
return schema.
|
|
10
|
+
return schema.mayImplement(fragmentDefinition.type, nodeType);
|
|
11
11
|
}
|
|
12
12
|
export {
|
|
13
13
|
implementsNodeInterface
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/compilerTransforms/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import invariant from \"invariant\";\nimport { CompilerContext, Fragment } from \"relay-compiler\";\n\nexport function implementsNodeInterface(\n context: CompilerContext,\n fragmentDefinition: Fragment,\n) {\n const schema = context.getSchema();\n const nodeType = schema.getTypeFromString(\"Node\");\n invariant(\n nodeType && schema.isInterface(nodeType),\n \"Expected schema to define a Node interface in order to support narrow observables.\",\n );\n return schema.
|
|
5
|
-
"mappings": ";AAAA,OAAO,eAAe;AAGf,SAAS,wBACd,SACA,oBACA;AACA,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,WAAW,OAAO,kBAAkB,MAAM;AAChD;AAAA,IACE,YAAY,OAAO,YAAY,QAAQ;AAAA,IACvC;AAAA,EACF;AACA,SAAO,OAAO,
|
|
4
|
+
"sourcesContent": ["import invariant from \"invariant\";\nimport { CompilerContext, Fragment } from \"relay-compiler\";\n\nexport function implementsNodeInterface(\n context: CompilerContext,\n fragmentDefinition: Fragment,\n) {\n const schema = context.getSchema();\n const nodeType = schema.getTypeFromString(\"Node\");\n invariant(\n nodeType && schema.isInterface(nodeType),\n \"Expected schema to define a Node interface in order to support narrow observables.\",\n );\n return schema.mayImplement(fragmentDefinition.type, nodeType);\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,eAAe;AAGf,SAAS,wBACd,SACA,oBACA;AACA,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,WAAW,OAAO,kBAAkB,MAAM;AAChD;AAAA,IACE,YAAY,OAAO,YAAY,QAAQ;AAAA,IACvC;AAAA,EACF;AACA,SAAO,OAAO,aAAa,mBAAmB,MAAM,QAAQ;AAC9D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -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,CAwFvB"}
|
package/lib/formatModule.js
CHANGED
|
@@ -74,11 +74,11 @@ function formatModuleFactory(options) {
|
|
|
74
74
|
if (options.emitSupermassiveDocuments) {
|
|
75
75
|
({ addTypesToRequestDocument } = yield import("@graphitation/supermassive-ast"));
|
|
76
76
|
}
|
|
77
|
-
function generateExports(moduleName, docText) {
|
|
77
|
+
function generateExports(moduleName, docText, emitNarrowObservables) {
|
|
78
78
|
const exports = {};
|
|
79
79
|
const originalDocument = (0, import_graphql.parse)(docText, { noLocation: true });
|
|
80
80
|
const optimizedDocument = (0, import_optimize.optimizeDocumentNode)(originalDocument);
|
|
81
|
-
if (!
|
|
81
|
+
if (!emitNarrowObservables) {
|
|
82
82
|
exports.executionQueryDocument = optimizedDocument;
|
|
83
83
|
} else {
|
|
84
84
|
if (!moduleName.endsWith("WatchNodeQuery.graphql")) {
|
|
@@ -100,17 +100,19 @@ function formatModuleFactory(options) {
|
|
|
100
100
|
}
|
|
101
101
|
return exports;
|
|
102
102
|
}
|
|
103
|
-
return ({ docText, hash, moduleName, typeText }) => {
|
|
104
|
-
const exports = options.emitDocuments ? docText && generateExports(
|
|
103
|
+
return ({ docText, hash, moduleName, typeText, definition }) => {
|
|
104
|
+
const exports = options.emitDocuments ? docText && generateExports(
|
|
105
|
+
moduleName,
|
|
106
|
+
docText,
|
|
107
|
+
options.emitNarrowObservables && definition.kind === "Request" && definition.root.operation === "query"
|
|
108
|
+
) : null;
|
|
109
|
+
const reExportWatchNodeQuery = options.emitDocuments && definition.kind === "Fragment";
|
|
105
110
|
const components = [
|
|
106
111
|
typeText,
|
|
107
112
|
exports && options.emitQueryDebugComments && exports.executionQueryDocument && printDocumentComment(exports.executionQueryDocument),
|
|
108
113
|
exports && options.emitQueryDebugComments && exports.watchQueryDocument && printDocumentComment(exports.watchQueryDocument),
|
|
109
|
-
exports &&
|
|
110
|
-
|
|
111
|
-
)};
|
|
112
|
-
|
|
113
|
-
export default documents;`
|
|
114
|
+
exports && printExports(exports),
|
|
115
|
+
reExportWatchNodeQuery && printWatchNodeQueryReExport(definition)
|
|
114
116
|
].filter(Boolean);
|
|
115
117
|
return `/* tslint:disable */
|
|
116
118
|
/* eslint-disable */
|
|
@@ -121,3 +123,27 @@ ${components.join("\n\n")}`;
|
|
|
121
123
|
};
|
|
122
124
|
});
|
|
123
125
|
}
|
|
126
|
+
function printWatchNodeQueryReExport(definition) {
|
|
127
|
+
const refetchable = definition.directives.find(
|
|
128
|
+
(d) => d.name === "refetchable" && d.loc.kind === "Source"
|
|
129
|
+
) || definition.directives.find(
|
|
130
|
+
(d) => d.name === "refetchable" && d.loc.kind === "Generated"
|
|
131
|
+
);
|
|
132
|
+
if (!refetchable) {
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
const queryNameArg = refetchable.args[0];
|
|
136
|
+
(0, import_invariant.default)(
|
|
137
|
+
queryNameArg.name === "queryName" && queryNameArg.value.kind === "Literal",
|
|
138
|
+
"Expected a @refetchable(queryName:) argument"
|
|
139
|
+
);
|
|
140
|
+
return `import { documents } from "./${queryNameArg.value.value}.graphql";
|
|
141
|
+
export default documents;`;
|
|
142
|
+
}
|
|
143
|
+
function printExports(exports) {
|
|
144
|
+
return `export const documents: import("@graphitation/apollo-react-relay-duct-tape-compiler").CompiledArtefactModule = ${(0, import_dedupeJSONStringify.default)(
|
|
145
|
+
exports
|
|
146
|
+
)};
|
|
147
|
+
|
|
148
|
+
export default documents;`;
|
|
149
|
+
}
|
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
|
|
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 { 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(\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 (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 &&\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.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 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"],
|
|
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,SA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AA,QACjB;AAAA,QACA,WACE,QAAQ,0BACR,QAAQ,0BACR,qBAAqB,QAAQ,sBAAsB;AAAA,QACrD,WACE,QAAQ,0BACR,QAAQ,sBACR,qBAAqB,QAAQ,kBAAkB;AAAA,QACjD,WAAW,aAAa,OAAO;AAAA,QAC/B,0BAA0B,4BAA4B,UAAU;AAAA,MAClE,EAAE,OAAO,OAAO;AAEhB,aAAO;AAAA;AAAA;AAAA,EAGT,OAAO,MAAM;AAAA,IAAc;AAAA,EAC3B,WAAW,KAAK,MAAM;AAAA,IACtB;AAAA,EACF;AAAA;AAGA,SAAS,4BAA4B,YAAsB;AACzD,QAAM,cACJ,WAAW,WAAW;AAAA,IACpB,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,IAAI,SAAS;AAAA,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,uBAAAA;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,sHAAkH,2BAAAC;AAAA,IACvH;AAAA,EACF;AAAA;AAAA;AACF;",
|
|
6
6
|
"names": ["import_graphql", "invariant", "dedupeJSONStringify"]
|
|
7
7
|
}
|
package/lib/formatModule.mjs
CHANGED
|
@@ -43,11 +43,11 @@ function formatModuleFactory(options) {
|
|
|
43
43
|
if (options.emitSupermassiveDocuments) {
|
|
44
44
|
({ addTypesToRequestDocument } = yield import("@graphitation/supermassive-ast"));
|
|
45
45
|
}
|
|
46
|
-
function generateExports(moduleName, docText) {
|
|
46
|
+
function generateExports(moduleName, docText, emitNarrowObservables) {
|
|
47
47
|
const exports = {};
|
|
48
48
|
const originalDocument = parse(docText, { noLocation: true });
|
|
49
49
|
const optimizedDocument = optimizeDocumentNode(originalDocument);
|
|
50
|
-
if (!
|
|
50
|
+
if (!emitNarrowObservables) {
|
|
51
51
|
exports.executionQueryDocument = optimizedDocument;
|
|
52
52
|
} else {
|
|
53
53
|
if (!moduleName.endsWith("WatchNodeQuery.graphql")) {
|
|
@@ -69,17 +69,19 @@ function formatModuleFactory(options) {
|
|
|
69
69
|
}
|
|
70
70
|
return exports;
|
|
71
71
|
}
|
|
72
|
-
return ({ docText, hash, moduleName, typeText }) => {
|
|
73
|
-
const exports = options.emitDocuments ? docText && generateExports(
|
|
72
|
+
return ({ docText, hash, moduleName, typeText, definition }) => {
|
|
73
|
+
const exports = options.emitDocuments ? docText && generateExports(
|
|
74
|
+
moduleName,
|
|
75
|
+
docText,
|
|
76
|
+
options.emitNarrowObservables && definition.kind === "Request" && definition.root.operation === "query"
|
|
77
|
+
) : null;
|
|
78
|
+
const reExportWatchNodeQuery = options.emitDocuments && definition.kind === "Fragment";
|
|
74
79
|
const components = [
|
|
75
80
|
typeText,
|
|
76
81
|
exports && options.emitQueryDebugComments && exports.executionQueryDocument && printDocumentComment(exports.executionQueryDocument),
|
|
77
82
|
exports && options.emitQueryDebugComments && exports.watchQueryDocument && printDocumentComment(exports.watchQueryDocument),
|
|
78
|
-
exports &&
|
|
79
|
-
|
|
80
|
-
)};
|
|
81
|
-
|
|
82
|
-
export default documents;`
|
|
83
|
+
exports && printExports(exports),
|
|
84
|
+
reExportWatchNodeQuery && printWatchNodeQueryReExport(definition)
|
|
83
85
|
].filter(Boolean);
|
|
84
86
|
return `/* tslint:disable */
|
|
85
87
|
/* eslint-disable */
|
|
@@ -90,6 +92,30 @@ ${components.join("\n\n")}`;
|
|
|
90
92
|
};
|
|
91
93
|
});
|
|
92
94
|
}
|
|
95
|
+
function printWatchNodeQueryReExport(definition) {
|
|
96
|
+
const refetchable = definition.directives.find(
|
|
97
|
+
(d) => d.name === "refetchable" && d.loc.kind === "Source"
|
|
98
|
+
) || definition.directives.find(
|
|
99
|
+
(d) => d.name === "refetchable" && d.loc.kind === "Generated"
|
|
100
|
+
);
|
|
101
|
+
if (!refetchable) {
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
const queryNameArg = refetchable.args[0];
|
|
105
|
+
invariant(
|
|
106
|
+
queryNameArg.name === "queryName" && queryNameArg.value.kind === "Literal",
|
|
107
|
+
"Expected a @refetchable(queryName:) argument"
|
|
108
|
+
);
|
|
109
|
+
return `import { documents } from "./${queryNameArg.value.value}.graphql";
|
|
110
|
+
export default documents;`;
|
|
111
|
+
}
|
|
112
|
+
function printExports(exports) {
|
|
113
|
+
return `export const documents: import("@graphitation/apollo-react-relay-duct-tape-compiler").CompiledArtefactModule = ${dedupeJSONStringify(
|
|
114
|
+
exports
|
|
115
|
+
)};
|
|
116
|
+
|
|
117
|
+
export default documents;`;
|
|
118
|
+
}
|
|
93
119
|
export {
|
|
94
120
|
formatModuleFactory
|
|
95
121
|
};
|
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
|
|
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 { 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(\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 (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 &&\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.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 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"],
|
|
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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AAQ,0BACR,qBAAqB,QAAQ,sBAAsB;AAAA,QACrD,WACE,QAAQ,0BACR,QAAQ,sBACR,qBAAqB,QAAQ,kBAAkB;AAAA,QACjD,WAAW,aAAa,OAAO;AAAA,QAC/B,0BAA0B,4BAA4B,UAAU;AAAA,MAClE,EAAE,OAAO,OAAO;AAEhB,aAAO;AAAA;AAAA;AAAA,EAGT,OAAO,MAAM;AAAA,IAAc;AAAA,EAC3B,WAAW,KAAK,MAAM;AAAA,IACtB;AAAA,EACF;AAAA;AAGA,SAAS,4BAA4B,YAAsB;AACzD,QAAM,cACJ,WAAW,WAAW;AAAA,IACpB,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,IAAI,SAAS;AAAA,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;",
|
|
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.3",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"duct-tape-compiler": "./lib/cli.js"
|