@trackunit/react-graphql-tools 1.14.47 → 1.14.49-alpha-df0e8d549b3.0

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,25 +1,3 @@
1
- ## 1.14.47 (2026-06-30)
2
-
3
- ### 🧱 Updated Dependencies
4
-
5
- - Updated react-vite-test-setup to 0.0.47
6
-
7
- ## 1.14.46 (2026-06-29)
8
-
9
- This was a version bump only for react-graphql-tools to align it with other projects, there were no code changes.
10
-
11
- ## 1.14.45 (2026-06-29)
12
-
13
- ### 🧱 Updated Dependencies
14
-
15
- - Updated react-vite-test-setup to 0.0.46
16
-
17
- ## 1.14.44 (2026-06-29)
18
-
19
- ### 🧱 Updated Dependencies
20
-
21
- - Updated react-vite-test-setup to 0.0.45
22
-
23
1
  ## 1.14.43 (2026-06-25)
24
2
 
25
3
  ### 🧱 Updated Dependencies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-graphql-tools",
3
- "version": "1.14.47",
3
+ "version": "1.14.49-alpha-df0e8d549b3.0",
4
4
  "main": "src/index.js",
5
5
  "executors": "./executors.json",
6
6
  "generators": "./generators.json",
@@ -6,15 +6,14 @@ const tslib_1 = require("tslib");
6
6
  const fs_1 = require("fs");
7
7
  const path_1 = require("path");
8
8
  const prettier = tslib_1.__importStar(require("prettier"));
9
- const ts_morph_1 = require("ts-morph");
10
9
  const scrubMockFile_1 = require("./scrubMockFile");
11
10
  const utils_1 = require("./utils");
12
11
  /**
13
12
  * Generates React hooks from your graphql files.
14
13
  */
