@eddeee888/gcg-typescript-resolver-files 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +191 -30
  2. package/package.json +5 -5
  3. package/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.d.ts +8 -0
  4. package/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.js +35 -0
  5. package/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.js.map +1 -0
  6. package/src/addVirtualTypesFileToTsMorphProject/index.d.ts +1 -0
  7. package/src/addVirtualTypesFileToTsMorphProject/index.js +5 -0
  8. package/src/addVirtualTypesFileToTsMorphProject/index.js.map +1 -0
  9. package/src/defineConfig.d.ts +5 -0
  10. package/src/defineConfig.js +19 -0
  11. package/src/defineConfig.js.map +1 -0
  12. package/src/generateResolverFiles/addExternalResolverImport.d.ts +1 -0
  13. package/src/generateResolverFiles/addExternalResolverImport.js +1 -0
  14. package/src/generateResolverFiles/addExternalResolverImport.js.map +1 -1
  15. package/src/generateResolverFiles/addResolverMainFile.d.ts +4 -1
  16. package/src/generateResolverFiles/addResolverMainFile.js +71 -50
  17. package/src/generateResolverFiles/addResolverMainFile.js.map +1 -1
  18. package/src/generateResolverFiles/ensureObjectTypeResolversAreGenerated.d.ts +6 -0
  19. package/src/generateResolverFiles/ensureObjectTypeResolversAreGenerated.js +80 -0
  20. package/src/generateResolverFiles/ensureObjectTypeResolversAreGenerated.js.map +1 -0
  21. package/src/generateResolverFiles/generateResolverFiles.js +3 -3
  22. package/src/generateResolverFiles/generateResolverFiles.js.map +1 -1
  23. package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.d.ts +6 -0
  24. package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.js +27 -0
  25. package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.js.map +1 -0
  26. package/src/generateResolverFiles/handleGraphQLObjectType.js +6 -2
  27. package/src/generateResolverFiles/handleGraphQLObjectType.js.map +1 -1
  28. package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.js +9 -2
  29. package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.js.map +1 -1
  30. package/src/generateResolverFiles/handleGraphQLScalarType.js +2 -1
  31. package/src/generateResolverFiles/handleGraphQLScalarType.js.map +1 -1
  32. package/src/generateResolverFiles/handleGraphQLUninionType.js +2 -1
  33. package/src/generateResolverFiles/handleGraphQLUninionType.js.map +1 -1
  34. package/src/generateResolverFiles/postProcessFiles.d.ts +8 -0
  35. package/src/generateResolverFiles/postProcessFiles.js +73 -0
  36. package/src/generateResolverFiles/postProcessFiles.js.map +1 -0
  37. package/src/generateResolverFiles/types.d.ts +19 -3
  38. package/src/generateResolverFiles/visitNamedType.js +28 -11
  39. package/src/generateResolverFiles/visitNamedType.js.map +1 -1
  40. package/src/generateTypeDefsFiles/generateTypeDefsContent.js.map +1 -0
  41. package/src/generateTypeDefsFiles/generateTypeDefsFiles.d.ts +13 -0
  42. package/src/generateTypeDefsFiles/generateTypeDefsFiles.js +60 -0
  43. package/src/generateTypeDefsFiles/generateTypeDefsFiles.js.map +1 -0
  44. package/src/generateTypeDefsFiles/index.d.ts +1 -0
  45. package/src/{generateTypeDefsContent → generateTypeDefsFiles}/index.js +1 -1
  46. package/src/{generateTypeDefsContent → generateTypeDefsFiles}/index.js.map +1 -1
  47. package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.d.ts +11 -0
  48. package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.js +70 -0
  49. package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.js.map +1 -0
  50. package/src/getGraphQLObjectTypeResolversToGenerate/index.d.ts +1 -0
  51. package/src/getGraphQLObjectTypeResolversToGenerate/index.js +5 -0
  52. package/src/getGraphQLObjectTypeResolversToGenerate/index.js.map +1 -0
  53. package/src/index.d.ts +1 -0
  54. package/src/index.js +3 -1
  55. package/src/index.js.map +1 -1
  56. package/src/parseGraphQLSchema/index.d.ts +1 -0
  57. package/src/{getPluginsConfig → parseGraphQLSchema}/index.js +1 -1
  58. package/src/parseGraphQLSchema/index.js.map +1 -0
  59. package/src/parseGraphQLSchema/parseGraphQLSchema.d.ts +16 -0
  60. package/src/{getPluginsConfig/getPluginsConfig.js → parseGraphQLSchema/parseGraphQLSchema.js} +15 -10
  61. package/src/parseGraphQLSchema/parseGraphQLSchema.js.map +1 -0
  62. package/src/parseSources/parseSources.d.ts +0 -1
  63. package/src/parseSources/parseSources.js +2 -3
  64. package/src/parseSources/parseSources.js.map +1 -1
  65. package/src/parseTypeMappers/collectTypeMappersFromSourceFile.d.ts +3 -2
  66. package/src/parseTypeMappers/collectTypeMappersFromSourceFile.js +51 -10
  67. package/src/parseTypeMappers/collectTypeMappersFromSourceFile.js.map +1 -1
  68. package/src/parseTypeMappers/parseTypeMappers.d.ts +7 -2
  69. package/src/parseTypeMappers/parseTypeMappers.js +10 -8
  70. package/src/parseTypeMappers/parseTypeMappers.js.map +1 -1
  71. package/src/preset.d.ts +2 -1
  72. package/src/preset.js +90 -44
  73. package/src/preset.js.map +1 -1
  74. package/src/utils/cwd.d.ts +4 -0
  75. package/src/utils/cwd.js +12 -0
  76. package/src/utils/cwd.js.map +1 -0
  77. package/src/utils/getNodePropertyMap.d.ts +9 -0
  78. package/src/utils/getNodePropertyMap.js +57 -0
  79. package/src/utils/getNodePropertyMap.js.map +1 -0
  80. package/src/utils/index.d.ts +5 -2
  81. package/src/utils/index.js +5 -16
  82. package/src/utils/index.js.map +1 -1
  83. package/src/utils/isRootObjectType.d.ts +1 -1
  84. package/src/utils/isWhitelistedModule.d.ts +5 -0
  85. package/src/utils/isWhitelistedModule.js +16 -0
  86. package/src/utils/isWhitelistedModule.js.map +1 -0
  87. package/src/utils/normalizeRelativePath.d.ts +1 -0
  88. package/src/utils/normalizeRelativePath.js +11 -0
  89. package/src/utils/normalizeRelativePath.js.map +1 -0
  90. package/src/utils/parseLocationForWhitelistedModule.js +7 -9
  91. package/src/utils/parseLocationForWhitelistedModule.js.map +1 -1
  92. package/src/utils/relativeModulePath.d.ts +1 -0
  93. package/src/utils/relativeModulePath.js +11 -0
  94. package/src/utils/relativeModulePath.js.map +1 -0
  95. package/src/validatePresetConfig/validatePresetConfig.d.ts +23 -4
  96. package/src/validatePresetConfig/validatePresetConfig.js +57 -17
  97. package/src/validatePresetConfig/validatePresetConfig.js.map +1 -1
  98. package/src/generateResolverFiles/fixExistingResolvers.d.ts +0 -2
  99. package/src/generateResolverFiles/fixExistingResolvers.js +0 -62
  100. package/src/generateResolverFiles/fixExistingResolvers.js.map +0 -1
  101. package/src/generateTypeDefsContent/generateTypeDefsContent.js.map +0 -1
  102. package/src/generateTypeDefsContent/index.d.ts +0 -1
  103. package/src/getPluginsConfig/getPluginsConfig.d.ts +0 -13
  104. package/src/getPluginsConfig/getPluginsConfig.js.map +0 -1
  105. package/src/getPluginsConfig/index.d.ts +0 -1
  106. package/src/getPluginsConfig/index.js.map +0 -1
  107. /package/src/{generateTypeDefsContent → generateTypeDefsFiles}/generateTypeDefsContent.d.ts +0 -0
  108. /package/src/{generateTypeDefsContent → generateTypeDefsFiles}/generateTypeDefsContent.js +0 -0
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateTypeDefsFiles = void 0;
4
+ const path = require("path");
5
+ const utils_1 = require("../utils");
6
+ const generateTypeDefsContent_1 = require("./generateTypeDefsContent");
7
+ const generateTypeDefsFiles = ({ baseOutputDir, typeDefsFilePath, typeDefsFileMode, sourceMap, blacklistedModules, whitelistedModules, }) => {
8
+ const filesContent = {};
9
+ Object.values(sourceMap).forEach(({ moduleName, source, sourcePath }) => {
10
+ const isWhitelisted = (0, utils_1.isWhitelistedModule)({
11
+ moduleName,
12
+ whitelistedModules,
13
+ blacklistedModules,
14
+ });
15
+ if (typeDefsFileMode === 'merged') {
16
+ appendSDLToFile({
17
+ filesContent,
18
+ filePath: path.posix.join(baseOutputDir, typeDefsFilePath),
19
+ rawSDL: source.rawSDL,
20
+ });
21
+ return;
22
+ }
23
+ if (isWhitelisted && typeDefsFileMode === 'mergedWhitelisted') {
24
+ appendSDLToFile({
25
+ filesContent,
26
+ filePath: path.posix.join(baseOutputDir, typeDefsFilePath),
27
+ rawSDL: source.rawSDL,
28
+ });
29
+ return;
30
+ }
31
+ if (isWhitelisted && typeDefsFileMode === 'modules') {
32
+ appendSDLToFile({
33
+ filesContent,
34
+ filePath: path.posix.join(sourcePath.dir, typeDefsFilePath),
35
+ rawSDL: source.rawSDL,
36
+ });
37
+ return;
38
+ }
39
+ });
40
+ const result = {};
41
+ Object.entries(filesContent).forEach(([filePath, content]) => {
42
+ result[filePath] = {
43
+ __filetype: 'file',
44
+ content: (0, generateTypeDefsContent_1.generateTypeDefsContent)({ mergedSDL: content }),
45
+ mainImportIdentifier: 'typeDefs',
46
+ };
47
+ });
48
+ return result;
49
+ };
50
+ exports.generateTypeDefsFiles = generateTypeDefsFiles;
51
+ const appendSDLToFile = ({ rawSDL, filePath, filesContent, }) => {
52
+ if (!rawSDL) {
53
+ return;
54
+ }
55
+ if (!filesContent[filePath]) {
56
+ filesContent[filePath] = '';
57
+ }
58
+ filesContent[filePath] += `${rawSDL}\n`;
59
+ };
60
+ //# sourceMappingURL=generateTypeDefsFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateTypeDefsFiles.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateTypeDefsFiles/generateTypeDefsFiles.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAG7B,oCAA+C;AAE/C,uEAAoE;AAW7D,MAAM,qBAAqB,GAAG,CAAC,EACpC,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,kBAAkB,GACU,EAAgC,EA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DAAuB,EAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;YACxD,oBAAoB,EAAE,UAAU;SACjC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAtDW,QAAA,qBAAqB,yBAsDhC;AAEF,MAAM,eAAe,GAAG,CAAC,EACvB,MAAM,EACN,QAAQ,EACR,YAAY,GAKb,EAAQ,EAAE;IACT,IAAI,CAAC,MAAM,EAAE;QACX,OAAO;KACR;IAED,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE;QAC3B,YAAY,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;KAC7B;IACD,YAAY,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC;AAC1C,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './generateTypeDefsFiles';
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./generateTypeDefsContent"), exports);
4
+ tslib_1.__exportStar(require("./generateTypeDefsFiles"), exports);
5
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateTypeDefsContent/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateTypeDefsFiles/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC"}
@@ -0,0 +1,11 @@
1
+ import { type SourceFile } from 'ts-morph';
2
+ import type { TypeMappersMap } from '../parseTypeMappers';
3
+ export type GraphQLObjectTypeResolversToGenerate = Record<string, Record<string, {
4
+ resolverName: string;
5
+ resolverDeclaration: string;
6
+ }>>;
7
+ export declare const getGraphQLObjectTypeResolversToGenerate: ({ typesSourceFile, userDefinedSchemaTypeMap, typeMappersMap, }: {
8
+ typesSourceFile: SourceFile;
9
+ typeMappersMap: TypeMappersMap;
10
+ userDefinedSchemaTypeMap: Record<string, true>;
11
+ }) => GraphQLObjectTypeResolversToGenerate;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGraphQLObjectTypeResolversToGenerate = void 0;
4
+ const ts_morph_1 = require("ts-morph");
5
+ const utils_1 = require("../utils");
6
+ const getGraphQLObjectTypeResolversToGenerate = ({ typesSourceFile, userDefinedSchemaTypeMap, typeMappersMap, }) => {
7
+ const typeMappersEntries = Object.entries(typeMappersMap);
8
+ if (typeMappersEntries.length === 0) {
9
+ return {};
10
+ }
11
+ // 1. Get property map of all schema types
12
+ const schemaTypePropertyMap = {};
13
+ const populateSchemaTypePropertyMap = (node) => {
14
+ const identifier = node.getNameNode();
15
+ const identifierName = identifier.getText();
16
+ if (userDefinedSchemaTypeMap[identifierName]) {
17
+ schemaTypePropertyMap[identifierName] = (0, utils_1.getNodePropertyMap)(node);
18
+ }
19
+ };
20
+ typesSourceFile
21
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.TypeAliasDeclaration)
22
+ .forEach(populateSchemaTypePropertyMap);
23
+ typesSourceFile
24
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.InterfaceDeclaration)
25
+ .forEach(populateSchemaTypePropertyMap);
26
+ // 3. Find resolvers to generate and add reason
27
+ const result = {};
28
+ typeMappersEntries.forEach(([_, { schemaType, typeMapperName, typeMapperPropertyMap }]) => {
29
+ const matchedSchemaTypePropertyMap = schemaTypePropertyMap[schemaType];
30
+ if (matchedSchemaTypePropertyMap) {
31
+ Object.values(matchedSchemaTypePropertyMap).forEach((schemaTypeProperty) => {
32
+ const typeMapperProperty = typeMapperPropertyMap[schemaTypeProperty.name];
33
+ const typeMapperPropertyIdentifier = `${typeMapperName}.${schemaTypeProperty.name}`;
34
+ const schemaTypePropertyIdentifier = `${schemaType}.${schemaTypeProperty.name}`;
35
+ if (schemaTypeProperty.name === '__typename') {
36
+ return;
37
+ }
38
+ result[schemaType] = result[schemaType] || {};
39
+ // If mapper does not have a field in schema type, report
40
+ if (!typeMapperProperty) {
41
+ result[schemaType][schemaTypeProperty.name] = {
42
+ resolverName: schemaTypeProperty.name,
43
+ resolverDeclaration: `() => { /* ${schemaTypePropertyIdentifier} resolver is required because ${schemaTypePropertyIdentifier} exists but ${typeMapperPropertyIdentifier} does not */ }`,
44
+ };
45
+ return;
46
+ }
47
+ /**
48
+ * FIXME: there's currently no way to check if a type is assignable to another type
49
+ * https://github.com/dsherret/ts-morph/issues/357
50
+ * https://github.com/microsoft/TypeScript/issues/9879
51
+ *
52
+ * 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
53
+ *
54
+ * Note: this happens only when mappers are used
55
+ */
56
+ result[schemaType][schemaTypeProperty.name] = {
57
+ resolverName: schemaTypeProperty.name,
58
+ resolverDeclaration: `({ ${schemaTypeProperty.name} }) => {
59
+ /* ${schemaTypePropertyIdentifier} resolver is required because ${schemaTypePropertyIdentifier} and ${typeMapperPropertyIdentifier} are not compatible */
60
+ return ${schemaTypeProperty.name}
61
+ }`,
62
+ };
63
+ return;
64
+ });
65
+ }
66
+ });
67
+ return result;
68
+ };
69
+ exports.getGraphQLObjectTypeResolversToGenerate = getGraphQLObjectTypeResolversToGenerate;
70
+ //# sourceMappingURL=getGraphQLObjectTypeResolversToGenerate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getGraphQLObjectTypeResolversToGenerate.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.ts"],"names":[],"mappings":";;;AAAA,uCAKkB;AAElB,oCAAoE;AAO7D,MAAM,uCAAuC,GAAG,CAAC,EACtD,eAAe,EACf,wBAAwB,EACxB,cAAc,GAKf,EAAwC,EAAE;IACzC,MAAM,kBAAkB,GAAG,MAA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,CAAC,IAAI,EAAE,CAAC;gBAEhF,IAAI,kBAAkB,CAAC,IAAI,KAAK,YAAY,EAAE;oBAC5C,OAAO;iBACR;gBAED,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;gBAE9C,yDAAyD;gBACzD,IAAI,CAAC,kBAAkB,EAAE;oBACvB,MAAM,CAAC,UAAU,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG;wBAC5C,YAAY,EAAE,kBAAkB,CAAC,IAAI;wBACrC,mBAAmB,EAAE,cAAc,4BAA4B,iCAAiC,4BAA4B,eAAe,4BAA4B,gBAAgB;qBACxL,CAAC;oBACF,OAAO;iBACR;gBAED;;;;;;;;mBAQG;gBACH,MAAM,CAAC,UAAU,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG;oBAC5C,YAAY,EAAE,kBAAkB,CAAC,IAAI;oBACrC,mBAAmB,EAAE,MAAM,kBAAkB,CAAC,IAAI;qBAC3C,4BAA4B,iCAAiC,4BAA4B,QAAQ,4BAA4B;yBACzH,kBAAkB,CAAC,IAAI;gBAChC;iBACH,CAAC;gBAEF,OAAO;YACT,CAAC,CACF,CAAC;SACH;IACH,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAvFW,QAAA,uCAAuC,2CAuFlD"}
@@ -0,0 +1 @@
1
+ export * from './getGraphQLObjectTypeResolversToGenerate';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./getGraphQLObjectTypeResolversToGenerate"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/getGraphQLObjectTypeResolversToGenerate/index.ts"],"names":[],"mappings":";;;AAAA,oFAA0D"}
package/src/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { preset } from './preset';
2
+ export { defineConfig } from './defineConfig';
package/src/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.preset = void 0;
3
+ exports.defineConfig = exports.preset = void 0;
4
4
  var preset_1 = require("./preset");
