@trackunit/react-graphql-tools 1.3.2 → 1.3.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
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## 1.3.4 (2025-02-24)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- **docs:** Updating url to target new location ([7c3ec8344af](https://github.com/Trackunit/manager/commit/7c3ec8344af))
|
|
6
|
+
- **docs:** Updating url to target new template location ([562d45cdfb0](https://github.com/Trackunit/manager/commit/562d45cdfb0))
|
|
7
|
+
|
|
8
|
+
### ❤️ Thank You
|
|
9
|
+
|
|
10
|
+
- Noah Jensen @craftutopia
|
|
11
|
+
|
|
12
|
+
## 1.3.3 (2025-02-21)
|
|
13
|
+
|
|
14
|
+
This was a version bump only for react-graphql-tools to align it with other projects, there were no code changes.
|
|
15
|
+
|
|
1
16
|
## 1.3.2 (2025-02-21)
|
|
2
17
|
|
|
3
18
|
This was a version bump only for react-graphql-tools to align it with other projects, there were no code changes.
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSourceFile = exports.convertEnumToConstObject = exports.getPreservedTypes = exports.isFragment = exports.isMutationVariables = exports.isMutation = exports.isQueryVariables = exports.isQuery = void 0;
|
|
3
|
+
exports.createSourceFile = exports.convertEnumToConstObject = exports.getPreservedTypes = exports.isFragment = exports.isSubscriptionVariables = exports.isSubscription = exports.isMutationVariables = exports.isMutation = exports.isQueryVariables = exports.isQuery = void 0;
|
|
4
4
|
const ts_morph_1 = require("ts-morph");
|
|
5
5
|
/**
|
|
6
6
|
* Check if the name is a *Query
|
|
7
7
|
*/
|
|
8
|
-
const isQuery = (name) => {
|
|
9
|
-
return
|
|
8
|
+
const isQuery = ({ typeLiteralText, name }) => {
|
|
9
|
+
return typeLiteralText === "Query" && name !== "Query";
|
|
10
10
|
};
|
|
11
11
|
exports.isQuery = isQuery;
|
|
12
12
|
/**
|
|
@@ -19,8 +19,8 @@ exports.isQueryVariables = isQueryVariables;
|
|
|
19
19
|
/**
|
|
20
20
|
* Check if the name is a Mutation
|
|
21
21
|
*/
|
|
22
|
-
const isMutation = (name) => {
|
|
23
|
-
return
|
|
22
|
+
const isMutation = ({ typeLiteralText, name }) => {
|
|
23
|
+
return typeLiteralText === "Mutation" && name !== "Mutation";
|
|
24
24
|
};
|
|
25
25
|
exports.isMutation = isMutation;
|
|
26
26
|
/**
|
|
@@ -30,6 +30,20 @@ const isMutationVariables = (name) => {
|
|
|
30
30
|
return name.endsWith("MutationVariables");
|
|
31
31
|
};
|
|
32
32
|
exports.isMutationVariables = isMutationVariables;
|
|
33
|
+
/**
|
|
34
|
+
* Check if the name is a Subscription
|
|
35
|
+
*/
|
|
36
|
+
const isSubscription = ({ typeLiteralText, name }) => {
|
|
37
|
+
return typeLiteralText === "Subscription" && name !== "Subscription";
|
|
38
|
+
};
|
|
39
|
+
exports.isSubscription = isSubscription;
|
|
40
|
+
/**
|
|
41
|
+
* Check if the name is a *SubscriptionVariables
|
|
42
|
+
*/
|
|
43
|
+
const isSubscriptionVariables = (name) => {
|
|
44
|
+
return name.endsWith("SubscriptionVariables");
|
|
45
|
+
};
|
|
46
|
+
exports.isSubscriptionVariables = isSubscriptionVariables;
|
|
33
47
|
/**
|
|
34
48
|
* Check if the name is a *Fragment and not *_Fragment
|
|
35
49
|
*/
|
|
@@ -67,11 +81,23 @@ const getPreservedTypes = (sourceFile, isVerbose) => {
|
|
|
67
81
|
const queryMutationListToProcess = [];
|
|
68
82
|
typeAliases.forEach(typeAlias => {
|
|
69
83
|
const name = typeAlias.getName();
|
|
70
|
-
|
|
84
|
+
// Get the type literal node that contains the properties
|
|
85
|
+
const typeLiteral = typeAlias.getTypeNode()?.asKind(ts_morph_1.SyntaxKind.TypeLiteral);
|
|
86
|
+
let typeLiteralText = null;
|
|
87
|
+
if (typeLiteral) {
|
|
88
|
+
// Find the __typename property
|
|
89
|
+
const typenameProperty = typeLiteral.getProperties().find(prop => prop.getName() === "__typename");
|
|
90
|
+
if (typenameProperty) {
|
|
91
|
+
typeLiteralText = typenameProperty.getType().getText().replaceAll('"', "");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if ((0, exports.isQueryVariables)(name) || (0, exports.isMutationVariables)(name) || (0, exports.isSubscriptionVariables)(name) || (0, exports.isFragment)(name)) {
|
|
71
95
|
variablesListToProcess.push(typeAlias);
|
|
72
96
|
queryAndMutations.push(typeAlias);
|
|
73
97
|
}
|
|
74
|
-
else if ((0, exports.isQuery)(
|
|
98
|
+
else if ((0, exports.isQuery)({ typeLiteralText, name }) ||
|
|
99
|
+
(0, exports.isMutation)({ typeLiteralText, name }) ||
|
|
100
|
+
(0, exports.isSubscription)({ typeLiteralText, name })) {
|
|
75
101
|
queryMutationListToProcess.push(typeAlias);
|
|
76
102
|
queryAndMutations.push(typeAlias);
|
|
77
103
|
}
|
|
@@ -98,29 +124,27 @@ const getPreservedTypes = (sourceFile, isVerbose) => {
|
|
|
98
124
|
exports.getPreservedTypes = getPreservedTypes;
|
|
99
125
|
const preserveTypes = (node, preservedTypes, sourceFile, isVerbose) => {
|
|
100
126
|
const typeReferences = [];
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
preserveTypes(foundTypeAlias, preservedTypes, sourceFile, isVerbose);
|
|
119
|
-
}
|
|
127
|
+
node.forEachDescendant(descendant => {
|
|
128
|
+
if (descendant.getKind() === ts_morph_1.SyntaxKind.TypeReference &&
|
|
129
|
+
!descendant.getText().startsWith("Scalars") &&
|
|
130
|
+
!descendant.getText().startsWith("Maybe<") &&
|
|
131
|
+
!descendant.getText().startsWith("InputMaybe<") &&
|
|
132
|
+
!descendant.getText().startsWith("Array<") &&
|
|
133
|
+
!descendant.getText().startsWith("Exact<") &&
|
|
134
|
+
!descendant.getText().includes("__typename")) {
|
|
135
|
+
if (isVerbose) {
|
|
136
|
+
// eslint-disable-next-line no-console
|
|
137
|
+
console.log("ADDING", getFullPathUpOfNode(descendant), ":", descendant.getText(), descendant.getKindName());
|
|
138
|
+
}
|
|
139
|
+
if (!preservedTypes.includes(descendant.getText())) {
|
|
140
|
+
const foundTypeAlias = sourceFile.getTypeAlias(descendant.getText());
|
|
141
|
+
preservedTypes.push(descendant.getText());
|
|
142
|
+
if (foundTypeAlias) {
|
|
143
|
+
preserveTypes(foundTypeAlias, preservedTypes, sourceFile, isVerbose);
|
|
120
144
|
}
|
|
121
145
|
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
124
148
|
return typeReferences;
|
|
125
149
|
};
|
|
126
150
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/utils.ts"],"names":[],"mappings":";;;AAAA,uCAAwG;AAExG;;GAEG;AACI,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE;IACtC,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;AAChE,CAAC,CAAC;AAFW,QAAA,OAAO,WAElB;AACF;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,EAAE;IAC/C,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACzC,CAAC,CAAC;AAFW,QAAA,gBAAgB,oBAE3B;AAEF;;GAEG;AACI,MAAM,UAAU,GAAG,CAAC,IAA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B,CAAC,CAAC,CAAC;IAEH,MAAM,oBAAoB,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5E,MAAM,eAAe,GAAG,gBAAgB,oBAAoB,WAAW,UAAU,CAAC,IAAI,CACpF,OAAO,CACR,+BAA+B,QAAQ,aAAa,oBAAoB,iBAAiB,oBAAoB,IAAI,CAAC;IAEnH,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAhBW,QAAA,wBAAwB,4BAgBnC;AAEF;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAC,WAAmB,EAAE,EAAE;IACtD,MAAM,OAAO,GAAG,IAAI,kBAAO,CAAC;QAC1B,eAAe,EAAE;YACf,cAAc,EAAE,IAAI;YACpB,kBAAkB,EAAE,IAAI;SACzB;KACF,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AACzD,CAAC,CAAC;AATW,QAAA,gBAAgB,oBAS3B","sourcesContent":["import { EnumDeclaration, Node, Project, SourceFile, SyntaxKind, TypeAliasDeclaration } from \"ts-morph\";\n\n/**\n * Check if the name is a *Query\n */\nexport const isQuery = (name: string) => {\n return name.endsWith(\"Query\") && name.length > \"Query\".length;\n};\n/**\n * Check if the name is a *QueryVariables\n */\nexport const isQueryVariables = (name: string) => {\n return name.endsWith(\"QueryVariables\");\n};\n\n/**\n * Check if the name is a Mutation\n */\nexport const isMutation = (name: string) => {\n return name.endsWith(\"Mutation\") && name.length > \"Mutation\".length;\n};\n\n/**\n * Check if the name is a *QueryVariables\n */\nexport const isMutationVariables = (name: string) => {\n return name.endsWith(\"MutationVariables\");\n};\n\n/**\n * Check if the name is a *Fragment and not *_Fragment\n */\nexport const isFragment = (name: string) => {\n return name.endsWith(\"Fragment\") && !name.endsWith(\"_Fragment\");\n};\n\n/**\n * Debug where you are in the tree\n */\nconst getFullPathUpOfNode = (node: Node) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let currentNode: any | undefined = node;\n const paths = [];\n\n while (currentNode) {\n // You can customize what details to include for each node (e.g., kind, text)\n let name = currentNode.getName ? currentNode.getName() : currentNode.getKindName();\n if (node.getKind() === SyntaxKind.TypeLiteral) {\n const typeLiteral = node.asKindOrThrow(SyntaxKind.TypeLiteral);\n name = typeLiteral.getText();\n }\n\n paths.unshift(`${name}`);\n currentNode = currentNode.getParent();\n }\n\n return paths.join(\">>\");\n};\n\n/**\n * Get the types that should be preserved\n */\nexport const getPreservedTypes = (\n sourceFile: SourceFile,\n isVerbose?: boolean\n): {\n preservedTypes: string[];\n queryAndMutations: Node[];\n} => {\n const typeAliases = sourceFile.getTypeAliases();\n const queryAndMutations: Node[] = [];\n\n const preservedTypes: string[] = [];\n\n const variablesListToProcess: TypeAliasDeclaration[] = [];\n const queryMutationListToProcess: TypeAliasDeclaration[] = [];\n\n typeAliases.forEach(typeAlias => {\n const name = typeAlias.getName();\n if (isQueryVariables(name) || isMutationVariables(name) || isFragment(name)) {\n variablesListToProcess.push(typeAlias);\n queryAndMutations.push(typeAlias);\n } else if (isQuery(name) || isMutation(name)) {\n queryMutationListToProcess.push(typeAlias);\n queryAndMutations.push(typeAlias);\n }\n });\n\n sourceFile.getVariableStatements().forEach(variableStatement => {\n const variable = variableStatement\n .getFirstChildByKind(SyntaxKind.VariableDeclarationList)\n ?.getFirstChildByKind(SyntaxKind.VariableDeclaration);\n if (variable?.getName().endsWith(\"Document\") || variable?.getName().endsWith(\"FragmentDoc\")) {\n queryAndMutations.push(variableStatement);\n }\n });\n\n // RUN VARAIABLES FIRST since it will force full props if nessasary\n\n // VARIABLES are input so force include all props\n variablesListToProcess.forEach(typeAlias => {\n preserveTypes(typeAlias, preservedTypes, sourceFile, isVerbose);\n });\n\n // QUERY and MUTATION are dynamic so dont force props\n queryMutationListToProcess.forEach(typeAlias => {\n preserveTypes(typeAlias, preservedTypes, sourceFile, isVerbose);\n });\n\n return { preservedTypes, queryAndMutations };\n};\n\nconst preserveTypes = (node: Node, preservedTypes: string[], sourceFile: SourceFile, isVerbose?: boolean): Node[] => {\n const typeReferences: Node[] = [];\n if (!node.getText().startsWith(\"export type Query\") && !node.getText().startsWith(\"export type Mutation\")) {\n node.forEachDescendant(descendant => {\n if (descendant.getKind() === SyntaxKind.TypeReference &&\n !descendant.getText().startsWith(\"Scalars\") &&\n !descendant.getText().startsWith(\"Maybe<\") &&\n !descendant.getText().startsWith(\"InputMaybe<\") &&\n !descendant.getText().startsWith(\"Array<\") &&\n !descendant.getText().startsWith(\"Exact<\") &&\n !descendant.getText().includes(\"__typename\")\n ) {\n if (isVerbose) {\n // eslint-disable-next-line no-console\n console.log(\"ADDING\", getFullPathUpOfNode(descendant), \":\", descendant.getText(), descendant.getKindName());\n }\n if (!preservedTypes.includes(descendant.getText())) {\n const foundTypeAlias = sourceFile.getTypeAlias(descendant.getText());\n preservedTypes.push(descendant.getText());\n if (foundTypeAlias) {\n preserveTypes(foundTypeAlias, preservedTypes, sourceFile, isVerbose);\n }\n }\n }\n });\n }\n\n return typeReferences;\n};\n\n/**\n * Convert an enum to a const object and string literal type\n */\nexport const convertEnumToConstObject = (enumDeclaration: EnumDeclaration) => {\n const enumName = enumDeclaration.getName();\n const members = enumDeclaration.getMembers();\n\n const properties = members.map(member => {\n const name = member.getName();\n const value = member.getValue();\n return `${name}: '${value}'`;\n });\n\n const lowerCaseFirstLetter = enumName[0]?.toLowerCase() + enumName.slice(1);\n const constObjectText = `export const ${lowerCaseFirstLetter} = {\\n ${properties.join(\n \",\\n \"\n )},\\n} as const;\\nexport type ${enumName} = typeof ${lowerCaseFirstLetter}[keyof typeof ${lowerCaseFirstLetter}];`;\n\n return constObjectText;\n};\n\n/**\n * Create a source file from a string\n */\nexport const createSourceFile = (fileContent: string) => {\n const project = new Project({\n compilerOptions: {\n noUnusedLocals: true,\n noUnusedParameters: true,\n },\n });\n\n return project.createSourceFile(\"tmp.ts\", fileContent);\n};\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/utils.ts"],"names":[],"mappings":";;;AAAA,uCAAwG;AAExG;;GAEG;AACI,MAAM,OAAO,GAAG,CAAC,EAAE,eAAe,EAAE,IAAI,EAAoD,EAAE,EAAE;IACrG,OAAO,eAAe,KAAK,OAAO,IAAI,IAAI,KAAK,OAAO,CAAC;AACzD,CAAC,CAAC;AAFW,QAAA,OAAO,WAElB;AACF;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,EAAE;IAC/C,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACzC,CAAC,CAAC;AAFW,QAAA,gBAAgB,oBAE3B;AAEF;;GAEG;AACI,MAAM,UAAU,GAAG,CAAC,EAAE,eAAe,EAAE,IAAI,EAAoD,EAAE,EAAE;IACxG,OAAO,eAAe,KAAK,UAAU,IAAI,IAAI,KAAK,UAAU,CAAC;AAC/D,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB;AAEF;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAE,EAAE;IAClD,OAAO,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;AAC5C,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B;AAEF;;GAEG;AACI,MAAM,cAAc,GAAG,CAAC,EAAE,eAAe,EAAE,IAAI,EAAoD,EAAE,EAAE;IAC5G,OAAO,eAAe,KAAK,cAAc,IAAI,IAAI,KAAK,cAAc,CAAC;AACvE,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AACF;;GAEG;AACI,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAE,EAAE;IACtD,OAAO,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC;AAChD,CAAC,CAAC;AAFW,QAAA,uBAAuB,2BAElC;AAEF;;GAEG;AACI,MAAM,U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AE,CAAC;QAC9B,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAChC,OAAO,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,MAAM,oBAAoB,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5E,MAAM,eAAe,GAAG,gBAAgB,oBAAoB,WAAW,UAAU,CAAC,IAAI,CACpF,OAAO,CACR,+BAA+B,QAAQ,aAAa,oBAAoB,iBAAiB,oBAAoB,IAAI,CAAC;IAEnH,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAhBW,QAAA,wBAAwB,4BAgBnC;AAEF;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAC,WAAmB,EAAE,EAAE;IACtD,MAAM,OAAO,GAAG,IAAI,kBAAO,CAAC;QAC1B,eAAe,EAAE;YACf,cAAc,EAAE,IAAI;YACpB,kBAAkB,EAAE,IAAI;SACzB;KACF,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AACzD,CAAC,CAAC;AATW,QAAA,gBAAgB,oBAS3B","sourcesContent":["import { EnumDeclaration, Node, Project, SourceFile, SyntaxKind, TypeAliasDeclaration } from \"ts-morph\";\n\n/**\n * Check if the name is a *Query\n */\nexport const isQuery = ({ typeLiteralText, name }: { typeLiteralText: string | null; name: string }) => {\n return typeLiteralText === \"Query\" && name !== \"Query\";\n};\n/**\n * Check if the name is a *QueryVariables\n */\nexport const isQueryVariables = (name: string) => {\n return name.endsWith(\"QueryVariables\");\n};\n\n/**\n * Check if the name is a Mutation\n */\nexport const isMutation = ({ typeLiteralText, name }: { typeLiteralText: string | null; name: string }) => {\n return typeLiteralText === \"Mutation\" && name !== \"Mutation\";\n};\n\n/**\n * Check if the name is a *QueryVariables\n */\nexport const isMutationVariables = (name: string) => {\n return name.endsWith(\"MutationVariables\");\n};\n\n/**\n * Check if the name is a Subscription\n */\nexport const isSubscription = ({ typeLiteralText, name }: { typeLiteralText: string | null; name: string }) => {\n return typeLiteralText === \"Subscription\" && name !== \"Subscription\";\n};\n/**\n * Check if the name is a *SubscriptionVariables\n */\nexport const isSubscriptionVariables = (name: string) => {\n return name.endsWith(\"SubscriptionVariables\");\n};\n\n/**\n * Check if the name is a *Fragment and not *_Fragment\n */\nexport const isFragment = (name: string) => {\n return name.endsWith(\"Fragment\") && !name.endsWith(\"_Fragment\");\n};\n\n/**\n * Debug where you are in the tree\n */\nconst getFullPathUpOfNode = (node: Node) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let currentNode: any | undefined = node;\n const paths = [];\n\n while (currentNode) {\n // You can customize what details to include for each node (e.g., kind, text)\n let name = currentNode.getName ? currentNode.getName() : currentNode.getKindName();\n if (node.getKind() === SyntaxKind.TypeLiteral) {\n const typeLiteral = node.asKindOrThrow(SyntaxKind.TypeLiteral);\n name = typeLiteral.getText();\n }\n\n paths.unshift(`${name}`);\n currentNode = currentNode.getParent();\n }\n\n return paths.join(\">>\");\n};\n\n/**\n * Get the types that should be preserved\n */\nexport const getPreservedTypes = (\n sourceFile: SourceFile,\n isVerbose?: boolean\n): {\n preservedTypes: string[];\n queryAndMutations: Node[];\n} => {\n const typeAliases = sourceFile.getTypeAliases();\n const queryAndMutations: Node[] = [];\n\n const preservedTypes: string[] = [];\n\n const variablesListToProcess: TypeAliasDeclaration[] = [];\n const queryMutationListToProcess: TypeAliasDeclaration[] = [];\n\n typeAliases.forEach(typeAlias => {\n const name = typeAlias.getName();\n\n // Get the type literal node that contains the properties\n const typeLiteral = typeAlias.getTypeNode()?.asKind(SyntaxKind.TypeLiteral);\n let typeLiteralText: string | null = null;\n if (typeLiteral) {\n // Find the __typename property\n const typenameProperty = typeLiteral.getProperties().find(prop => prop.getName() === \"__typename\");\n\n if (typenameProperty) {\n typeLiteralText = typenameProperty.getType().getText().replaceAll('\"', \"\");\n }\n }\n if (isQueryVariables(name) || isMutationVariables(name) || isSubscriptionVariables(name) || isFragment(name)) {\n variablesListToProcess.push(typeAlias);\n queryAndMutations.push(typeAlias);\n } else if (\n isQuery({ typeLiteralText, name }) ||\n isMutation({ typeLiteralText, name }) ||\n isSubscription({ typeLiteralText, name })\n ) {\n queryMutationListToProcess.push(typeAlias);\n queryAndMutations.push(typeAlias);\n }\n });\n\n sourceFile.getVariableStatements().forEach(variableStatement => {\n const variable = variableStatement\n .getFirstChildByKind(SyntaxKind.VariableDeclarationList)\n ?.getFirstChildByKind(SyntaxKind.VariableDeclaration);\n if (variable?.getName().endsWith(\"Document\") || variable?.getName().endsWith(\"FragmentDoc\")) {\n queryAndMutations.push(variableStatement);\n }\n });\n\n // RUN VARAIABLES FIRST since it will force full props if nessasary\n\n // VARIABLES are input so force include all props\n variablesListToProcess.forEach(typeAlias => {\n preserveTypes(typeAlias, preservedTypes, sourceFile, isVerbose);\n });\n\n // QUERY and MUTATION are dynamic so dont force props\n queryMutationListToProcess.forEach(typeAlias => {\n preserveTypes(typeAlias, preservedTypes, sourceFile, isVerbose);\n });\n\n return { preservedTypes, queryAndMutations };\n};\n\nconst preserveTypes = (node: Node, preservedTypes: string[], sourceFile: SourceFile, isVerbose?: boolean): Node[] => {\n const typeReferences: Node[] = [];\n\n node.forEachDescendant(descendant => {\n if (\n descendant.getKind() === SyntaxKind.TypeReference &&\n !descendant.getText().startsWith(\"Scalars\") &&\n !descendant.getText().startsWith(\"Maybe<\") &&\n !descendant.getText().startsWith(\"InputMaybe<\") &&\n !descendant.getText().startsWith(\"Array<\") &&\n !descendant.getText().startsWith(\"Exact<\") &&\n !descendant.getText().includes(\"__typename\")\n ) {\n if (isVerbose) {\n // eslint-disable-next-line no-console\n console.log(\"ADDING\", getFullPathUpOfNode(descendant), \":\", descendant.getText(), descendant.getKindName());\n }\n if (!preservedTypes.includes(descendant.getText())) {\n const foundTypeAlias = sourceFile.getTypeAlias(descendant.getText());\n preservedTypes.push(descendant.getText());\n if (foundTypeAlias) {\n preserveTypes(foundTypeAlias, preservedTypes, sourceFile, isVerbose);\n }\n }\n }\n });\n\n return typeReferences;\n};\n\n/**\n * Convert an enum to a const object and string literal type\n */\nexport const convertEnumToConstObject = (enumDeclaration: EnumDeclaration) => {\n const enumName = enumDeclaration.getName();\n const members = enumDeclaration.getMembers();\n\n const properties = members.map(member => {\n const name = member.getName();\n const value = member.getValue();\n return `${name}: '${value}'`;\n });\n\n const lowerCaseFirstLetter = enumName[0]?.toLowerCase() + enumName.slice(1);\n const constObjectText = `export const ${lowerCaseFirstLetter} = {\\n ${properties.join(\n \",\\n \"\n )},\\n} as const;\\nexport type ${enumName} = typeof ${lowerCaseFirstLetter}[keyof typeof ${lowerCaseFirstLetter}];`;\n\n return constObjectText;\n};\n\n/**\n * Create a source file from a string\n */\nexport const createSourceFile = (fileContent: string) => {\n const project = new Project({\n compilerOptions: {\n noUnusedLocals: true,\n noUnusedParameters: true,\n },\n });\n\n return project.createSourceFile(\"tmp.ts\", fileContent);\n};\n"]}
|