15
- const scrubFileContent = async (fileContent, nxRoot, isVerbose, providedSourceFile) => {
14
+ const scrubFileContent = async (fileContent, nxRoot, isVerbose) => {
16
15
  const start = new Date().getTime();
17
- const sourceFile = providedSourceFile ?? (0, utils_1.createSourceFile)(fileContent);
16
+ const sourceFile = (0, utils_1.createSourceFile)(fileContent);
18
17
  let resultFileContent = "";
19
18
  const scalarsType = sourceFile.getTypeAliasOrThrow("Scalars");
20
19
  scalarsType.getEndLineNumber();
@@ -30,14 +29,14 @@ const scrubFileContent = async (fileContent, nxRoot, isVerbose, providedSourceFi
30
29
  }
31
30
  sourceFile.getEnums().forEach(enumType => {
32
31
  const typeName = enumType.getName();
33
- if (preservedTypes.has(typeName) && !alreadyAdded.includes(typeName) && !(0, utils_1.isFragment)(typeName)) {
32
+ if (preservedTypes.includes(typeName) && !alreadyAdded.includes(typeName) && !(0, utils_1.isFragment)(typeName)) {
34
33
  alreadyAdded.push(typeName);
35
34
  resultFileContent += "\n" + (0, utils_1.convertEnumToConstObject)(enumType) + "\n";
36
35
  }
37
36
  });
38
37
  sourceFile.getTypeAliases().forEach(typeAlias => {
39
38
  const typeName = typeAlias.getName();
40
- if (preservedTypes.has(typeName) && !alreadyAdded.includes(typeName) && !(0, utils_1.isFragment)(typeName)) {
39
+ if (preservedTypes.includes(typeName) && !alreadyAdded.includes(typeName) && !(0, utils_1.isFragment)(typeName)) {
41
40
  alreadyAdded.push(typeName);
42
41
  resultFileContent += "\n" + typeAlias.getText() + "\n";
43
42
  }
@@ -62,20 +61,8 @@ const scrubFile = async (file, nxRoot, isVerbose) => {
62
61
  if (fileContent.length === 0) {
63
62
  console.warn(`File ${file} is empty`);
64
63
  }
65
- // Parse the (large) generated file into ts-morph once and share it between the main and mock scrub
66
- // instead of parsing it twice. Use the mock's stricter compiler options (the main scrub doesn't use
67
- // the TypeChecker, so they don't affect its output).
68
- const sharedSourceFile = new ts_morph_1.Project({
69
- compilerOptions: {
70
- noUnusedLocals: true,
71
- noUnusedParameters: true,
72
- strictNullChecks: true,
73
- },
74
- }).createSourceFile("tmp.ts", fileContent);
75
- // The main scrub reads line numbers from the pristine AST, so it must run before the mock scrub
76
- // mutates the shared source file via insertStatements().
77
- const scrubbedFileContent = await (0, exports.scrubFileContent)(fileContent, nxRoot, isVerbose, sharedSourceFile);
78
- const scrubbedMockFileContent = await (0, scrubMockFile_1.scrubMockFileContent)(fileContent, nxRoot, isVerbose, sharedSourceFile);
64
+ const scrubbedMockFileContent = await (0, scrubMockFile_1.scrubMockFileContent)(fileContent, nxRoot, isVerbose);
65
+ const scrubbedFileContent = await (0, exports.scrubFileContent)(fileContent, nxRoot, isVerbose);
79
66
  let options = null;
80
67
  try {
81
68
  options = prettier
@@ -281,16 +281,16 @@ const generateMockFromType = (type, text) => {
281
281
  /**
282
282
  * Generates React hooks from your graphql files.
283
283
  */
284
- const scrubMockFileContent = async (fileContent, nxRoot, isVerbose, providedSourceFile) => {
284
+ const scrubMockFileContent = async (fileContent, nxRoot, isVerbose) => {
285
285
  const start = new Date().getTime();
286
- const generatedFile = providedSourceFile ??
287
- new ts_morph_1.Project({
288
- compilerOptions: {
289
- noUnusedLocals: true,
290
- noUnusedParameters: true,
291
- strictNullChecks: true,
292
- },
293
- }).createSourceFile("tmpMock.ts", fileContent);
286
+ const project = new ts_morph_1.Project({
287
+ compilerOptions: {
288
+ noUnusedLocals: true,
289
+ noUnusedParameters: true,
290
+ strictNullChecks: true,
291
+ },
292
+ });
293
+ const generatedFile = project.createSourceFile("tmpMock.ts", fileContent);
294
294
  const mockThese = [];
295
295
  generatedFile.insertStatements(0, "/* eslint-disable @typescript-eslint/no-explicit-any */");
296
296
  generatedFile.insertStatements(1, "/* eslint-disable @typescript-eslint/array-type */");
@@ -70,33 +70,26 @@ const getFullPathUpOfNode = (node) => {
70
70
  const getPreservedTypes = (sourceFile, isVerbose) => {
71
71
  const typeAliases = sourceFile.getTypeAliases();
72
72
  const queryAndMutations = [];
73
- const preservedTypes = new Set();
73
+ const preservedTypes = [];
74
74
  const variablesListToProcess = [];
75
75
  const queryMutationListToProcess = [];
76
76
  typeAliases.forEach(typeAlias => {
77
77
  const name = typeAlias.getName();
78
- // Name-based classification needs no type info, so handle it first and skip resolving the
79
- // `__typename` literal for the (many) *Variables / *Fragment aliases.
80
- if (isQueryVariables(name) || isMutationVariables(name) || isSubscriptionVariables(name) || (0, exports.isFragment)(name)) {
81
- variablesListToProcess.push(typeAlias);
82
- queryAndMutations.push(typeAlias);
83
- return;
84
- }
85
78
  // Get the type literal node that contains the properties
86
79
  const typeLiteral = typeAlias.getTypeNode()?.asKind(ts_morph_1.SyntaxKind.TypeLiteral);
87
- if (!typeLiteral) {
88
- return;
80
+ let typeLiteralText = null;
81
+ if (typeLiteral) {
82
+ // Find the __typename property
83
+ const typenameProperty = typeLiteral.getProperties().find(prop => prop.getName() === "__typename");
84
+ if (typenameProperty) {
85
+ typeLiteralText = typenameProperty.getType().getText().replaceAll('"', "");
86
+ }
89
87
  }
90
- // Find the __typename property
91
- const typenameProperty = typeLiteral.getProperties().find(prop => prop.getName() === "__typename");
92
- if (!typenameProperty) {
93
- return;
88
+ if (isQueryVariables(name) || isMutationVariables(name) || isSubscriptionVariables(name) || (0, exports.isFragment)(name)) {
89
+ variablesListToProcess.push(typeAlias);
90
+ queryAndMutations.push(typeAlias);
94
91
  }
95
- // Read the literal straight from the AST type node (`__typename?: 'Query'`) instead of asking the
96
- // TypeChecker via `getType()`, which is dramatically faster on large generated files. The AST text
97
- // keeps the source quote style (codegen emits single quotes), so strip both quote characters.
98
- const typeLiteralText = (typenameProperty.getTypeNode()?.getText() ?? typenameProperty.getType().getText()).replace(/['"]/g, "");
99
- if (isQuery({ typeLiteralText, name }) ||
92
+ else if (isQuery({ typeLiteralText, name }) ||
100
93
  isMutation({ typeLiteralText, name }) ||
101
94
  isSubscription({ typeLiteralText, name })) {
102
95
  queryMutationListToProcess.push(typeAlias);
@@ -124,32 +117,29 @@ const getPreservedTypes = (sourceFile, isVerbose) => {
124
117
  };
125
118
  exports.getPreservedTypes = getPreservedTypes;
126
119
  const preserveTypes = (node, preservedTypes, sourceFile, isVerbose) => {
120
+ const typeReferences = [];
127
121
  node.forEachDescendant(descendant => {
128
- if (descendant.getKind() !== ts_morph_1.SyntaxKind.TypeReference) {
129
- return;
130
- }
131
- // `getText()` serialises the node's subtree, so compute it once instead of up to nine times.
132
- const text = descendant.getText();
133
- if (text.startsWith("Scalars") ||
134
- text.startsWith("Maybe<") ||
135
- text.startsWith("InputMaybe<") ||
136
- text.startsWith("Array<") ||
137
- text.startsWith("Exact<") ||
138
- text.includes("__typename")) {
139
- return;
140
- }
141
- if (isVerbose) {
142
- // eslint-disable-next-line no-console
143
- console.log("ADDING", getFullPathUpOfNode(descendant), ":", text, descendant.getKindName());
144
- }
145
- if (!preservedTypes.has(text)) {
146
- const foundTypeAlias = sourceFile.getTypeAlias(text);
147
- preservedTypes.add(text);
148
- if (foundTypeAlias) {
149
- preserveTypes(foundTypeAlias, preservedTypes, sourceFile, isVerbose);
122
+ if (descendant.getKind() === ts_morph_1.SyntaxKind.TypeReference &&
123
+ !descendant.getText().startsWith("Scalars") &&
124
+ !descendant.getText().startsWith("Maybe<") &&
125
+ !descendant.getText().startsWith("InputMaybe<") &&
126
+ !descendant.getText().startsWith("Array<") &&
127
+ !descendant.getText().startsWith("Exact<") &&
128
+ !descendant.getText().includes("__typename")) {
129
+ if (isVerbose) {
130
+ // eslint-disable-next-line no-console
131
+ console.log("ADDING", getFullPathUpOfNode(descendant), ":", descendant.getText(), descendant.getKindName());
132
+ }
133
+ if (!preservedTypes.includes(descendant.getText())) {
134
+ const foundTypeAlias = sourceFile.getTypeAlias(descendant.getText());
135
+ preservedTypes.push(descendant.getText());
136
+ if (foundTypeAlias) {
137
+ preserveTypes(foundTypeAlias, preservedTypes, sourceFile, isVerbose);
138
+ }
150
139
  }
151
140
  }
152
141
  });
142
+ return typeReferences;
153
143
  };
154
144
  /**
155
145
  * Convert an enum to a const object and string literal type