@trackunit/react-graphql-tools 0.0.84 → 0.0.86
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 -0
- package/package.json +6 -5
- package/src/executors/createHooks/executor.js +4 -5
- package/src/executors/createHooks/executor.js.map +1 -1
- package/src/executors/createHooks/generateHooks.js +4 -5
- package/src/executors/createHooks/generateHooks.js.map +1 -1
- package/src/executors/createHooks/scrubFile.js +9 -9
- package/src/executors/createHooks/scrubFile.js.map +1 -1
- package/src/executors/createHooks/scrubMockFile.js +2 -3
- package/src/executors/createHooks/scrubMockFile.js.map +1 -1
- package/src/generators/add-graphql/generator.js +26 -26
- package/src/generators/add-graphql/generator.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.0.86](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.85...react-graphql-tools/0.0.86) (2024-08-12)
|
|
6
|
+
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `test-setup` updated to version `0.0.85`
|
|
10
|
+
## [0.0.85](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.84...react-graphql-tools/0.0.85) (2024-08-12)
|
|
11
|
+
|
|
12
|
+
### Dependency Updates
|
|
13
|
+
|
|
14
|
+
* `test-setup` updated to version `0.0.84`
|
|
5
15
|
## [0.0.84](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.83...react-graphql-tools/0.0.84) (2024-08-09)
|
|
6
16
|
|
|
7
17
|
## [0.0.83](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.82...react-graphql-tools/0.0.83) (2024-07-09)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-graphql-tools",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "0.0.86",
|
|
4
|
+
"main": "src/index.js",
|
|
5
5
|
"executors": "./executors.json",
|
|
6
6
|
"generators": "./generators.json",
|
|
7
7
|
"repository": "https://github.com/Trackunit/manager",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"node": ">=20.x"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@nx/devkit": "
|
|
13
|
+
"@nx/devkit": "19.5.6",
|
|
14
14
|
"@graphql-codegen/cli": "^5.0.0",
|
|
15
15
|
"@graphql-codegen/client-preset": "^4.1.0",
|
|
16
16
|
"prettier": "3.3.2",
|
|
@@ -19,5 +19,6 @@
|
|
|
19
19
|
"win-ca": "^3.5.1",
|
|
20
20
|
"tslib": "^2.6.2"
|
|
21
21
|
},
|
|
22
|
-
"type": "commonjs"
|
|
23
|
-
|
|
22
|
+
"type": "commonjs",
|
|
23
|
+
"types": "./src/index.d.ts"
|
|
24
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateGraphqlHooks = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const fs_1 = require("fs");
|
|
6
5
|
const path_1 = require("path");
|
|
7
6
|
require("win-ca");
|
|
@@ -14,7 +13,7 @@ const scrubFile_1 = require("./scrubFile");
|
|
|
14
13
|
* @param context The execution context for this executor
|
|
15
14
|
* @returns {Promise<{ success: number; }>} success when finished
|
|
16
15
|
*/
|
|
17
|
-
const CreateGraphqlHooks = (_unused, context) =>
|
|
16
|
+
const CreateGraphqlHooks = async (_unused, context) => {
|
|
18
17
|
var _a;
|
|
19
18
|
const nxRoot = `${context.root}`;
|
|
20
19
|
if (!context.projectsConfigurations) {
|
|
@@ -47,7 +46,7 @@ const config: CodegenConfig = {
|
|
|
47
46
|
export default config;
|
|
48
47
|
`);
|
|
49
48
|
}
|
|
50
|
-
const result =
|
|
49
|
+
const result = await (0, generateHooks_1.generateHooks)({
|
|
51
50
|
nxRoot: context.root,
|
|
52
51
|
codeGenFilePath,
|
|
53
52
|
isVerbose: context.isVerbose,
|
|
@@ -60,11 +59,11 @@ export default config;
|
|
|
60
59
|
// eslint-disable-next-line no-console
|
|
61
60
|
console.log("Scrubbing file: ", pathToGenerateFile);
|
|
62
61
|
}
|
|
63
|
-
|
|
62
|
+
await (0, scrubFile_1.scrubFile)(pathToGenerateFile, nxRoot, context.isVerbose);
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
return { success: result };
|
|
67
|
-
}
|
|
66
|
+
};
|
|
68
67
|
exports.CreateGraphqlHooks = CreateGraphqlHooks;
|
|
69
68
|
exports.default = exports.CreateGraphqlHooks;
|
|
70
69
|
//# sourceMappingURL=executor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/executor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/executor.ts"],"names":[],"mappings":";;;AACA,2BAAgC;AAChC,+BAA4B;AAC5B,kBAAgB;AAChB,mDAAgD;AAChD,2CAAwC;AAExC;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,OAAgB,EAAE,OAAwB,EAAE,EAAE;;IACrF,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IACjC,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,OAAO,GAAG,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AAC;gBACtB,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;YACtD,CAAC;YACD,MAAM,IAAA,qBAAS,EAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC7B,CAAC,CAAC;AAvDW,QAAA,kBAAkB,sBAuD7B;AAEF,kBAAe,0BAAkB,CAAC","sourcesContent":["import { ExecutorContext } from \"@nx/devkit\";\nimport { existsSync } from \"fs\";\nimport { join } from \"path\";\nimport \"win-ca\";\nimport { generateHooks } from \"./generateHooks\";\nimport { scrubFile } from \"./scrubFile\";\n\n/**\n * This executor generates react hooks for all graphql files.\n *\n * @param _unused unused props from nx\n * @param context The execution context for this executor\n * @returns {Promise<{ success: number; }>} success when finished\n */\nexport const CreateGraphqlHooks = async (_unused: unknown, context: ExecutorContext) => {\n const nxRoot = `${context.root}`;\n if (!context.projectsConfigurations) {\n throw new Error(\"context projectsConfigurations is required\");\n }\n if (!context.projectName) {\n throw new Error(\"context projectName is required\");\n }\n\n const libRoot = context.projectsConfigurations.projects[context.projectName]?.root;\n\n if (!libRoot) {\n throw new Error(\"Missing library root\");\n }\n\n const fullLibRoot = join(nxRoot, libRoot);\n const tsConfigPath = existsSync(join(fullLibRoot, \"tsconfig.lib.json\"))\n ? join(fullLibRoot, \"tsconfig.lib.json\")\n : join(fullLibRoot, \"tsconfig.app.json\");\n\n if (!tsConfigPath) {\n throw new Error(\"context projectsConfigurations is required\");\n }\n\n const codeGenFilePath = join(fullLibRoot, \"codegen.ts\");\n if (!existsSync(codeGenFilePath)) {\n throw new Error(`codegen.ts file not found in ${fullLibRoot} please add this file and run again to generate hooks. The content should be\nimport { type CodegenConfig } from \"@graphql-codegen/cli\";\nimport { getGraphqlCodegenConfig } from \"@trackunit/iris-app-build-utilities\";\n\nconst config: CodegenConfig = {\n ...getGraphqlCodegenConfig(__dirname),\n // You can override codegen default config here\n};\nexport default config;\n`);\n }\n\n const result = await generateHooks({\n nxRoot: context.root,\n codeGenFilePath,\n isVerbose: context.isVerbose,\n tsConfigPath,\n });\n if (process.env.SKIP_SCRUB !== \"true\") {\n const pathToGenerateFile = join(fullLibRoot, \"src\", \"generated\", \"graphql-api\", \"graphql.ts\");\n if (existsSync(pathToGenerateFile)) {\n if (context.isVerbose) {\n // eslint-disable-next-line no-console\n console.log(\"Scrubbing file: \", pathToGenerateFile);\n }\n await scrubFile(pathToGenerateFile, nxRoot, context.isVerbose);\n }\n }\n return { success: result };\n};\n\nexport default CreateGraphqlHooks;\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateHooks = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const cli_1 = require("@graphql-codegen/cli");
|
|
6
5
|
/**
|
|
7
6
|
* Generates React hooks from your graphql files.
|
|
@@ -11,7 +10,7 @@ const cli_1 = require("@graphql-codegen/cli");
|
|
|
11
10
|
* @param options.tsConfigPath the path to the tsconfig file.
|
|
12
11
|
* @param options.isVerbose if true, will log more information.
|
|
13
12
|
*/
|
|
14
|
-
const generateHooks = (options) =>
|
|
13
|
+
const generateHooks = async (options) => {
|
|
15
14
|
const contextConfig = {
|
|
16
15
|
watch: false,
|
|
17
16
|
overwrite: true,
|
|
@@ -28,8 +27,8 @@ const generateHooks = (options) => tslib_1.__awaiter(void 0, void 0, void 0, fun
|
|
|
28
27
|
// eslint-disable-next-line no-console
|
|
29
28
|
console.log(contextConfig);
|
|
30
29
|
}
|
|
31
|
-
const context =
|
|
32
|
-
return
|
|
33
|
-
}
|
|
30
|
+
const context = await (0, cli_1.createContext)(contextConfig);
|
|
31
|
+
return await (0, cli_1.generate)(context);
|
|
32
|
+
};
|
|
34
33
|
exports.generateHooks = generateHooks;
|
|
35
34
|
//# sourceMappingURL=generateHooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateHooks.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/generateHooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateHooks.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/generateHooks.ts"],"names":[],"mappings":";;;AAAA,8CAA+D;AAC/D;;;;;;;GAOG;AACI,MAAM,aAAa,GAAG,KAAK,EAAE,OAKnC,EAAE,EAAE;IACH,MAAM,aAAa,GAAG;QACpB,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS;QAC1B,UAAU,EAAE,KAAK;QACjB,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,OAAO,CAAC,YAAY;QAC7B,MAAM,EAAE,OAAO,CAAC,eAAe;QAC/B,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,OAAO,CAAC,SAAS;QAC1B,KAAK,EAAE,OAAO,CAAC,SAAS;KACzB,CAAC;IACF,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAa,EAAC,aAAa,CAAC,CAAC;IAEnD,OAAO,MAAM,IAAA,cAAQ,EAAC,OAAO,CAAC,CAAC;AACjC,CAAC,CAAC;AA1BW,QAAA,aAAa,iBA0BxB","sourcesContent":["import { createContext, generate } from \"@graphql-codegen/cli\";\n/**\n * Generates React hooks from your graphql files.\n *\n * @param options.codeGenFilePath the path to the codegen file.\n * @param options.nxRoot the nx root.\n * @param options.tsConfigPath the path to the tsconfig file.\n * @param options.isVerbose if true, will log more information.\n */\nexport const generateHooks = async (options: {\n codeGenFilePath: string;\n nxRoot: string;\n isVerbose?: boolean;\n tsConfigPath: string;\n}) => {\n const contextConfig = {\n watch: false,\n overwrite: true,\n silent: !options.isVerbose,\n errorsOnly: false,\n profile: false,\n project: options.tsConfigPath,\n config: options.codeGenFilePath,\n require: [],\n verbose: options.isVerbose,\n debug: options.isVerbose,\n };\n if (options.isVerbose) {\n // eslint-disable-next-line no-console\n console.log(contextConfig);\n }\n\n const context = await createContext(contextConfig);\n\n return await generate(context);\n};\n"]}
|
|
@@ -11,7 +11,7 @@ const utils_1 = require("./utils");
|
|
|
11
11
|
/**
|
|
12
12
|
* Generates React hooks from your graphql files.
|
|
13
13
|
*/
|
|
14
|
-
const scrubFileContent = (fileContent, nxRoot, isVerbose) =>
|
|
14
|
+
const scrubFileContent = async (fileContent, nxRoot, isVerbose) => {
|
|
15
15
|
const start = new Date().getTime();
|
|
16
16
|
const sourceFile = (0, utils_1.createSourceFile)(fileContent);
|
|
17
17
|
let resultFileContent = "";
|
|
@@ -47,20 +47,20 @@ const scrubFileContent = (fileContent, nxRoot, isVerbose) => tslib_1.__awaiter(v
|
|
|
47
47
|
console.log("Execution time: " + time);
|
|
48
48
|
}
|
|
49
49
|
return result;
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
51
|
exports.scrubFileContent = scrubFileContent;
|
|
52
52
|
/**
|
|
53
53
|
* Scrubs the file content.
|
|
54
54
|
*
|
|
55
55
|
* @param file The file to scrub.
|
|
56
56
|
*/
|
|
57
|
-
const scrubFile = (file, nxRoot, isVerbose) =>
|
|
57
|
+
const scrubFile = async (file, nxRoot, isVerbose) => {
|
|
58
58
|
const fileContent = (0, fs_1.readFileSync)(file, { encoding: "utf-8" });
|
|
59
59
|
if (fileContent.length === 0) {
|
|
60
60
|
console.warn(`File ${file} is empty`);
|
|
61
61
|
}
|
|
62
|
-
const scrubbedMockFileContent =
|
|
63
|
-
const scrubbedFileContent =
|
|
62
|
+
const scrubbedMockFileContent = await (0, scrubMockFile_1.scrubMockFileContent)(fileContent, nxRoot, isVerbose);
|
|
63
|
+
const scrubbedFileContent = await (0, exports.scrubFileContent)(fileContent, nxRoot, isVerbose);
|
|
64
64
|
let options = null;
|
|
65
65
|
try {
|
|
66
66
|
options = prettier
|
|
@@ -77,12 +77,12 @@ const scrubFile = (file, nxRoot, isVerbose) => tslib_1.__awaiter(void 0, void 0,
|
|
|
77
77
|
if (!options) {
|
|
78
78
|
throw new Error("Could not find prettier config");
|
|
79
79
|
}
|
|
80
|
-
const prettierOptions =
|
|
80
|
+
const prettierOptions = await options;
|
|
81
81
|
let prettySrc = scrubbedFileContent;
|
|
82
82
|
if (prettierOptions) {
|
|
83
83
|
prettierOptions.parser = "typescript";
|
|
84
84
|
try {
|
|
85
|
-
prettySrc =
|
|
85
|
+
prettySrc = await prettier.format(scrubbedFileContent, prettierOptions);
|
|
86
86
|
}
|
|
87
87
|
catch (error) {
|
|
88
88
|
console.error("Error in prettier.format:", error);
|
|
@@ -93,7 +93,7 @@ const scrubFile = (file, nxRoot, isVerbose) => tslib_1.__awaiter(void 0, void 0,
|
|
|
93
93
|
if (prettierOptions) {
|
|
94
94
|
prettierOptions.parser = "typescript";
|
|
95
95
|
try {
|
|
96
|
-
prettyMockSrc =
|
|
96
|
+
prettyMockSrc = await prettier.format(scrubbedMockFileContent, prettierOptions);
|
|
97
97
|
}
|
|
98
98
|
catch (error) {
|
|
99
99
|
console.error("Error in prettier.format:", error);
|
|
@@ -102,6 +102,6 @@ const scrubFile = (file, nxRoot, isVerbose) => tslib_1.__awaiter(void 0, void 0,
|
|
|
102
102
|
const parentDir = (0, path_1.dirname)(file);
|
|
103
103
|
(0, fs_1.writeFileSync)((0, path_1.join)(parentDir, "mock.ts"), prettyMockSrc, { encoding: "utf-8" });
|
|
104
104
|
return prettySrc;
|
|
105
|
-
}
|
|
105
|
+
};
|
|
106
106
|
exports.scrubFile = scrubFile;
|
|
107
107
|
//# sourceMappingURL=scrubFile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrubFile.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/scrubFile.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,2BAAiD;AACjD,+BAAqC;AACrC,2DAAqC;AACrC,mDAAuD;AACvD,mCAAoG;AAEpG;;GAEG;AACI,MAAM,gBAAgB,GAAG,
|
|
1
|
+
{"version":3,"file":"scrubFile.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/scrubFile.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,2BAAiD;AACjD,+BAAqC;AACrC,2DAAqC;AACrC,mDAAuD;AACvD,mCAAoG;AAEpG;;GAEG;AACI,MAAM,gBAAgB,GAAG,KAAK,EAAE,WAAmB,EAAE,MAAc,EAAE,SAAmB,EAAE,EAAE;IACjG,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;IAEnC,MAAM,UAAU,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAEjD,IAAI,iBAAiB,GAAG,EAAE,CAAC;IAC3B,MAAM,WAAW,GAAG,UAAU,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC9D,WAAW,CAAC,gBAAgB,EAAE,CAAC;IAC/B,iBAAiB,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACxG,MAAM,YAAY,GAAG,UAAU;SAC5B,cAAc,EAAE;SAChB,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,kBAAkB,EAAE,GAAG,WAAW,CAAC,gBAAgB,EAAE,CAAC;SACpF,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;IAEzC,iBAAiB,GAAG,iBAAiB,CAAC,OAAO,CAC3C,u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B,CAAC,CAAC;AAjDW,QAAA,SAAS,aAiDpB","sourcesContent":["/* eslint-disable no-console */\nimport { readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport * as prettier from \"prettier\";\nimport { scrubMockFileContent } from \"./scrubMockFile\";\nimport { convertEnumToConstObject, createSourceFile, getPreservedTypes, isFragment } from \"./utils\";\n\n/**\n * Generates React hooks from your graphql files.\n */\nexport const scrubFileContent = async (fileContent: string, nxRoot: string, isVerbose?: boolean) => {\n const start = new Date().getTime();\n\n const sourceFile = createSourceFile(fileContent);\n\n let resultFileContent = \"\";\n const scalarsType = sourceFile.getTypeAliasOrThrow(\"Scalars\");\n scalarsType.getEndLineNumber();\n resultFileContent += fileContent.split(\"\\n\").slice(0, scalarsType.getEndLineNumber()).join(\"\\n\") + \"\\n\";\n const alreadyAdded = sourceFile\n .getTypeAliases()\n .filter(typeAlias => typeAlias.getStartLineNumber() < scalarsType.getEndLineNumber())\n .map(typeAlias => typeAlias.getName());\n\n resultFileContent = resultFileContent.replace(\n \"export type InputMaybe<T> = Maybe<T>;\",\n \"export type InputMaybe<T> = Maybe<T> | undefined;\"\n );\n\n const { preservedTypes, queryAndMutations } = getPreservedTypes(sourceFile, isVerbose);\n isVerbose && console.log(\"PreservedTypes:\", preservedTypes);\n\n sourceFile.getEnums().forEach(enumType => {\n const typeName = enumType.getName();\n if (preservedTypes.includes(typeName) && !alreadyAdded.includes(typeName) && !isFragment(typeName)) {\n alreadyAdded.push(typeName);\n resultFileContent += \"\\n\" + convertEnumToConstObject(enumType) + \"\\n\";\n }\n });\n sourceFile.getTypeAliases().forEach(typeAlias => {\n const typeName = typeAlias.getName();\n if (preservedTypes.includes(typeName) && !alreadyAdded.includes(typeName) && !isFragment(typeName)) {\n alreadyAdded.push(typeName);\n resultFileContent += \"\\n\" + typeAlias.getText() + \"\\n\";\n }\n });\n\n const resultQueryAndMutations = queryAndMutations.map(queryOrMutation => queryOrMutation.getFullText()).join(\"\\n\");\n\n const result = resultFileContent + \"\\n\" + resultQueryAndMutations;\n if (isVerbose) {\n const end = new Date().getTime();\n const time = end - start;\n console.log(\"Execution time: \" + time);\n }\n\n return result;\n};\n\n/**\n * Scrubs the file content.\n *\n * @param file The file to scrub.\n */\nexport const scrubFile = async (file: string, nxRoot: string, isVerbose?: boolean) => {\n const fileContent = readFileSync(file, { encoding: \"utf-8\" });\n if (fileContent.length === 0) {\n console.warn(`File ${file} is empty`);\n }\n const scrubbedMockFileContent = await scrubMockFileContent(fileContent, nxRoot, isVerbose);\n\n const scrubbedFileContent = await scrubFileContent(fileContent, nxRoot, isVerbose);\n\n let options = null;\n try {\n options = prettier\n .resolveConfig(join(nxRoot, \".prettierrc\"), {\n useCache: false,\n editorconfig: false,\n config: join(nxRoot, \".prettierrc\"),\n })\n .catch((error: Error) => console.log(error));\n } catch (e) {\n console.log(e);\n }\n if (!options) {\n throw new Error(\"Could not find prettier config\");\n }\n const prettierOptions = await options;\n\n let prettySrc = scrubbedFileContent;\n if (prettierOptions) {\n prettierOptions.parser = \"typescript\";\n try {\n prettySrc = await prettier.format(scrubbedFileContent, prettierOptions);\n } catch (error) {\n console.error(\"Error in prettier.format:\", error);\n }\n }\n writeFileSync(file, prettySrc, { encoding: \"utf-8\" });\n\n let prettyMockSrc = scrubbedMockFileContent;\n if (prettierOptions) {\n prettierOptions.parser = \"typescript\";\n try {\n prettyMockSrc = await prettier.format(scrubbedMockFileContent, prettierOptions);\n } catch (error) {\n console.error(\"Error in prettier.format:\", error);\n }\n }\n const parentDir = dirname(file);\n writeFileSync(join(parentDir, \"mock.ts\"), prettyMockSrc, { encoding: \"utf-8\" });\n return prettySrc;\n};\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.scrubMockFileContent = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
/* eslint-disable no-console */
|
|
6
5
|
const faker_1 = require("@faker-js/faker");
|
|
7
6
|
const ts_morph_1 = require("ts-morph");
|
|
@@ -59,7 +58,7 @@ const generateMockFromType = (type, text) => {
|
|
|
59
58
|
/**
|
|
60
59
|
* Generates React hooks from your graphql files.
|
|
61
60
|
*/
|
|
62
|
-
const scrubMockFileContent = (fileContent, nxRoot, isVerbose) =>
|
|
61
|
+
const scrubMockFileContent = async (fileContent, nxRoot, isVerbose) => {
|
|
63
62
|
const start = new Date().getTime();
|
|
64
63
|
const project = new ts_morph_1.Project({
|
|
65
64
|
compilerOptions: {
|
|
@@ -104,6 +103,6 @@ const scrubMockFileContent = (fileContent, nxRoot, isVerbose) => tslib_1.__await
|
|
|
104
103
|
|
|
105
104
|
${mock.join("\n")}
|
|
106
105
|
`;
|
|
107
|
-
}
|
|
106
|
+
};
|
|
108
107
|
exports.scrubMockFileContent = scrubMockFileContent;
|
|
109
108
|
//# sourceMappingURL=scrubMockFile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrubMockFile.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/scrubMockFile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scrubMockFile.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/scrubMockFile.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAwC;AACxC,uCAAyD;AAEzD,8DAA8D;AAC9D,MAAM,oBAAoB,GAAG,CAAC,IAAS,EAAE,IAAY,EAAO,EAAE;IAC5D,aAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,wDAAwD;IACxD,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACnE,IAAI,aAAa,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAClD,OAAO,0BAA0B,CA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+BAChD,MAAM,CAAC,OAAO,EAAE;;MAEzC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;;;;;;IAML,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;GAChB,CAAC;AACJ,CAAC,CAAC;AAnDW,QAAA,oBAAoB,wBAmD/B","sourcesContent":["/* eslint-disable no-console */\nimport { faker } from \"@faker-js/faker\";\nimport { Project, TypeAliasDeclaration } from \"ts-morph\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst generateMockFromType = (type: any, text: string): any => {\n faker.seed(123);\n // type aliases are not working well so using text here.\n const rightSideText = text.substring(text.indexOf(\":\") + 1).trim();\n if (rightSideText.startsWith(\"DateTimeISOString\")) {\n return \"2023-01-22T15:08:12.527Z\";\n }\n if (type.isStringLiteral()) {\n return type.compilerType.value; // Get the value of the string literal\n }\n if (type.isNumberLiteral()) {\n return parseFloat(type.compilerType.value);\n }\n if (type.isBooleanLiteral()) {\n return type.compilerType.value === \"true\";\n }\n\n if (type.getText() === \"string\") {\n return faker.lorem.word();\n }\n if (type.getText() === \"number\") {\n return faker.number.int();\n }\n if (type.getText() === \"Date\" || type.getText() === \"DateTime\") {\n return \"2023-01-22T15:08:12.527Z\";\n }\n\n if (type.isUnion()) {\n // We'll take the first type in the union for simplicity\n return generateMockFromType(type.getUnionTypes()[0], \"\");\n }\n if (type.isArray()) {\n return [generateMockFromType(type.getArrayElementTypeOrThrow(), \"\")];\n }\n if (type.isObject()) {\n const properties = type.getProperties();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const obj: any = {};\n for (const prop of properties) {\n const declaration = prop.getValueDeclarationOrThrow();\n const propType = declaration.getType();\n if (prop.getName() === \"__typename\") {\n obj[prop.getName()] = propType.getText().replace(/\"/g, \"\");\n } else {\n obj[prop.getName()] = generateMockFromType(propType, declaration.getText());\n }\n }\n return obj;\n }\n return null; // Default\n};\n\n/**\n * Generates React hooks from your graphql files.\n */\nexport const scrubMockFileContent = async (fileContent: string, nxRoot: string, isVerbose?: boolean) => {\n const start = new Date().getTime();\n\n const project = new Project({\n compilerOptions: {\n noUnusedLocals: true,\n noUnusedParameters: true,\n },\n });\n const generatedFile = project.createSourceFile(\"tmpMock.ts\", fileContent);\n const mockThese: TypeAliasDeclaration[] = [];\n\n generatedFile.insertStatements(0, \"/* eslint-disable @typescript-eslint/no-explicit-any */\");\n generatedFile.insertStatements(1, \"/* eslint-disable @typescript-eslint/array-type */\");\n\n generatedFile.getTypeAliases().forEach(node => {\n if (node.getName().endsWith(\"Query\") && node.getName().length > \"Query\".length) {\n mockThese.push(node);\n }\n if (node.getName().endsWith(\"Mutation\") && node.getName().length > \"Mutation\".length) {\n mockThese.push(node);\n }\n });\n\n if (isVerbose) {\n const end = new Date().getTime();\n const time = end - start;\n console.log(\"Mock Execution time: \" + time);\n }\n\n const mock = mockThese.map(mocker => {\n const postFix = (mocker.getName().includes(\"Query\") ? \"Query\" : \"Mutation\").length;\n return `\n \n export const mockFor${mocker.getName()} = (variables: gql.${mocker.getName()}Variables, data?: DeepPartialNullable<gql.${mocker.getName()}> ) => {\n return queryFor(gql.${mocker.getName().substring(0, mocker.getName().length - postFix)}Document, variables, \n mergeDeep(\n ${JSON.stringify(generateMockFromType(mocker.getType(), \"\"), null, 4)}\n , data || {}) as gql.${mocker.getName()}\n );\n }`;\n });\n\n return `\n import { OperationVariables } from \"@apollo/client\";\n import { mergeDeep } from \"@apollo/client/utilities\";\n import { queryFor, DeepPartialNullable } from \"@trackunit/react-core-contexts-test\";\n import * as gql from \"./graphql\";\n \n ${mock.join(\"\\n\")}\n `;\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addGraphqlGenerator =
|
|
3
|
+
exports.addGraphqlGenerator = addGraphqlGenerator;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
/* eslint-disable no-console */
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
@@ -8,32 +8,32 @@ const path = tslib_1.__importStar(require("path"));
|
|
|
8
8
|
/**
|
|
9
9
|
* Setting up Graphql tools for Iris App development
|
|
10
10
|
*/
|
|
11
|
-
function addGraphqlGenerator(tree, options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
projectJSON.targets
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
11
|
+
async function addGraphqlGenerator(tree, options) {
|
|
12
|
+
const workspaceRoot = "";
|
|
13
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
14
|
+
const libraryRoot = projectConfig.root;
|
|
15
|
+
if (!tree.exists("graphql.config.json") && !tree.exists("graphql.config.ts")) {
|
|
16
|
+
(0, devkit_1.generateFiles)(tree, path.join(__dirname, "files", "root"), workspaceRoot, options);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
console.log(`"graphql.config.json" already exist in your workspace root. \nPlease ensure that your "graphql.config.json" contains "schema": "https://iris.trackunit.com/api/graphql/".`);
|
|
20
|
+
}
|
|
21
|
+
if (!tree.exists(`${libraryRoot}/codegen.ts`)) {
|
|
22
|
+
(0, devkit_1.generateFiles)(tree, path.join(__dirname, "files", "subDirectory"), libraryRoot, options);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
console.log(`codegen.ts already exists in ${libraryRoot}`);
|
|
26
|
+
}
|
|
27
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(libraryRoot, "project.json"), projectJSON => {
|
|
28
|
+
projectJSON.targets = {
|
|
29
|
+
...projectJSON.targets,
|
|
30
|
+
"graphql-hooks": {
|
|
31
|
+
executor: "@trackunit/react-graphql-tools:createHooks",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
return projectJSON;
|
|
35
35
|
});
|
|
36
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
36
37
|
}
|
|
37
|
-
exports.addGraphqlGenerator = addGraphqlGenerator;
|
|
38
38
|
exports.default = addGraphqlGenerator;
|
|
39
39
|
//# sourceMappingURL=generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/generators/add-graphql/generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/generators/add-graphql/generator.ts"],"names":[],"mappings":";;AAQA,kDA4BC;;AApCD,+BAA+B;AAC/B,uCAAuH;AACvH,mDAA6B;AAG7B;;GAEG;AACI,KAAK,UAAU,mBAAmB,CAAC,IAAU,EAAE,OAAkC;IACtF,MAAM,aAAa,GAAG,EAAE,CAAC;IACzB,MAAM,aAAa,GAAG,IAAA,iCAAwB,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACtE,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC;IACvC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC7E,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IACrF,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CACT,2KAA2K,CAC5K,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,WAAW,aAAa,CAAC,EAAE,CAAC;QAC9C,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IAC3F,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,gCAAgC,WAAW,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,IAAA,mBAAU,EAAC,IAAI,EAAE,IAAA,0BAAiB,EAAC,WAAW,EAAE,cAAc,CAAC,EAAE,WAAW,CAAC,EAAE;QAC7E,WAAW,CAAC,OAAO,GAAG;YACpB,GAAG,WAAW,CAAC,OAAO;YACtB,eAAe,EAAE;gBACf,QAAQ,EAAE,4CAA4C;aACvD;SACF,CAAC;QACF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;IACH,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,kBAAe,mBAAmB,CAAC","sourcesContent":["/* eslint-disable no-console */\nimport { formatFiles, generateFiles, joinPathFragments, readProjectConfiguration, Tree, updateJson } from \"@nx/devkit\";\nimport * as path from \"path\";\nimport { AddGraphqlGeneratorSchema } from \"./schema\";\n\n/**\n * Setting up Graphql tools for Iris App development\n */\nexport async function addGraphqlGenerator(tree: Tree, options: AddGraphqlGeneratorSchema) {\n const workspaceRoot = \"\";\n const projectConfig = readProjectConfiguration(tree, options.project);\n const libraryRoot = projectConfig.root;\n if (!tree.exists(\"graphql.config.json\") && !tree.exists(\"graphql.config.ts\")) {\n generateFiles(tree, path.join(__dirname, \"files\", \"root\"), workspaceRoot, options);\n } else {\n console.log(\n `\"graphql.config.json\" already exist in your workspace root. \\nPlease ensure that your \"graphql.config.json\" contains \"schema\": \"https://iris.trackunit.com/api/graphql/\".`\n );\n }\n\n if (!tree.exists(`${libraryRoot}/codegen.ts`)) {\n generateFiles(tree, path.join(__dirname, \"files\", \"subDirectory\"), libraryRoot, options);\n } else {\n console.log(`codegen.ts already exists in ${libraryRoot}`);\n }\n\n updateJson(tree, joinPathFragments(libraryRoot, \"project.json\"), projectJSON => {\n projectJSON.targets = {\n ...projectJSON.targets,\n \"graphql-hooks\": {\n executor: \"@trackunit/react-graphql-tools:createHooks\",\n },\n };\n return projectJSON;\n });\n await formatFiles(tree);\n}\n\nexport default addGraphqlGenerator;\n"]}
|