@eddeee888/gcg-typescript-resolver-files 0.8.1 → 0.9.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 (41) hide show
  1. package/package.json +1 -1
  2. package/src/generateResolverFiles/generateResolverFiles.js +29 -82
  3. package/src/generateResolverFiles/generateResolverFiles.js.map +1 -1
  4. package/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.d.ts +5 -0
  5. package/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.js +20 -0
  6. package/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.js.map +1 -0
  7. package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.js +4 -4
  8. package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.js.map +1 -1
  9. package/src/generateResolverFiles/handleGraphQLInterfaceType.js +16 -10
  10. package/src/generateResolverFiles/handleGraphQLInterfaceType.js.map +1 -1
  11. package/src/generateResolverFiles/handleGraphQLObjectType.js +17 -10
  12. package/src/generateResolverFiles/handleGraphQLObjectType.js.map +1 -1
  13. package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.js +21 -12
  14. package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.js.map +1 -1
  15. package/src/generateResolverFiles/handleGraphQLScalarType.js +17 -11
  16. package/src/generateResolverFiles/handleGraphQLScalarType.js.map +1 -1
  17. package/src/generateResolverFiles/handleGraphQLUnionType.js +16 -10
  18. package/src/generateResolverFiles/handleGraphQLUnionType.js.map +1 -1
  19. package/src/generateResolverFiles/postProcessFiles.js +11 -3
  20. package/src/generateResolverFiles/postProcessFiles.js.map +1 -1
  21. package/src/generateResolverFiles/types.d.ts +21 -13
  22. package/src/generateResolverFiles/visitNamedType.d.ts +5 -20
  23. package/src/generateResolverFiles/visitNamedType.js +15 -115
  24. package/src/generateResolverFiles/visitNamedType.js.map +1 -1
  25. package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.d.ts +2 -1
  26. package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.js.map +1 -1
  27. package/src/parseGraphQLSchema/index.d.ts +1 -0
  28. package/src/parseGraphQLSchema/normalizeResolverName.d.ts +15 -0
  29. package/src/parseGraphQLSchema/normalizeResolverName.js +21 -0
  30. package/src/parseGraphQLSchema/normalizeResolverName.js.map +1 -0
  31. package/src/parseGraphQLSchema/parseGraphQLSchema.d.ts +37 -3
  32. package/src/parseGraphQLSchema/parseGraphQLSchema.js +177 -10
  33. package/src/parseGraphQLSchema/parseGraphQLSchema.js.map +1 -1
  34. package/src/parseGraphQLSchema/parseLocationForOutputDir.d.ts +24 -0
  35. package/src/parseGraphQLSchema/parseLocationForOutputDir.js +40 -0
  36. package/src/parseGraphQLSchema/parseLocationForOutputDir.js.map +1 -0
  37. package/src/preset.js +18 -15
  38. package/src/preset.js.map +1 -1
  39. package/src/validatePresetConfig/validatePresetConfig.d.ts +1 -1
  40. package/src/validatePresetConfig/validatePresetConfig.js +13 -1
  41. package/src/validatePresetConfig/validatePresetConfig.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eddeee888/gcg-typescript-resolver-files",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eddeee888/graphql-code-generator-plugins.git",
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateResolverFiles = void 0;
4
- const tslib_1 = require("tslib");
5
- const path = tslib_1.__importStar(require("path"));
6
- const graphql_1 = require("graphql");
7
- const utils_1 = require("../utils");
8
4
  const addResolverMainFiles_1 = require("./addResolverMainFiles");
9
5
  const postProcessFiles_1 = require("./postProcessFiles");
10
6
  const handleGraphQLRootObjectTypeField_1 = require("./handleGraphQLRootObjectTypeField");
@@ -14,84 +10,35 @@ const handleGraphQLScalarType_1 = require("./handleGraphQLScalarType");
14
10
  const handleGraphQLInterfaceType_1 = require("./handleGraphQLInterfaceType");
15
11
  const visitNamedType_1 = require("./visitNamedType");
