@graphitation/apollo-react-relay-duct-tape-compiler 1.5.3 → 1.5.5
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 +20 -2
- package/lib/typeGenerator.d.ts +1 -1
- package/lib/typescriptTransforms/createImportDocumentsTransform.js +1 -2
- package/lib/typescriptTransforms/createImportDocumentsTransform.js.map +2 -2
- package/lib/typescriptTransforms/createImportDocumentsTransform.mjs +1 -2
- package/lib/typescriptTransforms/createImportDocumentsTransform.mjs.map +2 -2
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
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, 17 Oct 2024 12:43:59 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.5.5
|
|
8
|
+
|
|
9
|
+
Thu, 17 Oct 2024 12:43:59 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- bump dependecies (pavelglac@microsoft.com)
|
|
14
|
+
- Bump @graphitation/supermassive to v3.5.4
|
|
15
|
+
|
|
16
|
+
## 1.5.4
|
|
17
|
+
|
|
18
|
+
Mon, 14 Oct 2024 07:58:57 GMT
|
|
19
|
+
|
|
20
|
+
### Patches
|
|
21
|
+
|
|
22
|
+
- Bump TS version to 5.5 (pavelglac@microsoft.com)
|
|
23
|
+
- Bump @graphitation/supermassive to v3.5.3
|
|
24
|
+
|
|
7
25
|
## 1.5.3
|
|
8
26
|
|
|
9
|
-
Wed, 03 Jul 2024 17:33:
|
|
27
|
+
Wed, 03 Jul 2024 17:33:49 GMT
|
|
10
28
|
|
|
11
29
|
### Patches
|
|
12
30
|
|
package/lib/typeGenerator.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { TypeGenerator } from "relay-compiler/lib/language/RelayLanguagePluginInterface";
|
|
2
|
-
export declare function generateFactory(wrappedGenerate: TypeGenerator["generate"]): (schema: import("relay-compiler").Schema, node: import("relay-compiler").
|
|
2
|
+
export declare function generateFactory(wrappedGenerate: TypeGenerator["generate"]): (schema: import("relay-compiler").Schema, node: import("relay-compiler").Root | import("relay-compiler").Fragment, options: import("relay-compiler/lib/language/RelayLanguagePluginInterface").TypeGeneratorOptions) => string;
|
|
3
3
|
//# sourceMappingURL=typeGenerator.d.ts.map
|
|
@@ -64,7 +64,7 @@ function createImportDocumentsTransform() {
|
|
|
64
64
|
return ts.visitEachChild(node, visitor, context);
|
|
65
65
|
};
|
|
66
66
|
return (sourceFile) => {
|
|
67
|
-
const outputSourceFile = ts.
|
|
67
|
+
const outputSourceFile = ts.visitEachChild(sourceFile, visitor, context);
|
|
68
68
|
return ts.factory.updateSourceFile(outputSourceFile, [
|
|
69
69
|
...imports,
|
|
70
70
|
...outputSourceFile.statements
|
|
@@ -131,7 +131,6 @@ function createImportStatement(moduleKind, namespaceName, modulePath) {
|
|
|
131
131
|
);
|
|
132
132
|
} else {
|
|
133
133
|
return ts.factory.createImportDeclaration(
|
|
134
|
-
void 0,
|
|
135
134
|
void 0,
|
|
136
135
|
ts.factory.createImportClause(
|
|
137
136
|
false,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/typescriptTransforms/createImportDocumentsTransform.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * TODO:\n * - Don't hardcode identifiers but check if they're aliased from their imports.\n * - Support mutations and subscriptions\n * - Properly emit errors from transformer, is invariant ok?\n */\n\nimport invariant from \"invariant\";\nimport * as ts from \"typescript\";\nimport {\n FragmentDefinitionNode,\n parse as parseGraphQL,\n StringValueNode,\n} from \"graphql\";\nimport * as path from \"path\";\nimport * as fs from \"fs\";\n\nconst PREFIX = \"__graphitation_\";\nconst QUERIES_NAMESPACE = \"generatedQueries\";\n\nexport function createImportDocumentsTransform(): ts.TransformerFactory<ts.SourceFile> {\n return (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n const imports: ts.Statement[] = [];\n\n const visitor: ts.Visitor = (node: ts.Node): ts.VisitResult<ts.Node> => {\n if (\n ts.isTaggedTemplateExpression(node) &&\n ts.isIdentifier(node.tag) &&\n node.tag.escapedText === \"graphql\"\n ) {\n const documentNodes = createGraphQLDocumentNodes(\n node,\n context.getCompilerOptions().module,\n );\n if (documentNodes) {\n const [modulePath, importStatement, replacementNode] = documentNodes;\n // Because we currently only emit new watch queries for fragments\n // on Node types, we cannot just assume the artefact exists for\n // every fragment definition. So check if it exists before emitting\n // the import.\n //\n // TODO: This file checking should not exist and is probably not\n // performant.\n const artefactFile =\n path.join(\n path.dirname(node.getSourceFile().fileName),\n modulePath.text,\n ) + \".ts\";\n const emitImport = fs.existsSync(artefactFile);\n if (emitImport) {\n imports.push(importStatement);\n return replacementNode;\n }\n }\n }\n return ts.visitEachChild(node, visitor, context);\n };\n\n return (sourceFile: ts.SourceFile) => {\n const outputSourceFile = ts.
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,uBAAsB;AACtB,SAAoB;AACpB,qBAIO;AACP,WAAsB;AACtB,SAAoB;AAEpB,MAAM,SAAS;AACf,MAAM,oBAAoB;AAEnB,SAAS,iCAAuE;AACrF,SAAO,CAAC,YAAqE;AAC3E,UAAM,UAA0B,CAAC;AAEjC,UAAM,UAAsB,CAAC,SAA2C;AACtE,UACE,GAAG,2BAA2B,IAAI,KAClC,GAAG,aAAa,KAAK,GAAG,KACxB,KAAK,IAAI,gBAAgB,WACzB;AACA,cAAM,gBAAgB;AAAA,UACpB;AAAA,UACA,QAAQ,mBAAmB,EAAE;AAAA,QAC/B;AACA,YAAI,eAAe;AACjB,gBAAM,CAAC,YAAY,iBAAiB,eAAe,IAAI;AAQvD,gBAAM,eACJ,KAAK;AAAA,YACH,KAAK,QAAQ,KAAK,cAAc,EAAE,QAAQ;AAAA,YAC1C,WAAW;AAAA,UACb,IAAI;AACN,gBAAM,aAAa,GAAG,WAAW,YAAY;AAC7C,cAAI,YAAY;AACd,oBAAQ,KAAK,eAAe;AAC5B,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AACA,aAAO,GAAG,eAAe,MAAM,SAAS,OAAO;AAAA,IACjD;AAEA,WAAO,CAAC,eAA8B;AACpC,YAAM,mBAAmB,GAAG,
|
|
4
|
+
"sourcesContent": ["/**\n * TODO:\n * - Don't hardcode identifiers but check if they're aliased from their imports.\n * - Support mutations and subscriptions\n * - Properly emit errors from transformer, is invariant ok?\n */\n\nimport invariant from \"invariant\";\nimport * as ts from \"typescript\";\nimport {\n FragmentDefinitionNode,\n parse as parseGraphQL,\n StringValueNode,\n} from \"graphql\";\nimport * as path from \"path\";\nimport * as fs from \"fs\";\n\nconst PREFIX = \"__graphitation_\";\nconst QUERIES_NAMESPACE = \"generatedQueries\";\n\nexport function createImportDocumentsTransform(): ts.TransformerFactory<ts.SourceFile> {\n return (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n const imports: ts.Statement[] = [];\n\n const visitor: ts.Visitor = (node: ts.Node): ts.VisitResult<ts.Node> => {\n if (\n ts.isTaggedTemplateExpression(node) &&\n ts.isIdentifier(node.tag) &&\n node.tag.escapedText === \"graphql\"\n ) {\n const documentNodes = createGraphQLDocumentNodes(\n node,\n context.getCompilerOptions().module,\n );\n if (documentNodes) {\n const [modulePath, importStatement, replacementNode] = documentNodes;\n // Because we currently only emit new watch queries for fragments\n // on Node types, we cannot just assume the artefact exists for\n // every fragment definition. So check if it exists before emitting\n // the import.\n //\n // TODO: This file checking should not exist and is probably not\n // performant.\n const artefactFile =\n path.join(\n path.dirname(node.getSourceFile().fileName),\n modulePath.text,\n ) + \".ts\";\n const emitImport = fs.existsSync(artefactFile);\n if (emitImport) {\n imports.push(importStatement);\n return replacementNode;\n }\n }\n }\n return ts.visitEachChild(node, visitor, context);\n };\n\n return (sourceFile: ts.SourceFile) => {\n const outputSourceFile = ts.visitEachChild(sourceFile, visitor, context);\n return ts.factory.updateSourceFile(outputSourceFile, [\n ...imports,\n ...outputSourceFile.statements,\n ]);\n };\n };\n}\n\n// This is for ts-jest\nexport { createImportDocumentsTransform as factory };\n\nfunction createGraphQLDocumentNodes(\n graphqlTagTemplateNode: ts.TaggedTemplateExpression,\n moduleKind: ts.ModuleKind = ts.ModuleKind.ES2015,\n):\n | [\n modulePath: ts.StringLiteral,\n importStatement: ts.Statement,\n importReference: ts.Identifier,\n ]\n | undefined {\n const graphqlDoc = ts.isNoSubstitutionTemplateLiteral(\n graphqlTagTemplateNode.template,\n )\n ? graphqlTagTemplateNode.template.rawText\n : graphqlTagTemplateNode.template.head.rawText;\n invariant(graphqlDoc, \"Expected a GraphQL document\");\n const graphqlAST = parseGraphQL(graphqlDoc);\n const definitionNode = graphqlAST.definitions[0];\n if (definitionNode.kind === \"OperationDefinition\") {\n if (definitionNode.operation !== \"query\") {\n return undefined;\n }\n const operationName = definitionNode.name?.value;\n invariant(operationName, \"Operations are required to have a name\");\n const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${operationName}`;\n const modulePath = createModulePathNode(operationName);\n return [\n modulePath,\n createImportStatement(moduleKind, namespaceName, modulePath),\n ts.factory.createIdentifier(namespaceName),\n ];\n } else if (definitionNode.kind === \"FragmentDefinition\") {\n const queryName = getQueryName(definitionNode);\n const fragmentName = definitionNode.name.value;\n const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${fragmentName}`;\n const modulePath = createModulePathNode(queryName);\n return [\n modulePath,\n createImportStatement(moduleKind, namespaceName, modulePath),\n ts.factory.createIdentifier(namespaceName),\n ];\n }\n invariant(false, `Unhandled GraphQL definition type: ${definitionNode.kind}`);\n}\n\nfunction createModulePathNode(baseName: string) {\n return ts.factory.createStringLiteral(`./__generated__/${baseName}.graphql`);\n}\n\nfunction createImportStatement(\n moduleKind: ts.ModuleKind,\n namespaceName: string,\n modulePath: ts.StringLiteral,\n): ts.Statement {\n if (moduleKind === ts.ModuleKind.CommonJS) {\n return ts.factory.createVariableStatement(\n undefined,\n ts.factory.createVariableDeclarationList([\n ts.factory.createVariableDeclaration(\n namespaceName,\n undefined,\n undefined,\n ts.factory.createPropertyAccessExpression(\n ts.factory.createCallExpression(\n ts.factory.createIdentifier(\"require\"),\n [],\n [modulePath],\n ),\n ts.factory.createIdentifier(\"documents\"),\n ),\n ),\n ]),\n );\n } else {\n return ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(\n false,\n undefined,\n ts.factory.createNamedImports([\n ts.factory.createImportSpecifier(\n false,\n ts.factory.createIdentifier(\"documents\"),\n ts.factory.createIdentifier(namespaceName),\n ),\n ]),\n ),\n modulePath,\n );\n }\n}\n\nfunction getQueryName(definitionNode: FragmentDefinitionNode) {\n const refetchableQueryNameNode = definitionNode.directives\n ?.find((directive) => directive.name.value === \"refetchable\")\n ?.arguments?.find((arg) => arg.name.value === \"queryName\")?.value as\n | StringValueNode\n | undefined;\n if (refetchableQueryNameNode) {\n return refetchableQueryNameNode.value;\n } else {\n const fragmentName = definitionNode.name.value;\n const fragmentBaseName = fragmentName.replace(/Fragment$/, \"\");\n return `${fragmentBaseName}WatchNodeQuery`;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,uBAAsB;AACtB,SAAoB;AACpB,qBAIO;AACP,WAAsB;AACtB,SAAoB;AAEpB,MAAM,SAAS;AACf,MAAM,oBAAoB;AAEnB,SAAS,iCAAuE;AACrF,SAAO,CAAC,YAAqE;AAC3E,UAAM,UAA0B,CAAC;AAEjC,UAAM,UAAsB,CAAC,SAA2C;AACtE,UACE,GAAG,2BAA2B,IAAI,KAClC,GAAG,aAAa,KAAK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A,IACF;AAAA,EACF;AACF;AAEA,SAAS,aAAa,gBAAwC;AAnK9D;AAoKE,QAAM,4BAA2B,sCAAe,eAAf,mBAC7B,KAAK,CAAC,cAAc,UAAU,KAAK,UAAU,mBADhB,mBAE7B,cAF6B,mBAElB,KAAK,CAAC,QAAQ,IAAI,KAAK,UAAU,iBAFf,mBAE6B;AAG9D,MAAI,0BAA0B;AAC5B,WAAO,yBAAyB;AAAA,EAClC,OAAO;AACL,UAAM,eAAe,eAAe,KAAK;AACzC,UAAM,mBAAmB,aAAa,QAAQ,aAAa,EAAE;AAC7D,WAAO,GAAG;AAAA,EACZ;AACF;",
|
|
6
6
|
"names": ["invariant", "parseGraphQL"]
|
|
7
7
|
}
|
|
@@ -33,7 +33,7 @@ function createImportDocumentsTransform() {
|
|
|
33
33
|
return ts.visitEachChild(node, visitor, context);
|
|
34
34
|
};
|
|
35
35
|
return (sourceFile) => {
|
|
36
|
-
const outputSourceFile = ts.
|
|
36
|
+
const outputSourceFile = ts.visitEachChild(sourceFile, visitor, context);
|
|
37
37
|
return ts.factory.updateSourceFile(outputSourceFile, [
|
|
38
38
|
...imports,
|
|
39
39
|
...outputSourceFile.statements
|
|
@@ -100,7 +100,6 @@ function createImportStatement(moduleKind, namespaceName, modulePath) {
|
|
|
100
100
|
);
|
|
101
101
|
} else {
|
|
102
102
|
return ts.factory.createImportDeclaration(
|
|
103
|
-
void 0,
|
|
104
103
|
void 0,
|
|
105
104
|
ts.factory.createImportClause(
|
|
106
105
|
false,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/typescriptTransforms/createImportDocumentsTransform.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * TODO:\n * - Don't hardcode identifiers but check if they're aliased from their imports.\n * - Support mutations and subscriptions\n * - Properly emit errors from transformer, is invariant ok?\n */\n\nimport invariant from \"invariant\";\nimport * as ts from \"typescript\";\nimport {\n FragmentDefinitionNode,\n parse as parseGraphQL,\n StringValueNode,\n} from \"graphql\";\nimport * as path from \"path\";\nimport * as fs from \"fs\";\n\nconst PREFIX = \"__graphitation_\";\nconst QUERIES_NAMESPACE = \"generatedQueries\";\n\nexport function createImportDocumentsTransform(): ts.TransformerFactory<ts.SourceFile> {\n return (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n const imports: ts.Statement[] = [];\n\n const visitor: ts.Visitor = (node: ts.Node): ts.VisitResult<ts.Node> => {\n if (\n ts.isTaggedTemplateExpression(node) &&\n ts.isIdentifier(node.tag) &&\n node.tag.escapedText === \"graphql\"\n ) {\n const documentNodes = createGraphQLDocumentNodes(\n node,\n context.getCompilerOptions().module,\n );\n if (documentNodes) {\n const [modulePath, importStatement, replacementNode] = documentNodes;\n // Because we currently only emit new watch queries for fragments\n // on Node types, we cannot just assume the artefact exists for\n // every fragment definition. So check if it exists before emitting\n // the import.\n //\n // TODO: This file checking should not exist and is probably not\n // performant.\n const artefactFile =\n path.join(\n path.dirname(node.getSourceFile().fileName),\n modulePath.text,\n ) + \".ts\";\n const emitImport = fs.existsSync(artefactFile);\n if (emitImport) {\n imports.push(importStatement);\n return replacementNode;\n }\n }\n }\n return ts.visitEachChild(node, visitor, context);\n };\n\n return (sourceFile: ts.SourceFile) => {\n const outputSourceFile = ts.
|
|
5
|
-
"mappings": ";AAOA,OAAO,eAAe;AACtB,YAAY,QAAQ;AACpB;AAAA,EAEE,SAAS;AAAA,OAEJ;AACP,YAAY,UAAU;AACtB,YAAY,QAAQ;AAEpB,IAAM,SAAS;AACf,IAAM,oBAAoB;AAEnB,SAAS,iCAAuE;AACrF,SAAO,CAAC,YAAqE;AAC3E,UAAM,UAA0B,CAAC;AAEjC,UAAM,UAAsB,CAAC,SAA2C;AACtE,UACK,8BAA2B,IAAI,KAC/B,gBAAa,KAAK,GAAG,KACxB,KAAK,IAAI,gBAAgB,WACzB;AACA,cAAM,gBAAgB;AAAA,UACpB;AAAA,UACA,QAAQ,mBAAmB,EAAE;AAAA,QAC/B;AACA,YAAI,eAAe;AACjB,gBAAM,CAAC,YAAY,iBAAiB,eAAe,IAAI;AAQvD,gBAAM,eACC;AAAA,YACE,aAAQ,KAAK,cAAc,EAAE,QAAQ;AAAA,YAC1C,WAAW;AAAA,UACb,IAAI;AACN,gBAAM,aAAgB,cAAW,YAAY;AAC7C,cAAI,YAAY;AACd,oBAAQ,KAAK,eAAe;AAC5B,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AACA,aAAU,kBAAe,MAAM,SAAS,OAAO;AAAA,IACjD;AAEA,WAAO,CAAC,eAA8B;AACpC,YAAM,mBAAsB,
|
|
4
|
+
"sourcesContent": ["/**\n * TODO:\n * - Don't hardcode identifiers but check if they're aliased from their imports.\n * - Support mutations and subscriptions\n * - Properly emit errors from transformer, is invariant ok?\n */\n\nimport invariant from \"invariant\";\nimport * as ts from \"typescript\";\nimport {\n FragmentDefinitionNode,\n parse as parseGraphQL,\n StringValueNode,\n} from \"graphql\";\nimport * as path from \"path\";\nimport * as fs from \"fs\";\n\nconst PREFIX = \"__graphitation_\";\nconst QUERIES_NAMESPACE = \"generatedQueries\";\n\nexport function createImportDocumentsTransform(): ts.TransformerFactory<ts.SourceFile> {\n return (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n const imports: ts.Statement[] = [];\n\n const visitor: ts.Visitor = (node: ts.Node): ts.VisitResult<ts.Node> => {\n if (\n ts.isTaggedTemplateExpression(node) &&\n ts.isIdentifier(node.tag) &&\n node.tag.escapedText === \"graphql\"\n ) {\n const documentNodes = createGraphQLDocumentNodes(\n node,\n context.getCompilerOptions().module,\n );\n if (documentNodes) {\n const [modulePath, importStatement, replacementNode] = documentNodes;\n // Because we currently only emit new watch queries for fragments\n // on Node types, we cannot just assume the artefact exists for\n // every fragment definition. So check if it exists before emitting\n // the import.\n //\n // TODO: This file checking should not exist and is probably not\n // performant.\n const artefactFile =\n path.join(\n path.dirname(node.getSourceFile().fileName),\n modulePath.text,\n ) + \".ts\";\n const emitImport = fs.existsSync(artefactFile);\n if (emitImport) {\n imports.push(importStatement);\n return replacementNode;\n }\n }\n }\n return ts.visitEachChild(node, visitor, context);\n };\n\n return (sourceFile: ts.SourceFile) => {\n const outputSourceFile = ts.visitEachChild(sourceFile, visitor, context);\n return ts.factory.updateSourceFile(outputSourceFile, [\n ...imports,\n ...outputSourceFile.statements,\n ]);\n };\n };\n}\n\n// This is for ts-jest\nexport { createImportDocumentsTransform as factory };\n\nfunction createGraphQLDocumentNodes(\n graphqlTagTemplateNode: ts.TaggedTemplateExpression,\n moduleKind: ts.ModuleKind = ts.ModuleKind.ES2015,\n):\n | [\n modulePath: ts.StringLiteral,\n importStatement: ts.Statement,\n importReference: ts.Identifier,\n ]\n | undefined {\n const graphqlDoc = ts.isNoSubstitutionTemplateLiteral(\n graphqlTagTemplateNode.template,\n )\n ? graphqlTagTemplateNode.template.rawText\n : graphqlTagTemplateNode.template.head.rawText;\n invariant(graphqlDoc, \"Expected a GraphQL document\");\n const graphqlAST = parseGraphQL(graphqlDoc);\n const definitionNode = graphqlAST.definitions[0];\n if (definitionNode.kind === \"OperationDefinition\") {\n if (definitionNode.operation !== \"query\") {\n return undefined;\n }\n const operationName = definitionNode.name?.value;\n invariant(operationName, \"Operations are required to have a name\");\n const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${operationName}`;\n const modulePath = createModulePathNode(operationName);\n return [\n modulePath,\n createImportStatement(moduleKind, namespaceName, modulePath),\n ts.factory.createIdentifier(namespaceName),\n ];\n } else if (definitionNode.kind === \"FragmentDefinition\") {\n const queryName = getQueryName(definitionNode);\n const fragmentName = definitionNode.name.value;\n const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${fragmentName}`;\n const modulePath = createModulePathNode(queryName);\n return [\n modulePath,\n createImportStatement(moduleKind, namespaceName, modulePath),\n ts.factory.createIdentifier(namespaceName),\n ];\n }\n invariant(false, `Unhandled GraphQL definition type: ${definitionNode.kind}`);\n}\n\nfunction createModulePathNode(baseName: string) {\n return ts.factory.createStringLiteral(`./__generated__/${baseName}.graphql`);\n}\n\nfunction createImportStatement(\n moduleKind: ts.ModuleKind,\n namespaceName: string,\n modulePath: ts.StringLiteral,\n): ts.Statement {\n if (moduleKind === ts.ModuleKind.CommonJS) {\n return ts.factory.createVariableStatement(\n undefined,\n ts.factory.createVariableDeclarationList([\n ts.factory.createVariableDeclaration(\n namespaceName,\n undefined,\n undefined,\n ts.factory.createPropertyAccessExpression(\n ts.factory.createCallExpression(\n ts.factory.createIdentifier(\"require\"),\n [],\n [modulePath],\n ),\n ts.factory.createIdentifier(\"documents\"),\n ),\n ),\n ]),\n );\n } else {\n return ts.factory.createImportDeclaration(\n undefined,\n ts.factory.createImportClause(\n false,\n undefined,\n ts.factory.createNamedImports([\n ts.factory.createImportSpecifier(\n false,\n ts.factory.createIdentifier(\"documents\"),\n ts.factory.createIdentifier(namespaceName),\n ),\n ]),\n ),\n modulePath,\n );\n }\n}\n\nfunction getQueryName(definitionNode: FragmentDefinitionNode) {\n const refetchableQueryNameNode = definitionNode.directives\n ?.find((directive) => directive.name.value === \"refetchable\")\n ?.arguments?.find((arg) => arg.name.value === \"queryName\")?.value as\n | StringValueNode\n | undefined;\n if (refetchableQueryNameNode) {\n return refetchableQueryNameNode.value;\n } else {\n const fragmentName = definitionNode.name.value;\n const fragmentBaseName = fragmentName.replace(/Fragment$/, \"\");\n return `${fragmentBaseName}WatchNodeQuery`;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAOA,OAAO,eAAe;AACtB,YAAY,QAAQ;AACpB;AAAA,EAEE,SAAS;AAAA,OAEJ;AACP,YAAY,UAAU;AACtB,YAAY,QAAQ;AAEpB,IAAM,SAAS;AACf,IAAM,oBAAoB;AAEnB,SAAS,iCAAuE;AACrF,SAAO,CAAC,YAAqE;AAC3E,UAAM,UAA0B,CAAC;AAEjC,UAAM,UAAsB,CAAC,SAA2C;AACtE,UACK,8BAA2B,IAAI,KAC/B,gBAAa,KAAK,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,IAAI,KAAK,UAAU,iBAFf,mBAE6B;AAG9D,MAAI,0BAA0B;AAC5B,WAAO,yBAAyB;AAAA,EAClC,OAAO;AACL,UAAM,eAAe,eAAe,KAAK;AACzC,UAAM,mBAAmB,aAAa,QAAQ,aAAa,EAAE;AAC7D,WAAO,GAAG;AAAA,EACZ;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.5.
|
|
5
|
+
"version": "1.5.5",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"duct-tape-compiler": "./lib/cli.js"
|
|
@@ -38,19 +38,19 @@
|
|
|
38
38
|
"relay-test-utils": "^12.0.0",
|
|
39
39
|
"relay-test-utils-internal": "^12.0.0",
|
|
40
40
|
"ts-node": "^10.4.0",
|
|
41
|
-
"typescript": "^
|
|
41
|
+
"typescript": "^5.5.3",
|
|
42
42
|
"@types/yargs": "^17.0.13"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"graphql": "^15.0.0",
|
|
46
|
-
"@graphitation/supermassive": "^3.5.
|
|
47
|
-
"typescript": "^
|
|
46
|
+
"@graphitation/supermassive": "^3.5.4",
|
|
47
|
+
"typescript": "^5.5.3"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"types": "./lib/index.d.ts",
|
|
53
52
|
"module": "./lib/index.mjs",
|
|
53
|
+
"types": "./lib/index.d.ts",
|
|
54
54
|
"exports": {
|
|
55
55
|
".": {
|
|
56
56
|
"import": "./lib/index.mjs",
|