@eddeee888/gcg-typescript-resolver-files 0.11.0 → 0.12.1

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.
Files changed (40) hide show
  1. package/README.md +34 -0
  2. package/package.json +8 -8
  3. package/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.js +7 -6
  4. package/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.js.map +1 -1
  5. package/src/generateResolverFiles/addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.d.ts +17 -0
  6. package/src/generateResolverFiles/addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.js +58 -0
  7. package/src/generateResolverFiles/addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.js.map +1 -0
  8. package/src/generateResolverFiles/handleGraphQLEnumType.js +2 -2
  9. package/src/generateResolverFiles/handleGraphQLEnumType.js.map +1 -1
  10. package/src/generateResolverFiles/handleGraphQLObjectType.js +2 -2
  11. package/src/generateResolverFiles/handleGraphQLObjectType.js.map +1 -1
  12. package/src/generateResolverFiles/postProcessFiles.js +45 -2
  13. package/src/generateResolverFiles/postProcessFiles.js.map +1 -1
  14. package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.d.ts +3 -1
  15. package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.js +136 -41
  16. package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.js.map +1 -1
  17. package/src/{utils → getGraphQLObjectTypeResolversToGenerate}/getNodePropertyMap.d.ts +4 -2
  18. package/src/{utils → getGraphQLObjectTypeResolversToGenerate}/getNodePropertyMap.js +11 -5
  19. package/src/getGraphQLObjectTypeResolversToGenerate/getNodePropertyMap.js.map +1 -0
  20. package/src/parseSources/parseSources.d.ts +6 -1
  21. package/src/parseSources/parseSources.js +15 -3
  22. package/src/parseSources/parseSources.js.map +1 -1
  23. package/src/parseTypeMappers/collectTypeMappersFromSourceFile.d.ts +2 -4
  24. package/src/parseTypeMappers/collectTypeMappersFromSourceFile.js +11 -39
  25. package/src/parseTypeMappers/collectTypeMappersFromSourceFile.js.map +1 -1
  26. package/src/parseTypeMappers/parseTypeMappers.d.ts +8 -6
  27. package/src/parseTypeMappers/parseTypeMappers.js +2 -4
  28. package/src/parseTypeMappers/parseTypeMappers.js.map +1 -1
  29. package/src/preset.js +19 -12
  30. package/src/preset.js.map +1 -1
  31. package/src/utils/index.d.ts +0 -1
  32. package/src/utils/index.js +0 -1
  33. package/src/utils/index.js.map +1 -1
  34. package/src/validatePresetConfig/validatePresetConfig.d.ts +6 -1
  35. package/src/validatePresetConfig/validatePresetConfig.js +28 -1
  36. package/src/validatePresetConfig/validatePresetConfig.js.map +1 -1
  37. package/src/generateResolverFiles/ensureObjectTypeResolversAreGenerated.d.ts +0 -6
  38. package/src/generateResolverFiles/ensureObjectTypeResolversAreGenerated.js +0 -86
  39. package/src/generateResolverFiles/ensureObjectTypeResolversAreGenerated.js.map +0 -1
  40. package/src/utils/getNodePropertyMap.js.map +0 -1
package/README.md CHANGED
@@ -109,6 +109,34 @@ Running codegen will generate the following files:
109
109
 
110
110
  How files are collocated. `modules` detects containing dir of a schema file as "modules", then split resolvers into those modules. `merged` treats `baseOutputDir` as the one and only module and generates resolvers.
111
111
 
112
+ ### moduleNamingMode
113
+
114
+ `last` or `first` or a number (Default: `last`)
115
+
116
+ Specifies how the plugin determines the module name for each schema file.
117
+
118
+ - **`last`**: The module name is derived from the **last** directory (within the schema directory) in the file's path.
119
+ - **`first`**: The module name is derived from the **first** directory (within the schema directory) in the file's path.
120
+ - **any number**: The module name is derived from the **nth zero-indexed** directory (within the schema directory) in the file's path. Supports negative numbers which select the **nth** directory from the back of the file's path.
121
+
122
+ For example:
123
+
124
+ #### last
125
+
126
+ - `src/schema/foo/bar/baz/User.graphql` => module name is `baz`
127
+
128
+ #### first
129
+
130
+ - `src/schema/foo/bar/baz/User.graphql` => module name is `foo`
131
+
132
+ #### 1
133
+
134
+ - `src/schema/foo/bar/baz/User.graphql` => module name is `bar`
135
+
136
+ #### -2
137
+
138
+ - `src/schema/foo/bar/baz/User.graphql` => module name is `bar`
139
+
112
140
  ### resolverTypesPath
113
141
 
114
142
  `string` (Default: `./types.generated.ts`)
@@ -328,6 +356,12 @@ Experimental options:
328
356
 
329
357
  - `namingConvention`
330
358
 
359
+ ### mappersRelativeTargetDir
360
+
361
+ `string` (Default: `./`)
362
+
363
+ By default, mappers must be siblings with the schema they represent. For example, if the schema file is `/path/to/schema.graphql`, the mapper file is `/path/to/schema.mappers.ts`. This extension allows mappers to reside in a different directory relative to the schema file using the pattern `<schemaPath>/<mappersRelativeTargetDir>/<schemaName><mappersFileExtension>`.
364
+
331
365
  ### mappersFileExtension
332
366
 
333
367
  `string` (Default: `.mappers.ts`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eddeee888/gcg-typescript-resolver-files",
3
- "version": "0.11.0",
3
+ "version": "0.12.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eddeee888/graphql-code-generator-plugins.git",
@@ -27,12 +27,12 @@
27
27
  "graphql": "^15.0.0 || ^16.0.0"
28
28
  },
