@trackunit/react-graphql-tools 0.0.60 → 0.0.62

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
@@ -2,6 +2,10 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.0.62](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.61...react-graphql-tools/0.0.62) (2024-01-08)
6
+
7
+ ## [0.0.61](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.60...react-graphql-tools/0.0.61) (2024-01-08)
8
+
5
9
  ## [0.0.60](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.59...react-graphql-tools/0.0.60) (2024-01-04)
6
10
 
7
11
  ### Dependency Updates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-graphql-tools",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
4
4
  "main": "./src/index.js",
5
5
  "executors": "./executors.json",
6
6
  "repository": "https://github.com/Trackunit/manager",
@@ -14,7 +14,8 @@
14
14
  "prettier": "3.1.0",
15
15
  "ts-morph": "^20.0.0",
16
16
  "@faker-js/faker": "^8.2.0",
17
- "tslib": "^2.6.2"
17
+ "tslib": "^2.6.2",
18
+ "@graphql-codegen/cli": "^5.0.0"
18
19
  },
19
20
  "type": "commonjs"
20
21
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateHooks = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const child_process_1 = require("child_process");
5
+ const cli_1 = require("@graphql-codegen/cli");
6
6
  /**
7
7
  * Generates React hooks from your graphql files.
8
8
  *
@@ -12,15 +12,24 @@ const child_process_1 = require("child_process");
12
12
  * @param options.isVerbose if true, will log more information.
13
13
  */
14
14
  const generateHooks = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
15
- const cmd = `./node_modules/.bin/graphql-codegen --config "${options.codeGenFilePath}" --require tsconfig-paths/register --debug --verbose --project "${options.tsConfigPath}"`;
15
+ const contextConfig = {
16
+ watch: false,
17
+ overwrite: true,
18
+ silent: !options.isVerbose,
19
+ errorsOnly: false,
20
+ profile: false,
21
+ project: options.tsConfigPath,
22
+ config: options.codeGenFilePath,
23
+ require: [],
24
+ verbose: options.isVerbose,
25
+ debug: options.isVerbose,
26
+ };
16
27
  if (options.isVerbose) {
17
28
  // eslint-disable-next-line no-console
18
- console.log(cmd);
29
+ console.log(contextConfig);
19
30
  }
20
- (0, child_process_1.execSync)(cmd, {
21
- stdio: options.isVerbose ? "inherit" : "ignore",
22
- cwd: options.nxRoot,
23
- });
31
+ const context = yield (0, cli_1.createContext)(contextConfig);
32
+ return yield (0, cli_1.generate)(context);
24
33
  });
25
34
  exports.generateHooks = generateHooks;
26
35
  //# 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":";;;;AAAA,iDAAyC;AACzC;;;;;;;GAOG;AACI,MAAM,aAAa,GAAG,CAAO,OAKnC,EAAE,EAAE;IACH,MAAM,GAAG,GAAG,iDAAiD,OAAO,CAAC,eAAe,oEAAoE,OAAO,CAAC,YAAY,GAAG,CAAC;IAChL,IAAI,OAAO,CAAC,SAAS,EAAE;QACrB,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAClB;IACD,IAAA,wBAAQ,EAAC,GAAG,EAAE;QACZ,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ;QAC/C,GAAG,EAAE,OAAO,CAAC,MAAM;KACpB,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AAfW,QAAA,aAAa,iBAexB","sourcesContent":["import { execSync } from \"child_process\";\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 cmd = `./node_modules/.bin/graphql-codegen --config \"${options.codeGenFilePath}\" --require tsconfig-paths/register --debug --verbose --project \"${options.tsConfigPath}\"`;\n if (options.isVerbose) {\n // eslint-disable-next-line no-console\n console.log(cmd);\n }\n execSync(cmd, {\n stdio: options.isVerbose ? \"inherit\" : \"ignore\",\n cwd: options.nxRoot,\n });\n};\n"]}
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,CAAO,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;QACrB,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;KAC5B;IAED,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAa,EAAC,aAAa,CAAC,CAAC;IAEnD,OAAO,MAAM,IAAA,cAAQ,EAAC,OAAO,CAAC,CAAC;AACjC,CAAC,CAAA,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"]}
@@ -22,6 +22,7 @@ const scrubFileContent = (fileContent, nxRoot, isVerbose) => tslib_1.__awaiter(v
22
22
  .getTypeAliases()
23
23
  .filter(typeAlias => typeAlias.getStartLineNumber() < scalarsType.getEndLineNumber())
24
24
  .map(typeAlias => typeAlias.getName());
25
+ resultFileContent = resultFileContent.replace("export type InputMaybe<T> = Maybe<T>;", "export type InputMaybe<T> = Maybe<T> | undefined;");
25
26
  const { preservedTypes, queryAndMutations } = (0, utils_1.getPreservedTypes)(sourceFile, isVerbose);
26
27
  isVerbose && console.log("PreservedTypes:", preservedTypes);
27
28
  sourceFile.getEnums().forEach(enumType => {
@@ -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,+BAA4B;AAC5B,2DAAqC;AACrC,mDAAuD;AACvD,mCAAoG;AAEpG;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAO,WAAmB,EAAE,MAAc,EAAE,SAAmB,EAAE,EAAE;IACjG,MAAM,KAAK,GAAG,IA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I,eAAe,EAAE;QACnB,eAAe,CAAC,MAAM,GAAG,YAAY,CAAC;QACtC,IAAI;YACF,aAAa,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,uBAAuB,EAAE,eAAe,CAAC,CAAC;SACjF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;SACnD;KACF;IACD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzD,IAAA,kBAAa,EAAC,SAAS,GAAG,UAAU,EAAE,aAAa,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5E,OAAO,SAAS,CAAC;AACnB,CAAC,CAAA,CAAC;AAjDW,QAAA,SAAS,aAiDpB","sourcesContent":["/* eslint-disable no-console */\nimport { readFileSync, writeFileSync } from \"fs\";\nimport { 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 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 = file.split(\"/\").slice(0, -1).join(\"/\");\n writeFileSync(parentDir + \"/mock.ts\", prettyMockSrc, { encoding: \"utf-8\" });\n return prettySrc;\n};\n"]}
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,+BAA4B;AAC5B,2DAAqC;AACrC,mDAAuD;AACvD,mCAAoG;AAEpG;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAO,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,iB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ent":["/* eslint-disable no-console */\nimport { readFileSync, writeFileSync } from \"fs\";\nimport { 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 = file.split(\"/\").slice(0, -1).join(\"/\");\n writeFileSync(parentDir + \"/mock.ts\", prettyMockSrc, { encoding: \"utf-8\" });\n return prettySrc;\n};\n"]}