5
5
  Object.defineProperty(exports, "preset", { enumerable: true, get: function () { return preset_1.preset; } });
6
+ var defineConfig_1 = require("./defineConfig");
7
+ Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return defineConfig_1.defineConfig; } });
6
8
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/typescript-resolver-files/src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/typescript-resolver-files/src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,+CAA8C;AAArC,4GAAA,YAAY,OAAA"}
@@ -0,0 +1 @@
1
+ export * from './parseGraphQLSchema';
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./getPluginsConfig"), exports);
4
+ tslib_1.__exportStar(require("./parseGraphQLSchema"), exports);
5
5
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseGraphQLSchema/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC"}
@@ -0,0 +1,16 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ import type { ParseSourcesResult } from '../parseSources';
3
+ import type { TypeMappersMap } from '../parseTypeMappers';
4
+ interface GetPluginsConfigParams {
5
+ schemaAst: GraphQLSchema;
6
+ sourceMap: ParseSourcesResult['sourceMap'];
7
+ typeMappersMap: TypeMappersMap;
8
+ whitelistedModules: string[];
9
+ blacklistedModules: string[];
10
+ }
11
+ type GetPluginsConfigResult = {
12
+ userDefinedSchemaTypeMap: Record<string, true>;
13
+ pluginsConfig: Record<'defaultScalarTypesMap' | 'defaultScalarExternalResolvers' | 'defaultTypeMappers', Record<string, string>>;
14
+ };
15
+ export declare const parseGraphQLSchema: ({ schemaAst, sourceMap, typeMappersMap, whitelistedModules, blacklistedModules, }: GetPluginsConfigParams) => GetPluginsConfigResult;
16
+ export {};
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPluginsConfig = void 0;
3
+ exports.parseGraphQLSchema = void 0;
4
4
  const graphql_1 = require("graphql");