29
29
  "dependencies": {
30
- "@eddeee888/gcg-server-config": "0.2.2",
31
- "@graphql-codegen/add": "^5.0.2",
32
- "@graphql-codegen/plugin-helpers": "^5.0.4",
30
+ "@eddeee888/gcg-server-config": "0.2.3",
31
+ "@graphql-codegen/add": "^5.0.3",
32
+ "@graphql-codegen/plugin-helpers": "^5.1.0",
33
33
  "@graphql-codegen/schema-ast": "^4.1.0",
34
- "@graphql-codegen/typescript": "^4.0.7",
35
- "@graphql-codegen/typescript-resolvers": "^4.4.0",
34
+ "@graphql-codegen/typescript": "^4.1.3",
35
+ "@graphql-codegen/typescript-resolvers": "^4.4.2",
36
36
  "@graphql-tools/merge": "^9.0.4",
37
37
  "@graphql-tools/utils": "^10.0.0",
38
38
  "micromatch": "^4.0.0",
@@ -42,7 +42,7 @@
42
42
  "publishConfig": {
43
43
  "directory": "../../dist/packages/typescript-resolver-files"
44
44
  },
45
+ "types": "./src/index.d.ts",
45
46
  "main": "./src/index.js",
46
- "type": "commonjs",
47
- "types": "./src/index.d.ts"
47
+ "type": "commonjs"
48
48
  }
@@ -21,26 +21,27 @@ exports.addVirtualTypesFileToTsMorphProject = addVirtualTypesFileToTsMorphProjec
21
21
  * This is used to statically detect and compare types in the parse and post-process steps
22
22
  */