16
12
  const generateResolverFiles = (ctx) => {
17
- Object.entries(ctx.config.schema.getTypeMap()).forEach(([schemaType, namedType]) => {
18
- var _a, _b;
19
- if ((0, utils_1.isNativeNamedType)(namedType)) {
20
- return;
21
- }
22
- //
23
- // "Visitor" pattern
24
- //
25
- const visitor = {
26
- RootObjectTypeField: handleGraphQLRootObjectTypeField_1.handleGraphQLRootObjectTypeField,
27
- ObjectType: handleGraphQLObjectType_1.handleGraphQLObjectType,
28
- UnionType: handleGraphQLUnionType_1.handleGraphQLUnionType,
29
- ScalarType: handleGraphQLScalarType_1.handleGraphQLScalarType,
30
- InterfaceType: handleGraphQLInterfaceType_1.handleGraphQLInterfaceType,
31
- };
32
- // Root object types e.g. Query, Mutation, Subscription
33
- if ((0, utils_1.isRootObjectType)(schemaType) && (0, graphql_1.isObjectType)(namedType)) {
34
- Object.entries(namedType.getFields()).forEach(([fieldName, fieldNode]) => {
35
- var _a;
36
- return (0, visitNamedType_1.visitNamedType)({
37
- namedType,
38
- resolverName: fieldName,
39
- belongsToRootObject: schemaType,
40
- location: (_a = fieldNode.astNode) === null || _a === void 0 ? void 0 : _a.loc,
41
- visitor,
42
- }, ctx);
43
- });
44
- return;
45
- }
46
- // Other output object types
47
- if ((0, graphql_1.isObjectType)(namedType)) {
48
- const fieldsByGraphQLModule = Object.entries(namedType.getFields()).reduce((res, [_, fieldNode]) => {
49
- var _a;
50
- const fieldLocation = (_a = fieldNode.astNode) === null || _a === void 0 ? void 0 : _a.loc;
51
- const graphQLModule = path.dirname((fieldLocation === null || fieldLocation === void 0 ? void 0 : fieldLocation.source.name) || '');
52
- if (!res[graphQLModule]) {
53
- res[graphQLModule] = {
54
- fieldNodes: [],
55
- // Note: fieldLocation here is the location of the first field found in a GraphQL Module.
56
- // The reason we use field's location instead of the object type's location is because when `extend type ObjectType` is used, the location of object type is the last found location.
57
- // i.e. we cannot rely on object's location if `extend type` is used.
58
- firstFieldLocation: fieldLocation,
59
- };
60
- }
61
- res[graphQLModule].fieldNodes.push(fieldNode);
62
- return res;
63
- }, {});
64
- let pickReferenceResolver = false;
65
- if (ctx.config.federationEnabled && ((_a = namedType.astNode) === null || _a === void 0 ? void 0 : _a.directives)) {
66
- pickReferenceResolver = namedType.astNode.directives.some((d) => d.name.value === 'key');
67
- }
68
- // If there are multiple object type files to generate e.g. `extend type ObjectType` is used across multiple modules
69
- // Then, generate one file for each location
70
- const fieldsToGenerate = Object.entries(fieldsByGraphQLModule);
71
- if (fieldsToGenerate.length > 1) {
72
- fieldsToGenerate.forEach(([_, { firstFieldLocation, fieldNodes }]) => {
73
- const fieldsToPick = fieldNodes.map((field) => field.name);
74
- (0, visitNamedType_1.visitNamedType)({
75
- namedType,
76
- resolverName: namedType.name,
77
- belongsToRootObject: null,
78
- location: firstFieldLocation,
79
- visitor,
80
- fieldsToPick,
81
- pickReferenceResolver,
82
- }, ctx);
83
- });
84
- return;
85
- }
86
- }
87
- // Other types e.g. Union, Scalar, Interface
88
- (0, visitNamedType_1.visitNamedType)({
89
- namedType,
90
- resolverName: namedType.name,
91
- belongsToRootObject: null,
92
- location: (_b = namedType.astNode) === null || _b === void 0 ? void 0 : _b.loc,
93
- visitor,
94
- }, ctx);
13
+ // Query
14
+ Object.values(ctx.config.parsedGraphQLSchemaMeta.userDefinedSchemaTypeMap.query).forEach((details) => {
15
+ (0, visitNamedType_1.visitNamedType)(Object.assign(Object.assign({}, details), { belongsToRootObject: 'Query', visitor: handleGraphQLRootObjectTypeField_1.handleGraphQLRootObjectTypeField }), ctx);
16
+ });
17
+ // Mutation
18
+ Object.values(ctx.config.parsedGraphQLSchemaMeta.userDefinedSchemaTypeMap.mutation).forEach((details) => {
19
+ (0, visitNamedType_1.visitNamedType)(Object.assign(Object.assign({}, details), { belongsToRootObject: 'Mutation', visitor: handleGraphQLRootObjectTypeField_1.handleGraphQLRootObjectTypeField }), ctx);
20
+ });
21
+ // Subscription
22
+ Object.values(ctx.config.parsedGraphQLSchemaMeta.userDefinedSchemaTypeMap.subscription).forEach((details) => {
23
+ (0, visitNamedType_1.visitNamedType)(Object.assign(Object.assign({}, details), { belongsToRootObject: 'Subscription', visitor: handleGraphQLRootObjectTypeField_1.handleGraphQLRootObjectTypeField }), ctx);
24
+ });
25
+ // Object
26
+ Object.values(ctx.config.parsedGraphQLSchemaMeta.userDefinedSchemaTypeMap.object).forEach((objectsByModules) => {
27
+ Object.values(objectsByModules).forEach((details) => {
28
+ (0, visitNamedType_1.visitNamedType)(Object.assign(Object.assign({}, details), { belongsToRootObject: null, visitor: (baseParams, prev_ctx) => (0, handleGraphQLObjectType_1.handleGraphQLObjectType)(Object.assign(Object.assign({}, baseParams), { fieldsToPick: details.fieldsToPick, pickReferenceResolver: details.pickReferenceResolver }), prev_ctx) }), ctx);
29
+ });
30
+ });
31
+ // Scalar
32
+ Object.values(ctx.config.parsedGraphQLSchemaMeta.userDefinedSchemaTypeMap.scalar).forEach((details) => {
33
+ (0, visitNamedType_1.visitNamedType)(Object.assign(Object.assign({}, details), { belongsToRootObject: null, visitor: handleGraphQLScalarType_1.handleGraphQLScalarType }), ctx);
34
+ });
35
+ // Interface
36
+ Object.values(ctx.config.parsedGraphQLSchemaMeta.userDefinedSchemaTypeMap.interface).forEach((details) => {
37
+ (0, visitNamedType_1.visitNamedType)(Object.assign(Object.assign({}, details), { belongsToRootObject: null, visitor: handleGraphQLInterfaceType_1.handleGraphQLInterfaceType }), ctx);
38
+ });
39
+ // Union
40
+ Object.values(ctx.config.parsedGraphQLSchemaMeta.userDefinedSchemaTypeMap.union).forEach((details) => {
41
+ (0, visitNamedType_1.visitNamedType)(Object.assign(Object.assign({}, details), { belongsToRootObject: null, visitor: handleGraphQLUnionType_1.handleGraphQLUnionType }), ctx);
95
42
  });
96
43
  // Post process generated files (could be existing files or files to be generated)
97
44
  (0, postProcessFiles_1.postProcessFiles)(ctx);
@@ -1 +1 @@
1
- {"version":3,"file":"generateResolverFiles.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/generateResolverFiles.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAC7B,qCAAyE;AACzE,oCAA+D;AAC/D,iEAA8D;AAC9D,yDAAsD;AACtD,yFAAsF;AACtF,uEAAoE;AACpE,qEAAkE;AAClE,uEAAoE;AACpE,6EAA0E;AAC1E,qDAA6E;AAGtE,MAAM,qBAAqB,GAAG,CACnC,GAAiC,EAC3B,EAAE;IACR,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CACpD,CAAC,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE,EAAE;;QAC1B,IAAI,IAAA,yBAAiB,EAAC,SAAS,CAAC,EAAE,CAAC;YACjC,OAAO;QACT,CAAC;QAED,EAAE;QACF,oBAAoB;QACpB,EAAE;QACF,MAAM,OAAO,GAAoC;YAC/C,mBAAmB,EAAE,mEAAgC;YACrD,UAAU,EAAE,iDAAuB;YACnC,SAAS,EAAE,+CAAsB;YACjC,UAAU,EAAE,iDAAuB;YACnC,aAAa,EAAE,uDAA0B;SAC1C,CAAC;QAEF,uDAAuD;QACvD,IAAI,IAAA,wBAAgB,EAAC,UAAU,CAAC,IAAI,IAAA,sBAAY,EAAC,SAAS,CAAC,EAAE,CAAC;YAC5D,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAC3C,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,EAAE;;gBACzB,OAAA,IAAA,+BAAc,EACZ;oBACE,SAAS;oBACT,YAAY,EAAE,SAAS;oBACvB,mBAAmB,EAAE,UAAU;oBAC/B,QAAQ,EAAE,MAAA,SAAS,CAAC,OAAO,0CAAE,GAAG;oBAChC,OAAO;iBACR,EACD,GAAG,CACJ,CAAA;aAAA,CACJ,CA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AC/D,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAChC,gBAAgB,CAAC,OAAO,CACtB,CAAC,CAAC,CAAC,EAAE,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE;oBAC1C,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAC3D,IAAA,+BAAc,EAIZ;wBACE,SAAS;wBACT,YAAY,EAAE,SAAS,CAAC,IAAI;wBAC5B,mBAAmB,EAAE,IAAI;wBACzB,QAAQ,EAAE,kBAAkB;wBAC5B,OAAO;wBACP,YAAY;wBACZ,qBAAqB;qBACtB,EACD,GAAG,CACJ,CAAC;gBACJ,CAAC,CACF,CAAC;gBACF,OAAO;YACT,CAAC;QACH,CAAC;QAED,4CAA4C;QAC5C,IAAA,+BAAc,EACZ;YACE,SAAS;YACT,YAAY,EAAE,SAAS,CAAC,IAAI;YAC5B,mBAAmB,EAAE,IAAI;YACzB,QAAQ,EAAE,MAAA,SAAS,CAAC,OAAO,0CAAE,GAAG;YAChC,OAAO;SACR,EACD,GAAG,CACJ,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,kFAAkF;IAClF,IAAA,mCAAgB,EAAC,GAAG,CAAC,CAAC;IAEtB,wDAAwD;IACxD,IAAA,2CAAoB,EAAC,GAAG,CAAC,CAAC;AAC5B,CAAC,CAAC;AA3HW,QAAA,qBAAqB,yBA2HhC"}
1
+ {"version":3,"file":"generateResolverFiles.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/generateResolverFiles.ts"],"names":[],"mappings":";;;AAAA,iEAA8D;AAC9D,yDAAsD;AACtD,yFAAsF;AACtF,uEAAoE;AACpE,qEAAkE;AAClE,uEAAoE;AACpE,6EAA0E;AAC1E,qDAAkD;AAG3C,MAAM,qBAAqB,GAAG,CACnC,GAAiC,EAC3B,EAAE;IACR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+ import type { ResolverFile } from './types';
3
+ export declare const getImportStatementWithExpectedNamedImport: (sourceFile: SourceFile, resolverFile: ResolverFile) => {
4
+ importDeclaration: ImportDeclaration | undefined;
5
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getImportStatementWithExpectedNamedImport = void 0;
4
+ const getImportStatementWithExpectedNamedImport = (sourceFile, resolverFile) => {
5
+ const importDeclaration = sourceFile.getImportDeclaration((declaration) => {
6
+ let foundNamedImport = false;
7
+ declaration.getNamedImports().forEach((namedImport) => {
8
+ var _a;
9
+ if (namedImport.getName() === ((_a = resolverFile.meta.resolverType) === null || _a === void 0 ? void 0 : _a.baseImport)) {
10
+ foundNamedImport = true;
11
+ }
12
+ });
13
+ return foundNamedImport;
14
+ });
15
+ return {
16
+ importDeclaration,
17
+ };
18
+ };
19
+ exports.getImportStatementWithExpectedNamedImport = getImportStatementWithExpectedNamedImport;
20
+ //# sourceMappingURL=getImportStatementWithExpectedNamedImport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getImportStatementWithExpectedNamedImport.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.ts"],"names":[],"mappings":";;;AAGO,MAAM,yCAAyC,GAAG,CACvD,UAAsB,EACtB,YAA0B,EAG1B,EAAE;IACF,MAAM,iBAAiB,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC,WAAW,EAAE,EAAE;QACxE,IAAI,gBAAgB,GAAG,KAAK,CAAC;QAC7B,WAAW,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;;YACpD,IACE,WAAW,CAAC,OAAO,EAAE,MAAK,MAAA,YAAY,CAAC,IAAI,CAAC,YAAY,0CAAE,UAAU,CAAA,EACpE,CAAC;gBACD,gBAAgB,GAAG,IAAI,CAAC;YAC1B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,iBAAiB;KAClB,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,yCAAyC,6CAqBpD"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getVariableStatementWithExpectedIdentifier = void 0;
4
4
  const getVariableStatementWithExpectedIdentifier = (sourceFile, resolverFile) => {
5
- var _a, _b;
5
+ var _a, _b, _c;
6
6
  let isExported = false;
7
7
  const variableStatementWithExpectedIdentifier = sourceFile.getVariableStatement((statement) => {
8
8
  let hasExpectedIdentifier = false;
@@ -27,10 +27,10 @@ const getVariableStatementWithExpectedIdentifier = (sourceFile, resolverFile) =>
27
27
  * e.g. `Book` might become `Pick<Book, 'title' | 'author'>`
28
28
  */
29
29
  if (variableStatementWithExpectedIdentifier &&
30
- resolverFile.meta.resolverTypeString) {
31
- (_b = (_a = variableStatementWithExpectedIdentifier
30
+ ((_a = resolverFile.meta.resolverType) === null || _a === void 0 ? void 0 : _a.final)) {
31
+ (_c = (_b = variableStatementWithExpectedIdentifier
32
32
  .getDeclarationList()
33
- .getDeclarations()[0]) === null || _a === void 0 ? void 0 : _a.getTypeNode()) === null || _b === void 0 ? void 0 : _b.replaceWithText(resolverFile.meta.resolverTypeString);
33
+ .getDeclarations()[0]) === null || _b === void 0 ? void 0 : _b.getTypeNode()) === null || _c === void 0 ? void 0 : _c.replaceWithText(resolverFile.meta.resolverType.final);
34
34
  }
35
35
  return {
36
36
  variableStatement: variableStatementWithExpectedIdentifier,
@@ -1 +1 @@
1
- {"version":3,"file":"getVariableStatementWithExpectedIdentifier.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.ts"],"names":[],"mappings":";;;AAGO,MAAM,0CAA0C,GAAG,CACxD,UAAsB,EACtB,YAA0B,EAI1B,EAAE;;IACF,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,MAAM,uCAAuC,GAC3C,UAAU,CAAC,oBAAoB,CAAC,CAAC,SAAS,EAAE,EAAE;QAC5C,IAAI,qBAAqB,GAAG,KAAK,CAAC;QAClC,SAAS;aACN,kBAAkB,EAAE;aACpB,eAAe,EAAE;aACjB,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE;YAC3B,IAAI,eAAe,CAAC,OAAO,EAAE,KAAK,YAAY,CAAC,oBAAoB,EAAE,CAAC;gBACpE,qBAAqB,GAAG,IAAI,CAAC;gBAC7B,IAAI,SAAS,CAAC,UAAU,EAAE,EAAE,CAAC;oBAC3B,UAAU,GAAG,IAAI,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACL,OAAO,qBAAqB,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEL;;;;;;OAMG;IACH,IACE,uCAAuC;QACvC,YAAY,CAAC,IAAI,CAAC,kBAAkB,EACpC,CAAC;QACD,MAAA,MAAA,uCAAuC;aACpC,kBAAkB,EAAE;aACpB,eAAe,EAAE,CAAC,CAAC,CAAC,0CACnB,WAAW,EAAE,0CACb,eAAe,CAAC,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO;QACL,iBAAiB,EAAE,uCAAuC;QAC1D,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AA/CW,QAAA,0CAA0C,8CA+CrD"}
1
+ {"version":3,"file":"getVariableStatementWithExpectedIdentifier.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.ts"],"names":[],"mappings":";;;AAGO,MAAM,0CAA0C,GAAG,CACxD,UAAsB,EACtB,YAA0B,EAI1B,EAAE;;IACF,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,MAAM,uCAAuC,GAC3C,UAAU,CAAC,oBAAoB,CAAC,CAAC,SAAS,EAAE,EAAE;QAC5C,IAAI,qBAAqB,GAAG,KAAK,CAAC;QAClC,SAAS;aACN,kBAAkB,EAAE;aACpB,eAAe,EAAE;aACjB,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE;YAC3B,IAAI,eAAe,CAAC,OAAO,EAAE,KAAK,YAAY,CAAC,oBAAoB,EAAE,CAAC;gBACpE,qBAAqB,GAAG,IAAI,CAAC;gBAC7B,IAAI,SAAS,CAAC,UAAU,EAAE,EAAE,CAAC;oBAC3B,UAAU,GAAG,IAAI,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACL,OAAO,qBAAqB,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEL;;;;;;OAMG;IACH,IACE,uCAAuC;SACvC,MAAA,YAAY,CAAC,IAAI,CAAC,YAAY,0CAAE,KAAK,CAAA,EACrC,CAAC;QACD,MAAA,MAAA,uCAAuC;aACpC,kBAAkB,EAAE;aACpB,eAAe,EAAE,CAAC,CAAC,CAAC,0CACnB,WAAW,EAAE,0CACb,eAAe,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO;QACL,iBAAiB,EAAE,uCAAuC;QAC1D,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AA/CW,QAAA,0CAA0C,8CA+CrD"}
@@ -2,34 +2,40 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleGraphQLInterfaceType = void 0;
4
4
  const utils_1 = require("../utils");
5
- const handleGraphQLInterfaceType = ({ fieldFilePath, resolverName, normalizedResolverName, resolversTypeMeta, moduleName, relativePathFromBaseToModule, }, { result, config: { resolverGeneration, emitLegacyCommonJSImports } }) => {
5
+ const handleGraphQLInterfaceType = ({ fieldFilePath, isFileAlreadyOnFilesystem, resolverName, normalizedResolverName, resolversTypeMeta, moduleName, relativePathFromBaseToModule, }, { result, config: { resolverGeneration, emitLegacyCommonJSImports } }) => {
6
6
  if (!(0, utils_1.isMatchResolverNamePattern)({
7
7
  pattern: resolverGeneration.interface,
8
8
  value: normalizedResolverName.withModule,
9
- })) {
9
+ }) &&
10
+ !isFileAlreadyOnFilesystem) {
10
11
  utils_1.logger.debug(`Skipped Interface resolver generation: "${normalizedResolverName.withModule}". Pattern: "${resolverGeneration.interface}".`);
11
12
  return;
12
13
  }
13
14
  const resolverTypeString = resolversTypeMeta.typeString;
15
+ const resolverTypeImportDeclaration = (0, utils_1.printImportLine)({
16
+ isTypeImport: true,
17
+ module: resolversTypeMeta.module,
18
+ moduleType: resolversTypeMeta.moduleType,
19
+ namedImports: [resolversTypeMeta.typeNamedImport],
20
+ emitLegacyCommonJSImports,
21
+ });
14
22
  const variableStatement = `export const ${resolverName}: ${resolverTypeString} = { /* Implement ${resolverName} interface logic here */ };`;
15
23
  result.files[fieldFilePath] = {
16
24
  __filetype: 'generalResolver',
17
25
  content: `
18
- ${(0, utils_1.printImportLine)({
19
- isTypeImport: true,
20
- module: resolversTypeMeta.module,
21
- moduleType: resolversTypeMeta.moduleType,
22
- namedImports: [resolversTypeMeta.typeNamedImport],
23
- emitLegacyCommonJSImports,
24
- })}
26
+ ${resolverTypeImportDeclaration}
25
27
  ${variableStatement}`,
26
28
  mainImportIdentifier: resolverName,
27
29
  meta: {
28
30
  moduleName,
29
31
  relativePathFromBaseToModule,
30
32
  normalizedResolverName,
33
+ resolverTypeImportDeclaration,
31
34
  variableStatement,
32
- resolverTypeString,
35
+ resolverType: {
36
+ baseImport: resolversTypeMeta.typeNamedImport,
37
+ final: resolverTypeString,
38
+ },
33
39
  },
34
40
  };
35
41
  };
@@ -1 +1 @@
1
- {"version":3,"file":"handleGraphQLInterfaceType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLInterfaceType.ts"],"names":[],"mappings":";;;AAAA,oCAA+E;AAGxE,MAAM,0BAA0B,GAAuB,CAC5D,EACE,aAAa,EACb,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,4BAA4B,GAC7B,EACD,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,EAAE,EACrE,EAAE;IACF,IACE,CAAC,IAAA,kCAA0B,EAAC;QAC1B,OAAO,EAAE,kBAAkB,CAAC,SAAS;QACrC,KAAK,EAAE,sBAAsB,CAAC,UAAU;KACzC,CAAC,EACF,CAAC;QACD,cAAM,CAAC,KAAK,CACV,2CAA2C,sBAAsB,CAAC,UAAU,gBAAgB,kBAAkB,CAAC,SAAS,IAAI,CAC7H,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,UAAU,CAAC;IAExD,MAAM,iBAAiB,GAAG,gBAAgB,YAAY,KAAK,kBAAkB,qBAAqB,YAAY,6BAA6B,CAAC;IAE5I,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG;QAC5B,UAAU,EAAE,iBAAiB;QAC7B,OAAO,EAAE;MACP,IAAA,uBAAe,EAAC;YAChB,YAAY,EAAE,IAAI;YAClB,MAAM,EAAE,iBAAiB,CAAC,MAAM;YAChC,UAAU,EAAE,iBAAiB,CAAC,UAAU;YACxC,YAAY,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC;YACjD,yBAAyB;SAC1B,CAAC;MACA,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,UAAU;YACV,4BAA4B;YAC5B,sBAAsB;YACtB,iBAAiB;YACjB,kBAAkB;SACnB;KACF,CAAC;AACJ,CAAC,CAAC;AA/CW,QAAA,0BAA0B,8BA+CrC"}
1
+ {"version":3,"file":"handleGraphQLInterfaceType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLInterfaceType.ts"],"names":[],"mappings":";;;AAAA,oCAA+E;AAGxE,MAAM,0BAA0B,GAAuB,CAC5D,EACE,aAAa,EACb,yBAAyB,EACzB,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,UAA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.handleGraphQLObjectType = void 0;
4
4
  const utils_1 = require("../utils");
5
- const handleGraphQLObjectType = ({ fieldFilePath, resolverName, normalizedResolverName, resolversTypeMeta, moduleName, relativePathFromBaseToModule, fieldsToPick = [], // If fieldsToPick.length === 0, it means the current object handles all resolvers
5
+ const handleGraphQLObjectType = ({ fieldFilePath, resolverName, isFileAlreadyOnFilesystem, normalizedResolverName, resolversTypeMeta, moduleName, relativePathFromBaseToModule, fieldsToPick = [], // If fieldsToPick.length === 0, it means the current object handles all resolvers
6
6
  pickReferenceResolver, }, { result, config: { resolverGeneration, typeMappersMap, graphQLObjectTypeResolversToGenerate, emitLegacyCommonJSImports, }, }) => {
7
7
  const matchedPatternToGenerate = (0, utils_1.isMatchResolverNamePattern)({
8
8
  pattern: resolverGeneration.object,
9
9
  value: normalizedResolverName.withModule,
10
10
  });
11
11
  const mapperDetails = typeMappersMap[normalizedResolverName.base];
12
- if (!matchedPatternToGenerate && !mapperDetails) {
12
+ if (!matchedPatternToGenerate &&
13
+ !mapperDetails &&
14
+ !isFileAlreadyOnFilesystem) {
13
15
  utils_1.logger.debug(`Skipped Object resolver generation: "${normalizedResolverName.withModule}". "Pattern: ${resolverGeneration.object}".`);
14
16
  return;
15
17
  }
@@ -52,24 +54,29 @@ pickReferenceResolver, }, { result, config: { resolverGeneration, typeMappersMap
52
54
  const variableStatement = `${forcedGenerationWarning}export const ${resolverName}: ${typeString} = {
53
55
  /* Implement ${resolverName} resolver logic here */
54
56
  };`;
57
+ const resolverTypeImportDeclaration = (0, utils_1.printImportLine)({
58
+ isTypeImport: true,
59
+ module: resolversTypeMeta.module,
60
+ moduleType: resolversTypeMeta.moduleType,
61
+ namedImports: [resolversTypeMeta.typeNamedImport],
62
+ emitLegacyCommonJSImports,
63
+ });
55
64
  result.files[fieldFilePath] = {
56
65
  __filetype: 'objectType',
57
66
  content: `
58
- ${(0, utils_1.printImportLine)({
59
- isTypeImport: true,
60
- module: resolversTypeMeta.module,
61
- moduleType: resolversTypeMeta.moduleType,
62
- namedImports: [resolversTypeMeta.typeNamedImport],
63
- emitLegacyCommonJSImports,
64
- })}
67
+ ${resolverTypeImportDeclaration}
65
68
  ${variableStatement}`,
66
69
  mainImportIdentifier: resolverName,
67
70
  meta: {
68
71
  moduleName,
69
72
  relativePathFromBaseToModule,
70
73
  normalizedResolverName,
74
+ resolverTypeImportDeclaration,
71
75
  variableStatement,
72
- resolverTypeString: typeString,
76
+ resolverType: {
77
+ baseImport: resolversTypeMeta.typeNamedImport,
78
+ final: typeString,
79
+ },
73
80
  resolversToGenerate,
74
81
  },
75
82
  };
@@ -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,GAMhC,CACF,EACE,aAAa,EACb,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,4BAA4B,EAC5B,YAAY,GAAG,EAAE,EAAE,kFAAkF;AACrG,qBAAqB,GACtB,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,aAAa,GAAG,cAAc,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAElE,IAAI,CAAC,wBAAwB,IAAI,CAAC,aAAa,EAAE,CAAC;QAChD,cAAM,CAAC,KAAK,CACV,wCAAwC,sBAAsB,CAAC,UAAU,gBAAgB,kBAAkB,CAAC,MAAM,IAAI,CACvH,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE;QACpC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B,CAAC;IAEJ,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG;QAC5B,UAAU,EAAE,YAAY;QACxB,OAAO,EAAE;MACP,IAAA,uBAAe,EAAC;YAChB,YAAY,EAAE,IAAI;YAClB,MAAM,EAAE,iBAAiB,CAAC,MAAM;YAChC,UAAU,EAAE,iBAAiB,CAAC,UAAU;YACxC,YAAY,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC;YACjD,yBAAyB;SAC1B,CAAC;MACA,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,UAAU;YACV,4BAA4B;YAC5B,sBAAsB;YACtB,iBAAiB;YACjB,kBAAkB,EAAE,UAAU;YAC9B,mBAAmB;SACpB;KACF,CAAC;AACJ,CAAC,CAAC;AAjHW,QAAA,uBAAuB,2BAiHlC"}
1
+ {"version":3,"file":"handleGraphQLObjectType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLObjectType.ts"],"names":[],"mappings":";;;AACA,oCAA+E;AAExE,MAAM,uBAAuB,GAMhC,CACF,EACE,aAAa,EACb,YAAY,EACZ,yBAAyB,EACzB,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,4BAA4B,EAC5B,YAAY,GAAG,EAAE,EAAE,kFAAkF;AACrG,qBAAqB,GACtB,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,aAAa,GAAG,cAAc,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAElE,IACE,CAAC,wBAAwB;QACzB,CAAC,aAAa;QACd,CAAC,yBAAyB,EA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AC;YACzD,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAAE,CACH;QACH,CAAC,CAAC,sBAAsB,CAAC;IAE7B,MAAM,iBAAiB,GAAG,GAAG,uBAAuB,gBAAgB,YAAY,KAAK,UAAU;mBAC9E,YAAY;KAC1B,CAAC;IAEJ,MAAM,6BAA6B,GAAG,IAAA,uBAAe,EAAC;QACpD,YAAY,EAAE,IAAI;QAClB,MAAM,EAAE,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,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;aAClB;YACD,mBAAmB;SACpB;KACF,CAAC;AACJ,CAAC,CAAC;AA5HW,QAAA,uBAAuB,2BA4HlC"}
@@ -2,22 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleGraphQLRootObjectTypeField = void 0;
4
4
  const utils_1 = require("../utils");
5
- const handleGraphQLRootObjectTypeField = ({ fieldFilePath, resolverName, belongsToRootObject, normalizedResolverName, resolversTypeMeta, moduleName, relativePathFromBaseToModule, }, { result, config: { resolverGeneration, emitLegacyCommonJSImports } }) => {
5
+ const handleGraphQLRootObjectTypeField = ({ fieldFilePath, isFileAlreadyOnFilesystem, resolverName, belongsToRootObject, normalizedResolverName, resolversTypeMeta, moduleName, relativePathFromBaseToModule, }, { result, config: { resolverGeneration, emitLegacyCommonJSImports } }) => {
6
6
  if ((belongsToRootObject === 'Query' &&
7
7
  !(0, utils_1.isMatchResolverNamePattern)({
8
8
  pattern: resolverGeneration.query,
9
9
  value: normalizedResolverName.withModule,
10
- })) ||
10
+ }) &&
11
+ !isFileAlreadyOnFilesystem) ||
11
12
  (belongsToRootObject === 'Mutation' &&
12
13
  !(0, utils_1.isMatchResolverNamePattern)({
13
14
  pattern: resolverGeneration.mutation,
14
15
  value: normalizedResolverName.withModule,
15
- })) ||
16
+ }) &&
17
+ !isFileAlreadyOnFilesystem) ||
16
18
  (belongsToRootObject === 'Subscription' &&
17
19
  !(0, utils_1.isMatchResolverNamePattern)({
18
20
  pattern: resolverGeneration.subscription,
19
21
  value: normalizedResolverName.withModule,
20
- }))) {
22
+ }) &&
23
+ !isFileAlreadyOnFilesystem)) {
21
24
  const resolverGenerationPattern = belongsToRootObject === 'Query'
22
25
  ? resolverGeneration.query
23
26
  : belongsToRootObject === 'Mutation'
@@ -36,24 +39,30 @@ const handleGraphQLRootObjectTypeField = ({ fieldFilePath, resolverName, belongs
36
39
  subscribe: async (_parent, _arg, _ctx) => { ${suggestion} },
37
40
  }`;
38
41
  }
42
+ const resolverTypeImportDeclaration = (0, utils_1.printImportLine)({
43
+ isTypeImport: true,
44
+ module: resolversTypeMeta.module,
45
+ moduleType: resolversTypeMeta.moduleType,
46
+ namedImports: [resolversTypeMeta.typeNamedImport],
47
+ emitLegacyCommonJSImports,
48
+ });
39
49
  result.files[fieldFilePath] = {
40
50
  __filetype: 'rootObjectTypeFieldResolver',
41
51
  content: `
42
- ${(0, utils_1.printImportLine)({
43
- isTypeImport: true,
44
- module: resolversTypeMeta.module,
45
- moduleType: resolversTypeMeta.moduleType,
46
- namedImports: [resolversTypeMeta.typeNamedImport],
47
- emitLegacyCommonJSImports,
48
- })}
52
+ ${resolverTypeImportDeclaration}
49
53
  ${variableStatement}`,
50
54
  mainImportIdentifier: resolverName,
51
55
  meta: {
52
56
  moduleName,
53
57
  relativePathFromBaseToModule,
54
58
  belongsToRootObject,
59
+ resolverTypeImportDeclaration,
55
60
  variableStatement,
56
- resolverTypeString,
61
+ resolverType: {
62
+ baseImport: resolversTypeMeta.typeNamedImport,
63
+ resolver: resolversTypeMeta.typeString,
64
+ final: resolverTypeString,
65
+ },
57
66
  normalizedResolverName,
58
67
  },
59
68
  };
@@ -1 +1 @@
1
- {"version":3,"file":"handleGraphQLRootObjectTypeField.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLRootObjectTypeField.ts"],"names":[],"mappings":";;;AAAA,oCAKkB;AAGX,MAAM,gCAAgC,GAEzC,CACF,EACE,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,4BAA4B,GAC7B,EACD,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,EAAE,EACrE,EAAE;IACF,IACE,CAAC,mBAAmB,KAAK,OAAO;QAC9B,CAAC,IAAA,kCAA0B,EAAC;YAC1B,OAAO,EAAE,kBAAkB,CAAC,KAAK;YACjC,KAAK,EAAE,sBAAsB,CAAC,UAAU;SACzC,CAAC,CAAC;QACL,CAAC,mBAAmB,KAAK,UAAU;YACjC,CAAC,IAAA,kCAA0B,EAAC;gBAC1B,OAAO,EAAE,kBAAkB,CAAC,QAAQ;gBACpC,KAAK,EAAE,sBAAsB,CAAC,UAAU;aACzC,CAAC,CAAC;QACL,CAAC,mBAAmB,KAAK,cAAc;YACrC,CAAC,IAAA,kCAA0B,EAAC;gBAC1B,OAAO,EAAE,kBAAkB,CAAC,YAAY;gBACxC,KAAK,EAAE,sBAAsB,CAAC,UAAU;aACzC,CAAC,CAAC,EACL,CAAC;QACD,MAAM,yBAAyB,GAC7B,mBAAmB,KAAK,OAAO;YAC7B,CAAC,CAAC,kBAAkB,CAAC,KAAK;YAC1B,CAAC,CAAC,mBAAmB,KAAK,UAAU;gBACpC,CAAC,CAAC,kBAAkB,CAAC,QAAQ;gBAC7B,CAAC,CAAC,mBAAmB,KAAK,cAAc;oBACxC,CAAC,CAAC,kBAAkB,CAAC,YAAY;oBACjC,CAAC,CAAC,SAAS,CAAC;QAChB,cAAM,CAAC,KAAK,CACV,WAAW,mBAAmB,0BAA0B,sBAAsB,CAAC,UAAU,gBAAgB,yBAAyB,IAAI,CACvI,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAAG,gBAAgB,sBAAsB,CAAC,IAAI,yBAAyB,CAAC;IAExF,MAAM,kBAAkB,GAAG,eAAe,iBAAiB,CAAC,UAAU,GAAG,CAAC;IAE1E,IAAI,iBAAiB,GAAG,gBAAgB,YAAY,KAAK,kBAAkB,uCAAuC,UAAU,KAAK,CAAC;IAClI,IAAI,mBAAmB,KAAK,cAAc,EAAE,CAAC;QAC3C,iBAAiB,GAAG,gBAAgB,YAAY,KAAK,kBAAkB;oDACvB,UAAU;MACxD,CAAC;IACL,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG;QAC5B,UAAU,EAAE,6BAA6B;QACzC,OAAO,EAAE;UACH,IAAA,uBAAe,EAAC;YAChB,YAAY,EAAE,IAAI;YAClB,MAAM,EAAE,iBAAiB,CAAC,MAAM;YAChC,UAAU,EAAE,iBAAiB,CAAC,UAAU;YACxC,YAAY,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC;YACjD,yBAAyB;SAC1B,CAAC;UACA,iBAAiB,EAAE;QACzB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,UAAU;YACV,4BAA4B;YAC5B,mBAAmB;YACnB,iBAAiB;YACjB,kBAAkB;YAClB,sBAAsB;SACvB;KACF,CAAC;AACJ,CAAC,CAAC;AA7EW,QAAA,gCAAgC,oCA6E3C"}
1
+ {"version":3,"file":"handleGraphQLRootObjectTypeField.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGra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AAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAAG,gBAAgB,sBAAsB,CAAC,IAAI,yBAAyB,CAAC;IAExF,MAAM,kBAAkB,GAAG,eAAe,iBAAiB,CAAC,UAAU,GAAG,CAAC;IAE1E,IAAI,iBAAiB,GAAG,gBAAgB,YAAY,KAAK,kBAAkB,uCAAuC,UAAU,KAAK,CAAC;IAClI,IAAI,mBAAmB,KAAK,cAAc,EAAE,CAAC;QAC3C,iBAAiB,GAAG,gBAAgB,YAAY,KAAK,kBAAkB;oDACvB,UAAU;MACxD,CAAC;IACL,CAAC;IAED,MAAM,6BAA6B,GAAG,IAAA,uBAAe,EAAC;QACpD,YAAY,EAAE,IAAI;QAClB,MAAM,EAAE,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,6BAA6B;QACzC,OAAO,EAAE;UACH,6BAA6B;UAC7B,iBAAiB,EAAE;QACzB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,UAAU;YACV,4BAA4B;YAC5B,mBAAmB;YACnB,6BAA6B;YAC7B,iBAAiB;YACjB,YAAY,EAAE;gBACZ,UAAU,EAAE,iBAAiB,CAAC,eAAe;gBAC7C,QAAQ,EAAE,iBAAiB,CAAC,UAAU;gBACtC,KAAK,EAAE,kBAAkB;aAC1B;YACD,sBAAsB;SACvB;KACF,CAAC;AACJ,CAAC,CAAC;AAxFW,QAAA,gCAAgC,oCAwF3C"}
@@ -3,15 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleGraphQLScalarType = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const graphQLScalarType = 'GraphQLScalarType';
6
- const handleGraphQLScalarType = ({ fieldFilePath, resolverName, normalizedResolverName, moduleName, relativePathFromBaseToModule, }, { result, config: { resolverGeneration, emitLegacyCommonJSImports } }) => {
6
+ const handleGraphQLScalarType = ({ fieldFilePath, isFileAlreadyOnFilesystem, resolverName, normalizedResolverName, moduleName, relativePathFromBaseToModule, }, { result, config: { resolverGeneration, emitLegacyCommonJSImports } }) => {
7
7
  if (!(0, utils_1.isMatchResolverNamePattern)({
8
8
  pattern: resolverGeneration.scalar,
9
9
  value: normalizedResolverName.withModule,
10
- })) {
10
+ }) &&
11
+ !isFileAlreadyOnFilesystem) {
11
12
  utils_1.logger.debug(`Skipped Scalar resolver generation: "${normalizedResolverName.withModule}". Pattern: "${resolverGeneration.scalar}".`);
12
13
  return;
13
14
  }
14
- const variableStatement = `export const ${resolverName} = new GraphQLScalarType({
15
+ const resolverTypeImportDeclaration = (0, utils_1.printImportLine)({
16
+ isTypeImport: false,
17
+ module: 'graphql',
18
+ moduleType: 'module',
19
+ namedImports: [graphQLScalarType],
20
+ emitLegacyCommonJSImports,
21
+ });
22
+ const variableStatement = `export const ${resolverName} = new ${graphQLScalarType}({
15
23
  name: '${resolverName}',
16
24
  description: '${resolverName} description',
17
25
  serialize: (value) => {
@@ -27,21 +35,19 @@ const handleGraphQLScalarType = ({ fieldFilePath, resolverName, normalizedResolv
27
35
  result.files[fieldFilePath] = {
28
36
  __filetype: 'generalResolver',
29
37
  content: `
30
- ${(0, utils_1.printImportLine)({
31
- isTypeImport: false,
32
- module: 'graphql',
33
- moduleType: 'module',
34
- namedImports: [graphQLScalarType],
35
- emitLegacyCommonJSImports,
36
- })}
38
+ ${resolverTypeImportDeclaration}
37
39
  ${variableStatement}`,
38
40
  mainImportIdentifier: resolverName,
39
41
  meta: {
40
42
  moduleName,
41
43
  relativePathFromBaseToModule,
42
44
  normalizedResolverName,
45
+ resolverTypeImportDeclaration,
43
46
  variableStatement,
44
- resolverTypeString: null,
47
+ resolverType: {
48
+ baseImport: graphQLScalarType,
49
+ final: graphQLScalarType,
50
+ },
45
51
  },
46
52
  };
47
53
  };
@@ -1 +1 @@
1
- {"version":3,"file":"handleGraphQLScalarType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLScalarType.ts"],"names":[],"mappings":";;;AAAA,oCAA+E;AAG/E,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAEvC,MAAM,uBAAuB,GAAuB,CACzD,EACE,aAAa,EACb,YAAY,EACZ,sBAAsB,EACtB,UAAU,EACV,4BAA4B,GAC7B,EACD,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,EAAE,EACrE,EAAE;IACF,IACE,CAAC,IAAA,kCAA0B,EAAC;QAC1B,OAAO,EAAE,kBAAkB,CAAC,MAAM;QAClC,KAAK,EAAE,sBAAsB,CAAC,UAAU;KACzC,CAAC,EACF,CAAC;QACD,cAAM,CAAC,KAAK,CACV,wCAAwC,sBAAsB,CAAC,UAAU,gBAAgB,kBAAkB,CAAC,MAAM,IAAI,CACvH,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,iBAAiB,GAAG,gBAAgB,YAAY;aAC3C,YAAY;oBACL,YAAY;;;;;;;;;;MAU1B,CAAC;IAEL,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG;QAC5B,UAAU,EAAE,iBAAiB;QAC7B,OAAO,EAAE;MACP,IAAA,uBAAe,EAAC;YAChB,YAAY,EAAE,KAAK;YACnB,MAAM,EAAE,SAAS;YACjB,UAAU,EAAE,QAAQ;YACpB,YAAY,EAAE,CAAC,iBAAiB,CAAC;YACjC,yBAAyB;SAC1B,CAAC;MACA,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,UAAU;YACV,4BAA4B;YAC5B,sBAAsB;YACtB,iBAAiB;YACjB,kBAAkB,EAAE,IAAI;SACzB;KACF,CAAC;AACJ,CAAC,CAAC;AAxDW,QAAA,uBAAuB,2BAwDlC"}
1
+ {"version":3,"file":"handleGraphQLScalarType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLScalarType.ts"],"names":[],"mappings":";;;AAAA,oCAA+E;AAG/E,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAEvC,MAAM,uBAAuB,GAAuB,CACzD,EACE,aAAa,EACb,yBAAyB,EACzB,YAAY,EACZ,sBAAsB,EACtB,UAAU,EACV,4BAA4B,GAC7B,EACD,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,EAAE,EACrE,EAAE;IACF,IACE,CAAC,IAAA,kCAA0B,EAAC;QAC1B,OAAO,EAAE,kBAAkB,CAAC,MAAM;QAClC,KAAK,EAAE,sBAAsB,CAAC,UAAU;KACzC,CAAC;QACF,CAAC,yBAAyB,EAC1B,CAAC;QACD,cAAM,CAAC,KAAK,CACV,wCAAwC,sBAAsB,CAAC,UAAU,gBAAgB,kBAAkB,CAAC,MAAM,IAAI,CACvH,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,6BAA6B,GAAG,IAAA,uBAAe,EAAC;QACpD,YAAY,EAAE,KAAK;QACnB,MAAM,EAAE,SAAS;QACjB,UAAU,EAAE,QAAQ;QACpB,YAAY,EAAE,CAAC,iBAAiB,CAAC;QACjC,yBAAyB;KAC1B,CAAC,CAAC;IACH,MAAM,iBAAiB,GAAG,gBAAgB,YAAY,UAAU,iBAAiB;aACtE,YAAY;oBACL,YAAY;;;;;;;;;;MAU1B,CAAC;IAEL,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG;QAC5B,UAAU,EAAE,iBAAiB;QAC7B,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;gBAC7B,KAAK,EAAE,iBAAiB;aACzB;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AA/DW,QAAA,uBAAuB,2BA+DlC"}
@@ -2,32 +2,38 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleGraphQLUnionType = void 0;
4
4
  const utils_1 = require("../utils");
5
- const handleGraphQLUnionType = ({ fieldFilePath, resolverName, normalizedResolverName, resolversTypeMeta, moduleName, relativePathFromBaseToModule, }, { result, config: { resolverGeneration, emitLegacyCommonJSImports } }) => {
5
+ const handleGraphQLUnionType = ({ fieldFilePath, isFileAlreadyOnFilesystem, resolverName, normalizedResolverName, resolversTypeMeta, moduleName, relativePathFromBaseToModule, }, { result, config: { resolverGeneration, emitLegacyCommonJSImports } }) => {
6
6
  if (!(0, utils_1.isMatchResolverNamePattern)({
7
7
  pattern: resolverGeneration.union,
8
8
  value: normalizedResolverName.withModule,
9
- })) {
9
+ }) &&
10
+ !isFileAlreadyOnFilesystem) {
10
11
  utils_1.logger.debug(`Skipped Union resolver generation: "${normalizedResolverName.withModule}". Pattern: "${resolverGeneration.union}".`);
11
12
  return;
12
13
  }
14
+ const resolverTypeImportDeclaration = (0, utils_1.printImportLine)({
15
+ isTypeImport: true,
16
+ module: resolversTypeMeta.module,
17
+ moduleType: resolversTypeMeta.moduleType,
18
+ namedImports: [resolversTypeMeta.typeNamedImport],
19
+ emitLegacyCommonJSImports,
20
+ });
13
21
  const variableStatement = `export const ${resolverName}: ${resolversTypeMeta.typeString} = { /* Implement ${resolverName} union logic here */ };`;
14
22
  result.files[fieldFilePath] = {
15
23
  __filetype: 'generalResolver',
16
24
  content: `
17
- ${(0, utils_1.printImportLine)({
18
- isTypeImport: true,
19
- module: resolversTypeMeta.module,
20
- moduleType: resolversTypeMeta.moduleType,
21
- namedImports: [resolversTypeMeta.typeNamedImport],
22
- emitLegacyCommonJSImports,
23
- })}
25
+ ${resolverTypeImportDeclaration}
24
26
  ${variableStatement}`,
25
27
  mainImportIdentifier: resolverName,
26
28
  meta: {
27
29
  moduleName,
28
30
  relativePathFromBaseToModule,
29
31
  normalizedResolverName,
30
- resolverTypeString: resolversTypeMeta.typeString,
32
+ resolverType: {
33
+ baseImport: resolversTypeMeta.typeNamedImport,
34
+ final: resolversTypeMeta.typeString,
35
+ },
36
+ resolverTypeImportDeclaration,
31
37
  variableStatement,
32
38
  },
33
39
  };
@@ -1 +1 @@
1
- {"version":3,"file":"handleGraphQLUnionType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLUnionType.ts"],"names":[],"mappings":";;;AAAA,oCAA+E;AAGxE,MAAM,sBAAsB,GAAuB,CACxD,EACE,aAAa,EACb,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,4BAA4B,GAC7B,EACD,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,EAAE,EACrE,EAAE;IACF,IACE,CAAC,IAAA,kCAA0B,EAAC;QAC1B,OAAO,EAAE,kBAAkB,CAAC,KAAK;QACjC,KAAK,EAAE,sBAAsB,CAAC,UAAU;KACzC,CAAC,EACF,CAAC;QACD,cAAM,CAAC,KAAK,CACV,uCAAuC,sBAAsB,CAAC,UAAU,gBAAgB,kBAAkB,CAAC,KAAK,IAAI,CACrH,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,iBAAiB,GAAG,gBAAgB,YAAY,KAAK,iBAAiB,CAAC,UAAU,qBAAqB,YAAY,yBAAyB,CAAC;IAElJ,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG;QAC5B,UAAU,EAAE,iBAAiB;QAC7B,OAAO,EAAE;MACP,IAAA,uBAAe,EAAC;YAChB,YAAY,EAAE,IAAI;YAClB,MAAM,EAAE,iBAAiB,CAAC,MAAM;YAChC,UAAU,EAAE,iBAAiB,CAAC,UAAU;YACxC,YAAY,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC;YACjD,yBAAyB;SAC1B,CAAC;MACA,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,UAAU;YACV,4BAA4B;YAC5B,sBAAsB;YACtB,kBAAkB,EAAE,iBAAiB,CAAC,UAAU;YAChD,iBAAiB;SAClB;KACF,CAAC;AACJ,CAAC,CAAC;AA7CW,QAAA,sBAAsB,0BA6CjC"}
1
+ {"version":3,"file":"handleGraphQLUnionType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLUnionType.ts"],"names":[],"mappings":";;;AAAA,oCAA+E;AAGxE,MAAM,sBAAsB,GAAuB,CACxD,EACE,aAAa,EACb,yBAAyB,EACzB,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,4BAA4B,GAC7B,EACD,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,EAAE,EACrE,EAAE;IACF,IACE,CAAC,IAAA,kCAA0B,EAAC;QAC1B,OAAO,EAAE,kBAAkB,CAAC,KAAK;QACjC,KAAK,EAAE,sBAAsB,CAAC,UAAU;KACzC,CAAC;QACF,CAAC,yBAAyB,EAC1B,CAAC;QACD,cAAM,CAAC,KAAK,CACV,uCAAuC,sBAAsB,CAAC,UAAU,gBAAgB,kBAAkB,CAAC,KAAK,IAAI,CACrH,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,6BAA6B,GAAG,IAAA,uBAAe,EAAC;QACpD,YAAY,EAAE,IAAI;QAClB,MAAM,EAAE,iBAAiB,CAAC,MAAM;QAChC,UAAU,EAAE,iBAAiB,CAAC,UAAU;QACxC,YAAY,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC;QACjD,yBAAyB;KAC1B,CAAC,CAAC;IACH,MAAM,iBAAiB,GAAG,gBAAgB,YAAY,KAAK,iBAAiB,CAAC,UAAU,qBAAqB,YAAY,yBAAyB,CAAC;IAElJ,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG;QAC5B,UAAU,EAAE,iBAAiB;QAC7B,OAAO,EAAE;MACP,6BAA6B;MAC7B,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,UAAU;YACV,4BAA4B;YAC5B,sBAAsB;YACtB,YAAY,EAAE;gBACZ,UAAU,EAAE,iBAAiB,CAAC,eAAe;gBAC7C,KAAK,EAAE,iBAAiB,CAAC,UAAU;aACpC;YACD,6BAA6B;YAC7B,iBAAiB;SAClB;KACF,CAAC;AACJ,CAAC,CAAC;AApDW,QAAA,sBAAsB,0BAoDjC"}
@@ -6,6 +6,7 @@ const path = tslib_1.__importStar(require("path"));
6
6
  const utils_1 = require("../utils");
7
7
  const getVariableStatementWithExpectedIdentifier_1 = require("./getVariableStatementWithExpectedIdentifier");
8
8
  const ensureObjectTypeResolversAreGenerated_1 = require("./ensureObjectTypeResolversAreGenerated");
9
+ const getImportStatementWithExpectedNamedImport_1 = require("./getImportStatementWithExpectedNamedImport");
9
10
  /**
10
11
  * postProcessFiles does static analysis on existing files OR to-be-generated files
11
12
  * e.g.
@@ -37,8 +38,7 @@ const postProcessFiles = ({ config: { tsMorph: { project }, fixObjectTypeResolve
37
38
  });
38
39
  sourceFilesToProcess.forEach(({ sourceFile, resolverFile }) => {
39
40
  const normalizedRelativePath = path.posix.relative((0, utils_1.cwd)(), sourceFile.getFilePath());
40
- // TODO: Check missing import
41
- // ...
41
+ ensureImportedType(sourceFile, resolverFile);
42
42
  ensureExportedResolver(sourceFile, resolverFile);
43
43
  if (fixObjectTypeResolvers === 'smart' &&
44
44
  resolverFile.__filetype === 'objectType') {
@@ -56,7 +56,6 @@ const ensureExportedResolver = (sourceFile, resolverFile) => {
56
56
  const { variableStatement, isExported } = (0, getVariableStatementWithExpectedIdentifier_1.getVariableStatementWithExpectedIdentifier)(sourceFile, resolverFile);
57
57
  if (!variableStatement) {
58
58
  // Did not find variable statement with expected identifier, add it to the end with a warning
59
- sourceFile.addStatements('/* WARNING: The following resolver was missing from this file. Make sure it is properly implemented or there could be runtime errors. */');
60
59
  sourceFile.addStatements(resolverFile.meta.variableStatement);
61
60
  }
62
61
  else if (variableStatement && !isExported) {
@@ -71,4 +70,13 @@ const ensureExportedResolver = (sourceFile, resolverFile) => {
71
70
  // else, if identifier's been exported do nothing
72
71
  }
73
72
  };
73
+ /**
74
+ * Ensure correctly imported resolves type generated by typescript-resolvers plugin
75
+ */
76
+ const ensureImportedType = (sourceFile, resolverFile) => {
77
+ const { importDeclaration } = (0, getImportStatementWithExpectedNamedImport_1.getImportStatementWithExpectedNamedImport)(sourceFile, resolverFile);
78
+ if (!importDeclaration) {
79
+ sourceFile.insertStatements(0, resolverFile.meta.resolverTypeImportDeclaration);
80
+ }
81
+ };
74
82
  //# sourceMappingURL=postProcessFiles.js.map