5
5
  const graphql_scalars_1 = require("graphql-scalars");
6
6
  const utils_1 = require("../utils");
7
- const getPluginsConfig = ({ schemaAst, sourceMap, typeMappersMap, whitelistedModules, blacklistedModules, }) => {
7
+ const parseGraphQLSchema = ({ schemaAst, sourceMap, typeMappersMap, whitelistedModules, blacklistedModules, }) => {
8
8
  return Object.entries(schemaAst.getTypeMap()).reduce((res, [schemaType, namedType]) => {
9
9
  var _a;
10
10
  if ((0, utils_1.isNativeNamedType)(namedType)) {
@@ -23,20 +23,25 @@ const getPluginsConfig = ({ schemaAst, sourceMap, typeMappersMap, whitelistedMod
23
23
  handleScalarType(schemaType, res);
24
24
  }
25
25
  if (!(0, utils_1.isRootObjectType)(schemaType) && (0, graphql_1.isObjectType)(namedType)) {
26
+ res.userDefinedSchemaTypeMap[schemaType] = true;
27
+ // Wire up `mappers` config
26
28
  const typeMapperDetails = typeMappersMap[schemaType];
27
29
  if (typeMapperDetails) {
28
- res.defaultTypeMappers[typeMapperDetails.schemaType] =
30
+ res.pluginsConfig.defaultTypeMappers[typeMapperDetails.schemaType] =
29
31
  typeMapperDetails.configImportPath;
30
32
  }
31
33
  }
32
34
  return res;
33
35
  }, {
34
- defaultScalarTypesMap: {},
35
- defaultScalarExternalResolvers: {},
36
- defaultTypeMappers: {},
36
+ userDefinedSchemaTypeMap: {},
37
+ pluginsConfig: {
38
+ defaultScalarTypesMap: {},
39
+ defaultScalarExternalResolvers: {},
40
+ defaultTypeMappers: {},
41
+ },
37
42
  });
38
43
  };
39
- exports.getPluginsConfig = getPluginsConfig;
44
+ exports.parseGraphQLSchema = parseGraphQLSchema;
40
45
  const handleScalarType = (schemaType, result) => {
41
46
  const scalarResolver = graphql_scalars_1.resolvers[schemaType];
42
47
  if (!scalarResolver) {
@@ -44,9 +49,9 @@ const handleScalarType = (schemaType, result) => {
44
49
  }
45
50
  if (scalarResolver.extensions.codegenScalarType &&
46
51
  typeof scalarResolver.extensions.codegenScalarType === 'string') {
47
- result.defaultScalarTypesMap[schemaType] =
52
+ result.pluginsConfig.defaultScalarTypesMap[schemaType] =
48
53
  scalarResolver.extensions.codegenScalarType;
49
54
  }
50
- result.defaultScalarExternalResolvers[schemaType] = `~graphql-scalars#${scalarResolver.name}Resolver`;
55
+ result.pluginsConfig.defaultScalarExternalResolvers[schemaType] = `~graphql-scalars#${scalarResolver.name}Resolver`;
51
56
  };
52
- //# sourceMappingURL=getPluginsConfig.js.map
57
+ //# sourceMappingURL=parseGraphQLSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseGraphQLSchema.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseGraphQLSchema/parseGraphQLSchema.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,qDAA+D;AAG/D,oCAIkB;AAoBX,MAAM,kBAAkB,GAAG,CAAC,EACjC,SAAS,EACT,SAAS,EACT,cAAc,EACd,kBAAkB,EAClB,kBAAkB,GACK,EAA0B,EAAE;IACnD,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC,MAAM,CAClD,CAAC,GAAG,EAAE,CAAC,UAAU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UAAU,CAAC,iBAAiB;QAC3C,OAAO,cAAc,CAAC,UAAU,CAAC,iBAAiB,KAAK,QAAQ,EAC/D;QACA,MAAM,CAAC,aAAa,CAAC,qBAAqB,CAAC,UAAU,CAAC;YACpD,cAAc,CAAC,UAAU,CAAC,iBAAiB,CAAC;KAC/C;IAED,MAAM,CAAC,aAAa,CAAC,8BAA8B,CACjD,UAAU,CACX,GAAG,oBAAoB,cAAc,CAAC,IAAI,UAAU,CAAC;AACxD,CAAC,CAAC"}
@@ -8,6 +8,5 @@ export interface ParsedSource {
8
8
  }
9
9
  export interface ParseSourcesResult {
10
10
  sourceMap: Record<string, ParsedSource>;
11
- mergedSDL: string;
12
11
  }
13
12
  export declare function parseSources(sources: Source[]): ParseSourcesResult;
@@ -9,15 +9,14 @@ function parseSources(sources) {
9
9
  }
10
10
  const sourcePath = path.parse(source.location);
11
11
  const moduleDir = sourcePath.dir;
12
- const [moduleName] = moduleDir.split(path.sep).slice(-1);
12
+ const moduleName = path.basename(moduleDir);
13
13
  result.sourceMap[source.location] = {
14
14
  source,
15
15
  sourcePath,
16
16
  moduleName,
17
17
  };
18
- result.mergedSDL += `\n${source.rawSDL}`;
19
18
  return result;
20
- }, { sourceMap: {}, mergedSDL: '' });
19
+ }, { sourceMap: {} });
21
20
  }
