@trackunit/react-graphql-tools 0.0.31 → 0.0.32
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,8 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.0.32](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.31...react-graphql-tools/0.0.32) (2023-10-05)
|
|
6
|
+
|
|
5
7
|
## [0.0.31](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.30...react-graphql-tools/0.0.31) (2023-10-04)
|
|
6
8
|
|
|
7
9
|
## [0.0.30](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.29...react-graphql-tools/0.0.30) (2023-10-04)
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@ const generateMockFromType = (type) => {
|
|
|
23
23
|
if (type.getText() === "number") {
|
|
24
24
|
return faker_1.faker.datatype.number();
|
|
25
25
|
}
|
|
26
|
-
if (type.getText() === "Date") {
|
|
26
|
+
if (type.getText() === "Date" || type.getText() === "DateTime" || type.getText() === "DateTimeISOString") {
|
|
27
27
|
return "2023-01-22T15:08:12.527Z";
|
|
28
28
|
}
|
|
29
29
|
if (type.isUnion()) {
|
|
@@ -1 +1 @@
|
|
|
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,EAAO,EAAE;IAC9C,aAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEhB,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;QAC1B,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,sCAAsC;KACvE;IACD,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;QAC1B,OAAO,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;KAC5C;IACD,IAAI,IAAI,CAAC,gBAAgB,EAAE,EAAE;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,MAAM,CAAC;KAC3C;IAED,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,QAAQ,EAAE;QAC/B,OAAO,aAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;KAC5B;IACD,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,QAAQ,EAAE;QAC/B,OAAO,aAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;KAChC;IACD,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE;
|
|
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,EAAO,EAAE;IAC9C,aAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEhB,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;QAC1B,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,sCAAsC;KACvE;IACD,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;QAC1B,OAAO,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;KAC5C;IACD,IAAI,IAAI,CAAC,gBAAgB,EAAE,EAAE;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,MAAM,CAAC;KAC3C;IAED,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,QAAQ,EAAE;QAC/B,OAAO,aAAK,CAAC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zB,OAAO,EAAE;aACT,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;;YAEnD,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;+BAC5C,MAAM,CAAC,OAAO,EAAE;;MAEzC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;;;;;;IAML,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;GAChB,CAAC;AACJ,CAAC,CAAA,CAAC;AAjDW,QAAA,oBAAoB,wBAiD/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): any => {\n faker.seed(123);\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.random.word();\n }\n if (type.getText() === \"number\") {\n return faker.datatype.number();\n }\n if (type.getText() === \"Date\" || type.getText() === \"DateTime\" || type.getText() === \"DateTimeISOString\") {\n return \"2023-01-22T15:08:12.527Z\";\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 propType = prop.getValueDeclarationOrThrow().getType();\n if (prop.getName() === \"__typename\") {\n obj[prop.getName()] = propType.getText().replace(/\"/g, \"\");\n } else {\n obj[prop.getName()] = generateMockFromType(propType);\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 });\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 return `\n \n export const mockFor${mocker.getName()} = (variables: gql.${mocker.getName()}Variables, data?: DeepPartialNullable<gql.${mocker.getName()}> ) => {\n return queryFor(gql.${mocker\n .getName()\n .substring(0, mocker.getName().length - \"Query\".length)}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-api/graphql\";\n \n ${mock.join(\"\\n\")}\n `;\n};\n"]}
|