23
23
  const generateVirtualTypesFile = (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ schemaAst, resolverTypesPath, resolverTypesConfig, addConfig, }) {
24
- var _b, _c, _d, _e, _f;
24
+ var _b;
25
25
  const [typescriptResult, typescriptResolversResult, addResult] = yield Promise.all([
26
26
  typeScriptPlugin.plugin(schemaAst, [], resolverTypesConfig),
27
27
  typeScriptResolversPlugin.plugin(schemaAst, [], resolverTypesConfig),
28
28
  addConfig ? addPlugin.plugin(schemaAst, [], addConfig) : '',
29
29
  ]);
30
30
  const addResultAsComplextOutput = convertPluginOutputToComplextPluginOutput(addResult);
31
+ const print = (value) => value ? value.join('\n') : '';
31
32
  return {
32
33
  filePath: resolverTypesPath,
33
34
  content: `
34
- ${(_b = addResultAsComplextOutput.prepend) === null || _b === void 0 ? void 0 : _b.join('\n')}
35
- ${(_c = typescriptResult.prepend) === null || _c === void 0 ? void 0 : _c.join('\n')}
36
- ${(_d = typescriptResolversResult.prepend) === null || _d === void 0 ? void 0 : _d.join('\n')}
35
+ ${print(addResultAsComplextOutput.prepend)}
36
+ ${print(typescriptResult.prepend)}
37
+ ${print(typescriptResolversResult.prepend)}
37
38
  ${typescriptResult.content}
38
39
  ${typescriptResolversResult.content}
39
40
  ${addResultAsComplextOutput.content}
40
- ${(_e = addResultAsComplextOutput.append) === null || _e === void 0 ? void 0 : _e.join('\n')}
41
+ ${print(addResultAsComplextOutput.append)}
41
42
  `,
42
43
  meta: {
43
- generatedResolverTypes: ((_f = typescriptResolversResult.meta) === null || _f === void 0 ? void 0 : _f.generatedResolverTypes) || {
44
+ generatedResolverTypes: ((_b = typescriptResolversResult.meta) === null || _b === void 0 ? void 0 : _b.generatedResolverTypes) || {
44
45
  resolversMap: { name: 'Resolvers' },
45
46
  userDefined: {},
46
47
  },
@@ -1 +1 @@
1
- {"version":3,"file":"addVirtualTypesFileToTsMorphProject.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.ts"],"names":[],"mappings":";;;;AACA,wEAAkD;AAElD,sFAAgE;AAChE,yGAAmF;AAM5E,MAAM,mCAAmC,GAAG,KAehD,EAAE,oDAfqD,EACxD,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,GAOV;IAIC,MAAM,SAAS,GAAG,MAAM,wBAAwB,CAAC;QAC/C,SAAS;QACT,iBAAiB;QACjB,mBAAmB;QACnB,SAAS;KACV,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,cAAc,CAAC,gBAAgB,CACrD,SAAS,CAAC,QAAQ,EAClB,SAAS,CAAC,OAAO,EACjB,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB,CAAC;IAEF,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;AACnD,CAAC,CAAA,CAAC;AA9BW,QAAA,mCAAmC,uCA8B9C;AAEF;;;GAGG;AACH,MAAM,wBAAwB,GAAG,KAc9B,EAAE,oDAdmC,EACtC,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,GAMV;;IAKC,MAAM,CAAC,gBAAgB,EAAE,yBAAyB,EAAE,SAAS,CAAC,GAC5D,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,mBAAmB,CAAC;QAC3D,yBAAyB,CAAC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AAC,CAAC"}
1
+ {"version":3,"file":"addVirtualTypesFileToTsMorphProject.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.ts"],"names":[],"mappings":";;;;AACA,wEAAkD;AAElD,sFAAgE;AAChE,yGAAmF;AAM5E,MAAM,mCAAmC,GAAG,KAehD,EAAE,oDAfqD,EACxD,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,GAOV;IAIC,MAAM,SAAS,GAAG,MAAM,wBAAwB,CAAC;QAC/C,SAAS;QACT,iBAAiB;QACjB,mBAAmB;QACnB,SAAS;KACV,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,cAAc,CAAC,gBAAgB,CACrD,SAAS,CAAC,QAAQ,EAClB,SAAS,CAAC,OAAO,EACjB,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB,CAAC;IAEF,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;AACnD,CAAC,CAAA,CAAC;AA9BW,QAAA,mCAAmC,uCA8B9C;AAEF;;;GAGG;AACH,MAAM,wBAAwB,GAAG,KAc9B,EAAE,oDAdmC,EACtC,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,GAMV;;IAKC,MAAM,CAAC,gBAAgB,EAAE,yBAAyB,EAAE,SAAS,CAAC,GAC5D,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,mBAAmB,CAAC;QAC3D,yBAAyB,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,mBAAmB,CAAC;QACpE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE;KAC5D,CAAC,CAAC;IAEL,MAAM,yBAAyB,GAC7B,yCAAyC,CAAC,SAAS,CAAC,CAAC;IAEvD,MAAM,KAAK,GAAG,CAAC,KAA2B,EAAU,EAAE,CACpD,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAEhC,OAAO;QACL,QAAQ,EAAE,iBAAiB;QAC3B,OAAO,EAAE;MACP,KAAK,CAAC,yBAAyB,CAAC,OAAO,CAAC;MACxC,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC;MAC/B,KAAK,CAAC,yBAAyB,CAAC,OAAO,CAAC;MACxC,gBAAgB,CAAC,OAAO;MACxB,yBAAyB,CAAC,OAAO;MACjC,yBAAyB,CAAC,OAAO;MACjC,KAAK,CAAC,yBAAyB,CAAC,MAAM,CAAC;KACxC;QACD,IAAI,EAAE;YACJ,sBAAsB,EAAE,CAAA,MAAA,yBAAyB,CAAC,IAAI,0CAClD,sBAAsB,KAAI;gBAC5B,YAAY,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;gBACnC,WAAW,EAAE,EAAE;aAChB;SACF;KACF,CAAC;AACJ,CAAC,CAAA,CAAC;AAEF,MAAM,yCAAyC,GAAG,CAChD,MAA0B,EACC,EAAE;IAC7B,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO;YACL,OAAO,EAAE,MAAM,IAAI,EAAE;SACtB,CAAC;IACJ,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type PropertyAssignment, type SourceFile } from 'ts-morph';
2
+ import type { ObjectTypeFile } from './types';
3
+ export type AddedPropertyAssignmentNodes = Record<string, // SourceFile's filename
4
+ Record<number, // Line number
5
+ {
6
+ node: PropertyAssignment;
7
+ resolverFile: ObjectTypeFile;
8
+ __toBeRemoved: boolean;
9
+ }>>;
10
+ /**
11
+ * Ensure objectTypeResolver files have all the resolvers due to mismatched types
12
+ */
13
+ export declare const addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented: ({ addedPropertyAssignmentNodes, sourceFile, resolverFile, }: {
14
+ addedPropertyAssignmentNodes: AddedPropertyAssignmentNodes;
15
+ sourceFile: SourceFile;
16
+ resolverFile: ObjectTypeFile;
17
+ }) => void;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented = void 0;
4
+ const ts_morph_1 = require("ts-morph");
5
+ const getVariableStatementWithExpectedIdentifier_1 = require("./getVariableStatementWithExpectedIdentifier");
6
+ /**
7
+ * Ensure objectTypeResolver files have all the resolvers due to mismatched types
8
+ */
9
+ const addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented = ({ addedPropertyAssignmentNodes, sourceFile, resolverFile, }) => {
10
+ const sourceFilePath = sourceFile.getFilePath().toString();
11
+ addedPropertyAssignmentNodes[sourceFilePath] =
12
+ addedPropertyAssignmentNodes[sourceFilePath] || {};
13
+ const resolversToGenerate = resolverFile.meta.resolversToGenerate || {};
14
+ if (!Object.keys(resolversToGenerate).length) {
15
+ return;
16
+ }
17
+ const { variableStatement } = (0, getVariableStatementWithExpectedIdentifier_1.getVariableStatementWithExpectedIdentifier)(sourceFile, resolverFile);
18
+ if (!variableStatement) {
19
+ throw new Error('Missing variableStatement in addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.');
20
+ }
21
+ // 1. Check to see which generated to-be-generated resolvers are implemented
22
+ const resolversData = Object.assign({}, resolversToGenerate);
23
+ variableStatement
24
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
25
+ .forEach((propertyAssignment) => {
26
+ const resolverName = propertyAssignment.getName();
27
+ if (resolversData[resolverName]) {
28
+ resolversData[resolverName].implemented = true;
29
+ }
30
+ });
31
+ variableStatement
32
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.MethodDeclaration)
33
+ .forEach((methodDeclaration) => {
34
+ const resolverName = methodDeclaration.getName();
35
+ if (resolversData[resolverName]) {
36
+ resolversData[resolverName].implemented = true;
37
+ }
38
+ });
39
+ // 2. Add missing resolver properties if they haven't been implemented
40
+ Object.values(resolversData).forEach(({ resolverName, resolverDeclaration, implemented }) => {
41
+ if (implemented) {
42
+ return;
43
+ }
44
+ const addedNode = variableStatement
45
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)[0]
46
+ .addPropertyAssignment({
47
+ name: resolverName,
48
+ initializer: resolverDeclaration,
49
+ });
50
+ addedPropertyAssignmentNodes[sourceFilePath][addedNode.getStartLineNumber()] = {
51
+ node: addedNode,
52
+ resolverFile,
53
+ __toBeRemoved: true,
54
+ };
55
+ });
56
+ };
57
+ exports.addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented = addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented;
58
+ //# sourceMappingURL=addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.ts"],"names":[],"mappings":";;;AAAA,uCAAgF;AAEhF,6GAA0G;AAc1G;;GAEG;AACI,MAAM,6DAA6D,GAAG,CAAC,EAC5E,4BAA4B,EAC5B,UAAU,EACV,YAAY,GAKb,EAAQ,EAAE;IACT,MAAM,cAAc,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC3D,4BAA4B,CAAC,cAAc,CAAC;QAC1C,4BAA4B,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC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C;QAED,MAAM,SAAS,GAAG,iBAAiB;aAChC,oBAAoB,CAAC,qBAAU,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;aAC3D,qBAAqB,CAAC;YACrB,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,mBAAmB;SACjC,CAAC,CAAC;QAEL,4BAA4B,CAAC,cAAc,CAAC,CAC1C,SAAS,CAAC,kBAAkB,EAAE,CAC/B,GAAG;YACF,IAAI,EAAE,SAAS;YACf,YAAY;YACZ,aAAa,EAAE,IAAI;SACpB,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAhFW,QAAA,6DAA6D,iEAgFxE"}
@@ -16,9 +16,9 @@ const handleGraphQLEnumType = ({ fieldFilePath, relativePathFromBaseToModule, re
16
16
  }
17
17
  const forcedGenerationWarning = (() => {
18
18
  if (!matchedPatternToGenerate && mapperDetails) {
19
- utils_1.logger.debug(`Enum resolver generation was NOT skipped because there is a associated mapper: "${normalizedResolverName.withModule}". "Pattern: ${resolverGeneration.enum}". Mapper: ${mapperDetails.typeMapperName}`);
19
+ utils_1.logger.debug(`Enum resolver generation was NOT skipped because there is a associated mapper: "${normalizedResolverName.withModule}". "Pattern: ${resolverGeneration.enum}". Mapper: ${mapperDetails.mapper.name}`);
20
20
  return `/*
21
- * Note: This enum file is generated because "${mapperDetails.typeMapperName}" is declared. This is to ensure runtime safety.
21
+ * Note: This enum file is generated because "${mapperDetails.mapper.name}" is declared. This is to ensure runtime safety.
22
22
  * If you want to skip this file generation, remove the mapper or update the pattern in the \`resolverGeneration.object\` config.
23
23
  */\n`;
24
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"handleGraphQLEnumType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLEnumType.ts"],"names":[],"mappings":";;;AAAA,oCAA+E;AAGxE,MAAM,qBAAqB,GAG9B,CACF,EACE,aAAa,EACb,4BAA4B,EAC5B,YAAY,EACZ,yBAAyB,E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GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;IAClE,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG;QAC5B,UAAU,EAAE,cAAc;QAC1B,UAAU,EAAE;YACV,IAAI,EAAE,SAAS;YACf,cAAc,EAAE,KAAK;SACtB;QACD,OAAO,EAAE;MACP,6BAA6B;MAC7B,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,UAAU;YACV,4BAA4B;YAC5B,6BAA6B;YAC7B,iBAAiB;YACjB,YAAY,EAAE;gBACZ,UAAU,EAAE,iBAAiB,CAAC,eAAe;gBAC7C,KAAK,EAAE,iBAAiB,CAAC,UAAU;aACpC;YACD,sBAAsB;YACtB,aAAa;SACd;KACF,CAAC;AACJ,CAAC,CAAC;AAtFW,QAAA,qBAAqB,yBAsFhC"}
1
+ {"version":3,"file":"handleGraphQLEnumType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLEnumType.ts"],"names":[],"mappings":";;;AAAA,oCAA+E;AAGxE,MAAM,qBAAqB,GAG9B,CACF,EACE,aAAa,EACb,4BAA4B,EAC5B,YAAY,EACZ,yBAAyB,EACzB,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,aAAa,GACd,EACD,EACE,MAAM,EACN,MAAM,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,GAC1E,EACD,EAAE;IACF,MAAM,wBAAwB,GAAG,IAAA,kCAA0B,EAAC;QAC1D,OAAO,EAAE,kBAAkB,CAAC,IAAI;QAChC,KAAK,EAAE,sBAAsB,CAAC,UAAU;KACzC,CAAC,CAAC;IACH,MAAM,aAAa,GAAG,cAAc,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAElE,IACE,CAAC,wBAAwB;QACzB,CAA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YACV,4BAA4B;YAC5B,6BAA6B;YAC7B,iBAAiB;YACjB,YAAY,EAAE;gBACZ,UAAU,EAAE,iBAAiB,CAAC,eAAe;gBAC7C,KAAK,EAAE,iBAAiB,CAAC,UAAU;aACpC;YACD,sBAAsB;YACtB,aAAa;SACd;KACF,CAAC;AACJ,CAAC,CAAC;AAtFW,QAAA,qBAAqB,yBAsFhC"}
@@ -18,9 +18,9 @@ generatedTypesFileMeta, }, { result, config: { resolverGeneration, typeMappersMa
18
18
  }
19
19
  const forcedGenerationWarning = (() => {
20
20
  if (!matchedPatternToGenerate && mapperDetails) {
21
- utils_1.logger.debug(`Object resolver generation was NOT skipped because there is a associated mapper: "${normalizedResolverName.withModule}". "Pattern: ${resolverGeneration.object}". Mapper: ${mapperDetails.typeMapperName}`);
21
+ utils_1.logger.debug(`Object resolver generation was NOT skipped because there is a associated mapper: "${normalizedResolverName.withModule}". "Pattern: ${resolverGeneration.object}". Mapper: ${mapperDetails.mapper.name}`);
22
22
  return `/*
23
- * Note: This object type is generated because "${mapperDetails.typeMapperName}" is declared. This is to ensure runtime safety.
23
+ * Note: This object type is generated because "${mapperDetails.mapper.name}" is declared. This is to ensure runtime safety.
24
24
  *
25
25
  * When a mapper is used, it is possible to hit runtime errors in some scenarios:
26
26
  * - given a field name, the schema type's field type does not match mapper's field type
@@ -1 +1 @@
1
- {"version":3,"file":"handleGraphQLObjectType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLObjectType.ts"],"names":[],"mappings":";;;AACA,oCAA+E;AAExE,MAAM,uBAAuB,GAKhC,CACF,EACE,aAAa,EACb,YAAY,EACZ,yBAAyB,EACzB,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,4BAA4B,EAC5B,YAAY,GAAG,EAAE,EAAE,kFAAkF;AACrG,sBAAsB,GACvB,EACD,EACE,MAAM,EACN,MAAM,EAAE,EACN,kBAAkB,EAClB,cAAc,EACd,oCAAoC,EACpC,yBAA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E,iBAAiB,CAAC,MAAM;QAChC,UAAU,EAAE,iBAAiB,CAAC,UAAU;QACxC,YAAY,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC;QACjD,yBAAyB;KAC1B,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG;QAC5B,UAAU,EAAE,YAAY;QACxB,UAAU,EAAE;YACV,IAAI,EAAE,SAAS;YACf,cAAc,EAAE,KAAK;SACtB;QACD,OAAO,EAAE;MACP,6BAA6B;MAC7B,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,UAAU;YACV,4BAA4B;YAC5B,sBAAsB;YACtB,6BAA6B;YAC7B,iBAAiB;YACjB,YAAY,EAAE;gBACZ,UAAU,EAAE,iBAAiB,CAAC,eAAe;gBAC7C,KAAK,EAAE,UAAU;gBACjB,aAAa,EAAE,uBAAuB;aACvC;YACD,mBAAmB;SACpB;KACF,CAAC;AACJ,CAAC,CAAC;AA5JW,QAAA,uBAAuB,2BA4JlC"}
1
+ {"version":3,"file":"handleGraphQLObjectType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLObjectType.ts"],"names":[],"mappings":";;;AACA,oCAA+E;AAExE,MAAM,uBAAuB,GAKhC,CACF,EACE,aAAa,EACb,YAAY,EACZ,yBAAyB,EACzB,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,4BAA4B,EAC5B,YAAY,GAAG,EAAE,EAAE,kFAAkF;AACrG,sBAAsB,GACvB,EACD,EACE,MAAM,EACN,MAAM,EAAE,EACN,kBAAkB,EAClB,cAAc,EACd,oCAAoC,EACpC,yBAAyB,GAC1B,GACF,EACD,EAAE;;IACF,MAAM,wBAAwB,GAAG,IAAA,kCAA0B,EAAC;QAC1D,OAAO,EAAE,kBAAkB,CAAC,MAAM;QAClC,KAAK,EAAE,sBAAsB,CAAC,UAAU;KACzC,CAAC,CAAC;IACH,MAAM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,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG;QAC5B,UAAU,EAAE,YAAY;QACxB,UAAU,EAAE;YACV,IAAI,EAAE,SAAS;YACf,cAAc,EAAE,KAAK;SACtB;QACD,OAAO,EAAE;MACP,6BAA6B;MAC7B,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,UAAU;YACV,4BAA4B;YAC5B,sBAAsB;YACtB,6BAA6B;YAC7B,iBAAiB;YACjB,YAAY,EAAE;gBACZ,UAAU,EAAE,iBAAiB,CAAC,eAAe;gBAC7C,KAAK,EAAE,UAAU;gBACjB,aAAa,EAAE,uBAAuB;aACvC;YACD,mBAAmB;SACpB;KACF,CAAC;AACJ,CAAC,CAAC;AA5JW,QAAA,uBAAuB,2BA4JlC"}
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const path = tslib_1.__importStar(require("path"));
6
6
  const utils_1 = require("../utils");
7
7
  const getVariableStatementWithExpectedIdentifier_1 = require("./getVariableStatementWithExpectedIdentifier");
8
- const ensureObjectTypeResolversAreGenerated_1 = require("./ensureObjectTypeResolversAreGenerated");
8
+ const addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented_1 = require("./addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented");
9
9
  const ensureEnumTypeResolversAreGenerated_1 = require("./ensureEnumTypeResolversAreGenerated");
10
10
  const getImportStatementWithExpectedNamedImport_1 = require("./getImportStatementWithExpectedNamedImport");
11
11
  /**
@@ -16,6 +16,7 @@ const getImportStatementWithExpectedNamedImport_1 = require("./getImportStatemen
16
16
  */
17
17
  const postProcessFiles = ({ config: { tsMorph: { project }, fixObjectTypeResolvers, }, result, }) => {
18
18
  const sourceFilesToProcess = [];
19
+ // 1. Load resolver files into ts-morph project so we can run static analysis
19
20
  Object.entries(result.files).forEach(([filePath, file]) => {
20
21
  if (file.__filetype === 'file') {
21
22
  return;
@@ -41,6 +42,9 @@ const postProcessFiles = ({ config: { tsMorph: { project }, fixObjectTypeResolve
41
42
  });
42
43
  }
43
44
  });
45
+ // `addedPropertyAssignmentNodes` is used to store added property assignments in object types
46
+ // these property assigments are to be removed if there's no TypeScript error
47
+ const addedPropertyAssignmentNodes = {};
44
48
  sourceFilesToProcess.forEach(({ sourceFile, resolverFile }) => {
45
49
  const normalizedRelativePath = path.posix.relative((0, utils_1.cwd)(), sourceFile.getFilePath());
46
50
  const { addedVariableStatement } = ensureExportedResolver(sourceFile, resolverFile);
@@ -52,7 +56,11 @@ const postProcessFiles = ({ config: { tsMorph: { project }, fixObjectTypeResolve
52
56
  }
53
57
  if (fixObjectTypeResolvers.object === 'smart' &&
54
58
  resolverFile.__filetype === 'objectType') {
55
- (0, ensureObjectTypeResolversAreGenerated_1.ensureObjectTypeResolversAreGenerated)(sourceFile, resolverFile);
59
+ (0, addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented_1.addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented)({
60
+ addedPropertyAssignmentNodes,
61
+ sourceFile,
62
+ resolverFile,
63
+ });
56
64
  }
57
65
  if (fixObjectTypeResolvers.enum === 'smart' &&
58
66
  resolverFile.__filetype === 'enumResolver') {
@@ -61,6 +69,41 @@ const postProcessFiles = ({ config: { tsMorph: { project }, fixObjectTypeResolve
61
69
  // Overwrite existing files with fixes
62
70
  result.files[normalizedRelativePath] = Object.assign(Object.assign({}, resolverFile), { content: sourceFile.getText() });
63
71
  });
72
+ // 3. ensure object type's added property assignments are removed if there's no related TypeScript error
73
+ // We do this only once at the project level instead of sourceFile level to speed up the process
74
+ if (fixObjectTypeResolvers.object === 'smart') {
75
+ project.getPreEmitDiagnostics().forEach((d) => {
76
+ var _a;
77
+ const filename = (_a = d.getSourceFile()) === null || _a === void 0 ? void 0 : _a.getFilePath().toString();
78
+ if (!filename || !addedPropertyAssignmentNodes[filename]) {
79
+ return;
80
+ }
81
+ const lineNumberWithError = d.getLineNumber();
82
+ // If erroring on a recently added line, do not remove as user needs to implement it
83
+ if (lineNumberWithError &&
84
+ addedPropertyAssignmentNodes[filename][lineNumberWithError]) {
85
+ addedPropertyAssignmentNodes[filename][lineNumberWithError].__toBeRemoved = false;
86
+ }
87
+ });
88
+ Object.values(addedPropertyAssignmentNodes).forEach((addedNodes) => {
89
+ Object.values(addedNodes).forEach(({ node, resolverFile, __toBeRemoved }) => {
90
+ if (__toBeRemoved) {
91
+ node.remove();
92
+ }
93
+ else {
94
+ // If found a property assignment that cannot be removed i.e. incompatible types between mapper vs schema types
95
+ // Then we must mark the content as updated to be added to generate list
96
+ resolverFile.filesystem.contentUpdated = true;
97
+ }
98
+ });
99
+ });
100
+ }
101
+ // 4. Apply to result files the updated content done in step 2. and 3. above
102
+ sourceFilesToProcess.forEach(({ sourceFile, resolverFile }) => {
103
+ const normalizedRelativePath = path.posix.relative((0, utils_1.cwd)(), sourceFile.getFilePath());
104
+ // Overwrite existing files with fixes
105
+ result.files[normalizedRelativePath] = Object.assign(Object.assign({}, resolverFile), { content: sourceFile.getText() });
106
+ });
64
107
  };
65
108
  exports.postProcessFiles = postProcessFiles;
66
109
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"postProcessFiles.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/postProcessFiles.ts"],"names":[],"mappings":";;;;AACA,mDAA6B;AAC7B,oCAA+B;AAE/B,6GAA0G;AAC1G,mGAAgG;AAChG,+FAA4F;AAC5F,2GAAwG;AAExG;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,EAC/B,MAAM,EAAE,EACN,OAAO,EAAE,EAAE,OAAO,EAAE,EACpB,sBAAsB,GACvB,EACD,MAAM,GACuB,EAAQ,EAAE;IACvC,MAAM,oBAAoB,GAGpB,EAAE,CAAC;IACT,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;QACxD,IAAI,IAAI,CAAC,U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AAI,CAAC,iBAAiB,CAAC,CAAC;QAC9D,YAAY,CAAC,UAAU,CAAC,cAAc,GAAG,IAAI,CAAC;QAE9C,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,CAAC;IAC1C,CAAC;SAAM,IAAI,iBAAiB,IAAI,CAAC,UAAU,EAAE,CAAC;QAC5C,qCAAqC;QACrC,kCAAkC;QAClC,MAAM,4BAA4B,GAAG,OAAO,CAC1C,UAAU;aACP,uBAAuB,EAAE;aACzB,GAAG,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAC1C,CAAC;QACF,IAAI,CAAC,4BAA4B,EAAE,CAAC;YAClC,iBAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YACtC,YAAY,CAAC,UAAU,CAAC,cAAc,GAAG,IAAI,CAAC;QAChD,CAAC;QACD,iDAAiD;QACjD,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,CAAC;IAC3C,CAAC;IAED,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,CAAC;AAC3C,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAAG,CACzB,UAAsB,EACtB,YAA0B,EACpB,EAAE;IACR,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAA,qFAAyC,EACrE,UAAU,EACV,YAAY,CACb,CAAC;IAEF,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,UAAU,CAAC,gBAAgB,CACzB,CAAC,EACD,YAAY,CAAC,IAAI,CAAC,6BAA6B,CAChD,CAAC;QACF,YAAY,CAAC,UAAU,CAAC,cAAc,GAAG,IAAI,CAAC;IAChD,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"postProcessFiles.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/postProcessFiles.ts"],"names":[],"mappings":";;;;AACA,mDAA6B;AAC7B,oCAA+B;AAE/B,6GAA0G;AAC1G,mJAGyE;AACzE,+FAA4F;AAC5F,2GAAwG;AAEx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sB,EAAE,KAAK,EAAE,CAAC;IAC3C,CAAC;IAED,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,CAAC;AAC3C,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAAG,CACzB,UAAsB,EACtB,YAA0B,EACpB,EAAE;IACR,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAA,qFAAyC,EACrE,UAAU,EACV,YAAY,CACb,CAAC;IAEF,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,UAAU,CAAC,gBAAgB,CACzB,CAAC,EACD,YAAY,CAAC,IAAI,CAAC,6BAA6B,CAChD,CAAC;QACF,YAAY,CAAC,UAAU,CAAC,cAAc,GAAG,IAAI,CAAC;IAChD,CAAC;AACH,CAAC,CAAC"}
@@ -1,13 +1,15 @@
1
1
  import { type SourceFile, type Project } from 'ts-morph';
2
2
  import type { TypeMappersMap } from '../parseTypeMappers';
3
3
  import type { ParsedGraphQLSchemaMeta } from '../parseGraphQLSchema';
4
+ import type { GeneratedTypesFileMeta } from '../generateResolverFiles';
4
5
  export type GraphQLObjectTypeResolversToGenerate = Record<string, Record<string, {
5
6
  resolverName: string;
6
7
  resolverDeclaration: string;
7
8
  }>>;
8
- export declare const getGraphQLObjectTypeResolversToGenerate: ({ tsMorphProject, typesSourceFile, userDefinedSchemaObjectTypeMap, typeMappersMap, }: {
9
+ export declare const getGraphQLObjectTypeResolversToGenerate: ({ tsMorphProject, typesSourceFile, typeMappersMap, userDefinedSchemaObjectTypeMap, generatedTypesFileMeta, }: {
9
10
  tsMorphProject: Project;
10
11
  typesSourceFile: SourceFile;
11
12
  typeMappersMap: TypeMappersMap;
12
13
  userDefinedSchemaObjectTypeMap: ParsedGraphQLSchemaMeta["userDefinedSchemaTypeMap"]["object"];
14
+ generatedTypesFileMeta: GeneratedTypesFileMeta;
13
15
  }) => GraphQLObjectTypeResolversToGenerate;
@@ -2,19 +2,42 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getGraphQLObjectTypeResolversToGenerate = void 0;
4
4
  const ts_morph_1 = require("ts-morph");
5
- const utils_1 = require("../utils");
6
- const getGraphQLObjectTypeResolversToGenerate = ({ tsMorphProject, typesSourceFile, userDefinedSchemaObjectTypeMap, typeMappersMap, }) => {
5
+ const getNodePropertyMap_1 = require("./getNodePropertyMap");
6
+ const getGraphQLObjectTypeResolversToGenerate = ({ tsMorphProject, typesSourceFile, typeMappersMap, userDefinedSchemaObjectTypeMap, generatedTypesFileMeta, }) => {
7
7
  const typeMappersEntries = Object.entries(typeMappersMap);
8
8
  if (typeMappersEntries.length === 0) {
9
9
  return {};
10
10
  }
11
+ /**
12
+ * `generatedTypesFileMeta.generatedResolverTypes.userDefined` is `schemaType` -> `generatedResolverTypes`
13
+ * We will be parsing `types.generated.ts` file for the `generatedResolverTypes`
14
+ * So, we need to invert `generatedTypesFileMeta.generatedResolverTypes.userDefined` to get `generatedResolverTypes` -> `schemaType`
15
+ * e.g.
16
+ *
17
+ * generatedTypesFileMeta.generatedResolverTypes.userDefined = {
18
+ * User: {
19
+ * name: 'UserResolvers'
20
+ * }
21
+ * }
22
+ *
23
+ * after transformation:
24
+ *
25
+ * generatedSchemaTypeNameMap = {
26
+ * UserResolvers: 'User'
27
+ * }
28
+ */
29
+ const generatedSchemaTypeNameMap = Object.entries(generatedTypesFileMeta.generatedResolverTypes.userDefined).reduce((res, [schemaType, generatedSchemaTypeName]) => {
30
+ res[generatedSchemaTypeName.name] = schemaType;
31
+ return res;
32
+ }, {});
11
33
  // 1. Get property map of all schema types
12
- const schemaTypePropertyMap = {};
13
- const populateSchemaTypePropertyMap = (node) => {
34
+ const schemaResolversTypePropertyMap = {};
35
+ const populateSchemaTypeResolversPropertyMap = (node) => {
14
36
  const identifier = node.getNameNode();
15
37
  const identifierName = identifier.getText();
16
- if (userDefinedSchemaObjectTypeMap[identifierName]) {
17
- schemaTypePropertyMap[identifierName] = (0, utils_1.getNodePropertyMap)({
38
+ const schemaType = generatedSchemaTypeNameMap[identifierName];
39
+ if (schemaType && userDefinedSchemaObjectTypeMap[schemaType]) {
40
+ schemaResolversTypePropertyMap[schemaType] = (0, getNodePropertyMap_1.getNodePropertyMap)({
18
41
  tsMorphProject,
19
42
  node,
20
43
  });
@@ -22,52 +45,124 @@ const getGraphQLObjectTypeResolversToGenerate = ({ tsMorphProject, typesSourceFi
22
45
  };
23
46
  typesSourceFile
24
47
  .getDescendantsOfKind(ts_morph_1.SyntaxKind.TypeAliasDeclaration)
25
- .forEach(populateSchemaTypePropertyMap);
48
+ .forEach(populateSchemaTypeResolversPropertyMap);
26
49
  typesSourceFile
27
50
  .getDescendantsOfKind(ts_morph_1.SyntaxKind.InterfaceDeclaration)
28
- .forEach(populateSchemaTypePropertyMap);
51
+ .forEach(populateSchemaTypeResolversPropertyMap);
29
52
  // 3. Find resolvers to generate and add reason
30
53
  const result = {};
31
- typeMappersEntries.forEach(([_, { schemaType, typeMapperName, typeMapperPropertyMap }]) => {
32
- const matchedSchemaTypePropertyMap = schemaTypePropertyMap[schemaType];
33
- if (matchedSchemaTypePropertyMap) {
34
- Object.values(matchedSchemaTypePropertyMap).forEach((schemaTypeProperty) => {
35
- const typeMapperProperty = typeMapperPropertyMap[schemaTypeProperty.name];
36
- const typeMapperPropertyIdentifier = `${typeMapperName}.${schemaTypeProperty.name}`;
37
- const schemaTypePropertyIdentifier = `${schemaType}.${schemaTypeProperty.name}`;
38
- if (schemaTypeProperty.name === '__typename') {
39
- return;
40
- }
41
- result[schemaType] = result[schemaType] || {};
42
- // If mapper does not have a field in schema type, report
43
- if (!typeMapperProperty) {
44
- result[schemaType][schemaTypeProperty.name] = {
45
- resolverName: schemaTypeProperty.name,
46
- resolverDeclaration: `async (_parent, _arg, _ctx) => { /* ${schemaTypePropertyIdentifier} resolver is required because ${schemaTypePropertyIdentifier} exists but ${typeMapperPropertyIdentifier} does not */ }`,
47
- };
48
- return;
49
- }
50
- /**
51
- * FIXME: there's currently no way to check if a type is assignable to another type
52
- * https://github.com/dsherret/ts-morph/issues/357
53
- * https://github.com/microsoft/TypeScript/issues/9879
54
- *
55
- * Therefore, the workaround now is to generate all resolvers with matching names, then use TS diagnostics to see if there's error when trying to merge the two keys
56
- *
57
- * Note: this happens only when mappers are used
58
- */
54
+ typeMappersEntries.forEach(([_, { schemaType, mapper }]) => {
55
+ const matchedSchemaTypePropertyMap = schemaResolversTypePropertyMap[schemaType];
56
+ if (!matchedSchemaTypePropertyMap) {
57
+ return;
58
+ }
59
+ const originalDeclarationNode = mustGetMapperOriginalDeclarationNode({
60
+ tsMorphProject,
61
+ mapper,
62
+ });
63
+ const typeMapperPropertyMap = (0, getNodePropertyMap_1.getNodePropertyMap)({
64
+ tsMorphProject,
65
+ node: originalDeclarationNode,
66
+ });
67
+ Object.values(matchedSchemaTypePropertyMap).forEach((schemaTypeProperty) => {
68
+ const typeMapperProperty = typeMapperPropertyMap[schemaTypeProperty.name];
69
+ const typeMapperPropertyIdentifier = `${mapper.name}.${schemaTypeProperty.name}`;
70
+ const schemaTypePropertyIdentifier = `${schemaType}.${schemaTypeProperty.name}`;
71
+ // Generated resolvers types may have one or more of these meta resolvers
72
+ // A mapper would most likely never have these resolvers, so we skip them
73
+ // Otherwise, these resolvers will always be generated
74
+ const metaResolvers = {
75
+ __isTypeOf: true,
76
+ __resolveReference: true,
77
+ };
78
+ if (metaResolvers[schemaTypeProperty.name]) {
79
+ return;
80
+ }
81
+ result[schemaType] = result[schemaType] || {};
82
+ // If mapper does not have a field in schema type, add missing resolver
83
+ if (!typeMapperProperty) {
59
84
  result[schemaType][schemaTypeProperty.name] = {
60
85
  resolverName: schemaTypeProperty.name,
61
- resolverDeclaration: `({ ${schemaTypeProperty.name} }, _arg, _ctx) => {
86
+ resolverDeclaration: `async (_parent, _arg, _ctx) => { /* ${schemaTypePropertyIdentifier} resolver is required because ${schemaTypePropertyIdentifier} exists but ${typeMapperPropertyIdentifier} does not */ }`,
87
+ };
88
+ return;
89
+ }
90
+ /**
91
+ * FIXME: TypeScript's `isTypeAssignableTo` should be used to check if the mapper type vs resolver return type is compatible.
92
+ * The current challenge is to:
93
+ * - Switch from using the schema type to resolver return type e.g. `User` -> `UserResolver`
94
+ * - Take the ReturnType of the resolver function type e.g. `Resolver<ResolversTypes['UserRole'], ParentType, ContextType>`
95
+ *
96
+ * For now, the workaround now is to generate all resolvers with matching names,
97
+ * then use TS diagnostics to see if there's error when trying to merge the two keys.
98
+ *
99
+ * Note: this happens only when mappers are used
100
+ */
101
+ result[schemaType][schemaTypeProperty.name] = {
102
+ resolverName: schemaTypeProperty.name,
103
+ resolverDeclaration: `({ ${schemaTypeProperty.name} }, _arg, _ctx) => {
62
104
  /* ${schemaTypePropertyIdentifier} resolver is required because ${schemaTypePropertyIdentifier} and ${typeMapperPropertyIdentifier} are not compatible */
63
105
  return ${schemaTypeProperty.name}
64
106
  }`,
65
- };
66
- return;
67
- });
68
- }
107
+ };
108
+ return;
109
+ });
69
110
  });