22
21
  exports.parseSources = parseSources;
23
22
  //# sourceMappingURL=parseSources.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseSources.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseSources/parseSources.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAc7B,SAAgB,YAAY,CAAC,OAAiB;IAC5C,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QACjB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC5C;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC;QAEjC,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAEzD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG;YAClC,MAAM;YACN,UAAU;YACV,UAAU;SACX,CAAC;QAEF,MAAM,CAAC,SAAS,IAAI,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;QAEzC,OAAO,MAAM,CAAC;IAChB,CAAC,EACD,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CACjC,CAAC;AACJ,CAAC;AAxBD,oCAwBC"}
1
+ {"version":3,"file":"parseSources.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseSources/parseSources.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAa7B,SAAgB,YAAY,CAAC,OAAiB;IAC5C,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QACjB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC5C;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC;QAEjC,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAE5C,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG;YAClC,MAAM;YACN,UAAU;YACV,UAAU;SACX,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC,EACD,EAAE,SAAS,EAAE,EAAE,EAAE,CAClB,CAAC;AACJ,CAAC;AAtBD,oCAsBC"}
@@ -1,7 +1,8 @@
1
- import type { SourceFile } from 'ts-morph';
1
+ import { type SourceFile } from 'ts-morph';
2
2
  import type { TypeMappersMap } from './parseTypeMappers';