70
111
  return result;
71
112
  };
72
113
  exports.getGraphQLObjectTypeResolversToGenerate = getGraphQLObjectTypeResolversToGenerate;
114
+ const mustGetMapperOriginalDeclarationNode = ({ tsMorphProject, mapper, }) => {
115
+ const typeMapperFile = tsMorphProject.getSourceFile(mapper.filename);
116
+ if (!typeMapperFile) {
117
+ throw new Error(`Unable to find ${typeMapperFile} file after parsing. This shouldn't happen.`);
118
+ }
119
+ /**
120
+ * Finding `firstDescendantThatIsMapper` here is a bit of the duplicated traversing logic in `collectTypeMappersFromSourceFile`.
121
+ * However, in `collectTypeMappersFromSourceFile`, we find the mappers details.
122
+ * And here, we actually do look for the mapper nodes and run analysis on it.
123
+ *
124
+ * Previously, we were parsing the node property map in `collectTypeMappersFromSourceFile`
125
+ * but for some reason `isAssignableTo` has issue comparing types, so we have to move the static analysis here for now.
126
+ */
127
+ const firstDescendantThatIsMapper = (() => {
128
+ for (const descendant of typeMapperFile.getDescendants()) {
129
+ const typedNode = descendant.isKind(mapper.kind);
130
+ if (typedNode) {
131
+ let identifierNode = descendant.getNameNode();
132
+ if (descendant.isKind(ts_morph_1.SyntaxKind.ExportSpecifier)) {
133
+ const aliasNode = descendant.getAliasNode();
134
+ if (aliasNode) {
135
+ identifierNode = aliasNode;
136
+ }
137
+ }
138
+ if ((identifierNode === null || identifierNode === void 0 ? void 0 : identifierNode.getText()) === mapper.name) {
139
+ return {
140
+ declarationNode: descendant,
141
+ identifierNode,
142
+ };
143
+ }
144
+ }
145
+ }
146
+ return;
147
+ })();
148
+ if (!firstDescendantThatIsMapper) {
149
+ throw new Error(`Unable to find ${mapper.name} node after parsing. This shouldn't happen.`);
150
+ }
151
+ return getOriginalDeclarationNode(firstDescendantThatIsMapper);
152
+ };
153
+ const getOriginalDeclarationNode = ({ declarationNode, identifierNode, }) => {
154
+ if (declarationNode.isKind(ts_morph_1.SyntaxKind.ExportSpecifier) ||
155
+ declarationNode.isKind(ts_morph_1.SyntaxKind.ClassDeclaration)) {
156
+ return identifierNode.getDefinitionNodes()[0];
157
+ }
158
+ // InterfaceDeclaration
159
+ if (declarationNode.isKind(ts_morph_1.SyntaxKind.InterfaceDeclaration)) {
160
+ return declarationNode;
161
+ }
162
+ // TypeAliasDeclaration
163
+ const typeNode = declarationNode.getTypeNodeOrThrow();
164
+ return ts_morph_1.Node.isTypeReference(typeNode)
165
+ ? identifierNode.getDefinitionNodes()[0] // If type alias is a reference, go to definition using `getDefinitionNodes`
166
+ : declarationNode;
167
+ };
73
168
  //# sourceMappingURL=getGraphQLObjectTypeResolversToGenerate.js.map