3
- export declare const collectTypeMappersFromSourceFile: ({ typeMappersSourceFile, typeMappersSuffix, resolverTypesPath, }: {
3
+ export declare const collectTypeMappersFromSourceFile: ({ typeMappersSourceFile, typeMappersSuffix, resolverTypesPath, shouldCollectPropertyMap, }: {
4
4
  typeMappersSourceFile: SourceFile;
5
5
  typeMappersSuffix: string;
6
6
  resolverTypesPath: string;
7
+ shouldCollectPropertyMap: boolean;
7
8
  }, result: TypeMappersMap) => void;
@@ -2,18 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.collectTypeMappersFromSourceFile = void 0;
4
4
  const path = require("path");
5
+ const ts_morph_1 = require("ts-morph");
5
6
  const utils_1 = require("../utils");
6
- const collectTypeMappersFromSourceFile = ({ typeMappersSourceFile, typeMappersSuffix, resolverTypesPath, }, result) => {
7
+ const collectTypeMappersFromSourceFile = ({ typeMappersSourceFile, typeMappersSuffix, resolverTypesPath, shouldCollectPropertyMap, }, result) => {
7
8
  // Look for interfaces with exported keywords
8
9
  typeMappersSourceFile.getInterfaces().forEach((interfaceDeclaration) => {
9
10
  if (!interfaceDeclaration.hasExportKeyword()) {
10
11
  return;
11
12
  }
12
13
  addTypeMapperDetailsIfValid({
13
- identifierName: interfaceDeclaration.getName(),
14
+ declarationNode: interfaceDeclaration,
15
+ identifierNode: interfaceDeclaration.getNameNode(),
14
16
  typeMappersSuffix,
15
17
  typeMappersFilePath: typeMappersSourceFile.getFilePath(),
16
18
  resolverTypesPath,
19
+ shouldCollectPropertyMap,
17
20
  }, result);
18
21
  });
19
22
  // Look for exported types with exported keywords
@@ -21,35 +24,41 @@ const collectTypeMappersFromSourceFile = ({ typeMappersSourceFile, typeMappersSu
21
24
  if (!typeAlias.hasExportKeyword()) {
22
25
  return;
23
26
  }
27
+ const identifierNode = typeAlias.getNameNode();
24
28
  addTypeMapperDetailsIfValid({
25
- identifierName: typeAlias.getName(),
29
+ declarationNode: typeAlias,
30
+ identifierNode,
26
31
  typeMappersSuffix,
27
32
  typeMappersFilePath: typeMappersSourceFile.getFilePath(),
28
33
  resolverTypesPath,
34
+ shouldCollectPropertyMap,
29
35
  }, result);
30
36
  });
31
37
  // Look for named exports e.g.
32
38
  // - export { something } from 'module';
33
39
  // - export type { something } from 'module';
34
- // - export { something, somethingelse }'
40
+ // - export { something, somethingelse as somethingelse2 }'
35
41
  typeMappersSourceFile.getExportDeclarations().forEach((exportDeclaration) => {
36
42
  exportDeclaration.getNamedExports().forEach((namedExport) => {
37
- let identifierName = namedExport.getFullText();
43
+ let identifierNode = namedExport.getNameNode();
38
44
  const aliasNode = namedExport.getAliasNode();
39
45
  if (aliasNode) {
40
- identifierName = aliasNode.getFullText();
46
+ identifierNode = aliasNode;
41
47
  }
42
48
  addTypeMapperDetailsIfValid({
43
- identifierName: identifierName.trim(),
49
+ declarationNode: null,
50
+ identifierNode,
44
51
  typeMappersSuffix,
45
52
  typeMappersFilePath: typeMappersSourceFile.getFilePath(),
46
53
  resolverTypesPath,
54
+ shouldCollectPropertyMap,
47
55
  }, result);
48
56
  });
49
57
  });
50
58
  };
51
59
  exports.collectTypeMappersFromSourceFile = collectTypeMappersFromSourceFile;
52
- const addTypeMapperDetailsIfValid = ({ identifierName, typeMappersSuffix, typeMappersFilePath, resolverTypesPath, }, result) => {
60
+ const addTypeMapperDetailsIfValid = ({ declarationNode, identifierNode, typeMappersSuffix, typeMappersFilePath, resolverTypesPath, shouldCollectPropertyMap, }, result) => {
61
+ const identifierName = identifierNode.getText();
53
62
  if (!identifierName.endsWith(typeMappersSuffix)) {
54
63
  return;
55
64
  }
@@ -57,16 +66,48 @@ const addTypeMapperDetailsIfValid = ({ identifierName, typeMappersSuffix, typeMa
57
66
  if (!schemaType) {
58
67
  return;
59
68
  }
60
- const parsedRelativePathFromResolverTypesToSourceFile = path.parse(path.relative(path.dirname(resolverTypesPath), typeMappersFilePath));
61
- const relativeImportPathFromResolverTypesToSourceFile = (0, utils_1.normalizeRelativePath)(path.join(parsedRelativePathFromResolverTypesToSourceFile.dir, parsedRelativePathFromResolverTypesToSourceFile.name));
69
+ /**
70
+ * We MUST use path.relative() instead of path.posix.relative() here
71
+ * Reason being `typeMappersFilePath` is a file system path e.g. C://Windows/Path/To/File or /Unix/path/to/file
72
+ * path.relative works correctly but returns inconsistent path seperator e.g. relative\\path\\windows or relative/path/unix
73
+ *
74
+ * Therefore, we need to split/join to normalise the path to posix path e.g relative/path/unix
75
+ */
76
+ const relativePath = path
77
+ .relative(path.dirname(resolverTypesPath), typeMappersFilePath)
78
+ .split(path.sep)
79
+ .join(path.posix.sep);
80
+ const parsedRelativePathFromResolverTypesToSourceFile = path.parse(relativePath);
81
+ const relativeImportPathFromResolverTypesToSourceFile = (0, utils_1.normalizeRelativePath)(path.posix.join(parsedRelativePathFromResolverTypesToSourceFile.dir, parsedRelativePathFromResolverTypesToSourceFile.name));
62
82
  const configImportPath = `${relativeImportPathFromResolverTypesToSourceFile}#${identifierName}`;
63
83
  if (result[schemaType]) {
64
84
  throw new Error(`GraphQL type "${schemaType}" has duplicated "${identifierName}" mappers:\n - ${configImportPath}\n - ${result[schemaType].configImportPath}`);
65
85
  }
86
+ let typeMapperPropertyMap = {};
87
+ if (shouldCollectPropertyMap) {
88
+ const originalDeclarationNode = getOriginalDeclarationNode(declarationNode, identifierNode);
89
+ typeMapperPropertyMap = (0, utils_1.getNodePropertyMap)(originalDeclarationNode);
90
+ }
66
91
  result[schemaType] = {
67
92
  schemaType,
68
93
  typeMapperName: identifierName,
94
+ typeMapperPropertyMap,
69
95
  configImportPath,
70
96
  };
71
97
  };
98
+ const getOriginalDeclarationNode = (declarationNode, identifierNode) => {
99
+ if (!declarationNode) {
100
+ return identifierNode.getDefinitionNodes()[0];
101
+ }
102
+ // InterfaceDeclaration
103
+ if (declarationNode.isKind(ts_morph_1.SyntaxKind.InterfaceDeclaration)) {
104
+ return declarationNode;
105
+ }
106
+ // TypeAliasDeclaration
107
+ const typeNode = declarationNode.getTypeNodeOrThrow();
108
+ const node = ts_morph_1.Node.isTypeReference(typeNode) // If type alias is a reference, go to definition using `getDefinitionNodes`
109
+ ? identifierNode.getDefinitionNodes()[0]
110
+ : declarationNode;
111
+ return node;
112
+ };
72
113
  //# sourceMappingURL=collectTypeMappersFromSourceFile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"collectTypeMappersFromSourceFile.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseTypeMappers/collectTypeMappersFromSourceFile.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAE7B,oCAAiD;AAG1C,MAAM,gCAAgC,GAAG,CAC9C,EACE,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,GAKlB,EACD,MAAsB,EAChB,EAAE;IACR,6CAA6C;IAC7C,qBAAqB,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,CAAC,oBAAoB,EAAE,EAAE;QACrE,IAAI,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,EAAE;YAC5C,OAAO;SACR;QAED,2BAA2B,CACzB;YACE,cAAc,EAAE,oBAAoB,CAAC,OAAO,EAAE;YAC9C,iBAAiB;YACjB,mBAAmB,EAAE,qBAAqB,CAAC,WAAW,EAAE;YACxD,iBAAiB;SAClB,EACD,MAAM,CACP,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,iDAAiD;IACjD,qBAAqB,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QAC3D,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,EAAE;YACjC,OAAO;SACR;QAED,2BAA2B,CACzB;YACE,cAAc,EAAE,SAAS,CAAC,OAAO,EAAE;YACnC,iBAAiB;YACjB,mBAAmB,EAAE,qBAAqB,CAAC,WAAW,EAAE;YACxD,iBAAiB;SAClB,EACD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AI,CAAC,IAAI,CACP,+CAA+C,CAAC,GAAG,EACnD,+CAA+C,CAAC,IAAI,CACrD,CACF,CAAC;IAEF,MAAM,gBAAgB,GAAG,GAAG,+CAA+C,IAAI,cAAc,EAAE,CAAC;IAEhG,IAAI,MAAM,CAAC,UAAU,CAAC,EAAE;QACtB,MAAM,IAAI,KAAK,CACb,iBAAiB,UAAU,qBAAqB,cAAc,mBAAmB,gBAAgB,SAAS,MAAM,CAAC,UAAU,CAAC,CAAC,gBAAgB,EAAE,CAChJ,CAAC;KACH;IAED,MAAM,CAAC,UAAU,CAAC,GAAG;QACnB,UAAU;QACV,cAAc,EAAE,cAAc;QAC9B,gBAAgB;KACjB,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"collectTypeMappersFromSourceFile.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseTypeMappers/collectTypeMappersFromSourceFile.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,uCAOkB;AAClB,oCAAqE;AAG9D,MAAM,gCAAgC,GAAG,CAC9C,EACE,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,GAMzB,EACD,MAAsB,EAChB,EAAE;IACR,6CAA6C;IAC7C,qBAAqB,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,CAAC,oBAAoB,EAAE,EAAE;QACrE,IAAI,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,EAAE;YAC5C,OAAO;SACR;QAED,2BAA2B,CACzB;YACE,eAAe,EAAE,oBAAoB;YACrC,cAAc,EAAE,oBAAoB,CAAC,WAAW,EAAE;YAClD,iBAAiB;YACjB,mBAAmB,EAAE,qBAAqB,CAAC,WAAW,EAAE;YACxD,iBAAiB;YACjB,wBAAwB;SACzB,EACD,MAAM,CACP,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,iDAAiD;IACjD,qBAAqB,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;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,EACpB,EAAE;IACR,IAAI,CAAC,eAAe,EAAE;QACpB,OAAO,cAAc,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,CAAC;KAC/C;IAED,uBAAuB;IACvB,IAAI,eAAe,CAAC,MAAM,CAAC,qBAAU,CAAC,oBAAoB,CAAC,EAAE;QAC3D,OAAO,eAAe,CAAC;KACxB;IAED,uBAAuB;IACvB,MAAM,QAAQ,GAAG,eAAe,CAAC,kBAAkB,EAAE,CAAC;IACtD,MAAM,IAAI,GAAG,eAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,4EAA4E;QACtH,CAAC,CAAC,cAAc,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC;QACxC,CAAC,CAAC,eAAe,CAAC;IACpB,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -1,14 +1,19 @@
1
+ import { Project } from 'ts-morph';
1
2
  import type { ParseSourcesResult } from '../parseSources';
3
+ import type { NodePropertyMap } from '../utils';
2
4
  export interface ParseTypeMappersParams {
3
5
  sourceMap: ParseSourcesResult['sourceMap'];
4
6
  resolverTypesPath: string;
5
7
  typeMappersFileExtension: string;
6
8
  typeMappersSuffix: string;
9
+ tsMorphProject: Project;
10
+ shouldCollectPropertyMap: boolean;
7
11
  }
8
12
  export interface TypeMapperDetails {
9
13
  schemaType: string;
10
14
  typeMapperName: string;
15
+ typeMapperPropertyMap: NodePropertyMap;
11
16
  configImportPath: string;
12
17
  }
13
- export declare type TypeMappersMap = Record<string, TypeMapperDetails>;
14
- export declare const parseTypeMappers: ({ sourceMap, resolverTypesPath, typeMappersFileExtension, typeMappersSuffix, }: ParseTypeMappersParams) => TypeMappersMap;
18
+ export type TypeMappersMap = Record<string, TypeMapperDetails>;
19
+ export declare const parseTypeMappers: ({ sourceMap, resolverTypesPath, typeMappersFileExtension, typeMappersSuffix, tsMorphProject, shouldCollectPropertyMap, }: ParseTypeMappersParams) => TypeMappersMap;
@@ -2,18 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseTypeMappers = void 0;
4
4
  const path = require("path");
5
- const fs = require("fs");
6
- const ts_morph_1 = require("ts-morph");
7
5
  const collectTypeMappersFromSourceFile_1 = require("./collectTypeMappersFromSourceFile");
8
- const parseTypeMappers = ({ sourceMap, resolverTypesPath, typeMappersFileExtension, typeMappersSuffix, }) => {
6
+ const parseTypeMappers = ({ sourceMap, resolverTypesPath, typeMappersFileExtension, typeMappersSuffix, tsMorphProject, shouldCollectPropertyMap, }) => {
9
7
  const result = Object.entries(sourceMap).reduce((res, [_, { sourcePath }]) => {
10
- const typeMapperFilePath = path.join(sourcePath.dir, `${sourcePath.name}${typeMappersFileExtension}`);
11
- if (!fs.existsSync(typeMapperFilePath)) {
8
+ const typeMapperFilePath = path.posix.join(sourcePath.dir, `${sourcePath.name}${typeMappersFileExtension}`);
9
+ const typeMappersSourceFile = tsMorphProject.addSourceFileAtPathIfExists(typeMapperFilePath);
10
+ if (!typeMappersSourceFile) {
12
11
  return res;
13
12
  }
14
- const project = new ts_morph_1.Project();
15
- const [typeMappersSourceFile] = project.addSourceFilesAtPaths(typeMapperFilePath);
16
- (0, collectTypeMappersFromSourceFile_1.collectTypeMappersFromSourceFile)({ typeMappersSourceFile, typeMappersSuffix, resolverTypesPath }, res);
13
+ (0, collectTypeMappersFromSourceFile_1.collectTypeMappersFromSourceFile)({
14
+ typeMappersSourceFile,
15
+ typeMappersSuffix,
16
+ resolverTypesPath,
17
+ shouldCollectPropertyMap,
18
+ }, res);
17
19
  return res;
18
20
  }, {});
19
21
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"parseTypeMappers.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseTypeMappers/parseTypeMappers.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,yBAAyB;AACzB,uCAAmC;AAEnC,yFAAsF;AAiB/E,MAAM,gBAAgB,GAAG,CAAC,EAC/B,SAAS,EACT,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GACM,EAAkB,EAAE;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAC7C,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE;QAC3B,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAClC,UAAU,CAAC,GAAG,EACd,GAAG,UAAU,CAAC,IAAI,GAAG,wBAAwB,EAAE,CAChD,CAAC;QAEF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;YACtC,OAAO,GAAG,CAAC;SACZ;QAED,MAAM,OAAO,GAAG,IAAI,kBAAO,EAAE,CAAC;QAC9B,MAAM,CAAC,qBAAqB,CAAC,GAC3B,OAAO,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;QAEpD,IAAA,mEAAgC,EAC9B,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,EAC/D,GAAG,CACJ,CAAC;QAEF,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA/BW,QAAA,gBAAgB,oBA+B3B"}
1
+ {"version":3,"file":"parseTypeMappers.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseTypeMappers/parseTypeMappers.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAI7B,yFAAsF;AAoB/E,MAAM,gBAAgB,GAAG,CAAC,EAC/B,SAAS,EACT,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,cAAc,EACd,wBAAwB,GACD,EAAkB,EAAE;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAC7C,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE;QAC3B,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CACxC,UAAU,CAAC,GAAG,EACd,GAAG,UAAU,CAAC,IAAI,GAAG,wBAAwB,EAAE,CAChD,CAAC;QAEF,MAAM,qBAAqB,GACzB,cAAc,CAAC,2BAA2B,CAAC,kBAAkB,CAAC,CAAC;QAEjE,IAAI,CAAC,qBAAqB,EAAE;YAC1B,OAAO,GAAG,CAAC;SACZ;QAED,IAAA,mEAAgC,EAC9B;YACE,qBAAqB;YACrB,iBAAiB;YACjB,iBAAiB;YACjB,wBAAwB;SACzB,EACD,GAAG,CACJ,CAAC;QAEF,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AArCW,QAAA,gBAAgB,oBAqC3B"}
package/src/preset.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import type { Types } from '@graphql-codegen/plugin-helpers';
1
+ import { type Types } from '@graphql-codegen/plugin-helpers';
2
2
  import { RawPresetConfig } from './validatePresetConfig';
3
+ export declare const presetName = "@eddeee888/gcg-typescript-resolver-files";
3
4
  export declare const preset: Types.OutputPreset<RawPresetConfig>;