@eddeee888/gcg-typescript-resolver-files 0.2.0 → 0.3.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.
- package/README.md +2 -0
- package/package.json +5 -5
- package/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.d.ts +8 -0
- package/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.js +35 -0
- package/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.js.map +1 -0
- package/src/addVirtualTypesFileToTsMorphProject/index.d.ts +1 -0
- package/src/addVirtualTypesFileToTsMorphProject/index.js +5 -0
- package/src/addVirtualTypesFileToTsMorphProject/index.js.map +1 -0
- package/src/generateResolverFiles/addResolverMainFile.js +2 -1
- package/src/generateResolverFiles/addResolverMainFile.js.map +1 -1
- package/src/generateResolverFiles/ensureObjectTypeResolversAreGenerated.d.ts +6 -0
- package/src/generateResolverFiles/ensureObjectTypeResolversAreGenerated.js +80 -0
- package/src/generateResolverFiles/ensureObjectTypeResolversAreGenerated.js.map +1 -0
- package/src/generateResolverFiles/generateResolverFiles.js +3 -3
- package/src/generateResolverFiles/generateResolverFiles.js.map +1 -1
- package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.d.ts +6 -0
- package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.js +27 -0
- package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.js.map +1 -0
- package/src/generateResolverFiles/handleGraphQLObjectType.js +8 -6
- package/src/generateResolverFiles/handleGraphQLObjectType.js.map +1 -1
- package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.d.ts +2 -1
- package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.js +4 -4
- package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.js.map +1 -1
- package/src/generateResolverFiles/handleGraphQLScalarType.js +4 -5
- package/src/generateResolverFiles/handleGraphQLScalarType.js.map +1 -1
- package/src/generateResolverFiles/handleGraphQLUninionType.js +4 -5
- package/src/generateResolverFiles/handleGraphQLUninionType.js.map +1 -1
- package/src/generateResolverFiles/postProcessFiles.d.ts +8 -0
- package/src/generateResolverFiles/postProcessFiles.js +72 -0
- package/src/generateResolverFiles/postProcessFiles.js.map +1 -0
- package/src/generateResolverFiles/types.d.ts +31 -7
- package/src/generateResolverFiles/visitNamedType.d.ts +1 -1
- package/src/generateResolverFiles/visitNamedType.js +12 -9
- package/src/generateResolverFiles/visitNamedType.js.map +1 -1
- package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.d.ts +11 -0
- package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.js +70 -0
- package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.js.map +1 -0
- package/src/getGraphQLObjectTypeResolversToGenerate/index.d.ts +1 -0
- package/src/getGraphQLObjectTypeResolversToGenerate/index.js +5 -0
- package/src/getGraphQLObjectTypeResolversToGenerate/index.js.map +1 -0
- package/src/getPluginsConfig/getPluginsConfig.d.ts +7 -1
- package/src/getPluginsConfig/getPluginsConfig.js +14 -6
- package/src/getPluginsConfig/getPluginsConfig.js.map +1 -1
- package/src/parseTypeMappers/collectTypeMappersFromSourceFile.d.ts +3 -2
- package/src/parseTypeMappers/collectTypeMappersFromSourceFile.js +38 -8
- package/src/parseTypeMappers/collectTypeMappersFromSourceFile.js.map +1 -1
- package/src/parseTypeMappers/parseTypeMappers.d.ts +6 -1
- package/src/parseTypeMappers/parseTypeMappers.js +9 -7
- package/src/parseTypeMappers/parseTypeMappers.js.map +1 -1
- package/src/preset.d.ts +2 -1
- package/src/preset.js +66 -28
- package/src/preset.js.map +1 -1
- package/src/utils/getNodePropertyMap.d.ts +9 -0
- package/src/utils/getNodePropertyMap.js +49 -0
- package/src/utils/getNodePropertyMap.js.map +1 -0
- package/src/utils/index.d.ts +1 -0
- package/src/utils/index.js +1 -0
- package/src/utils/index.js.map +1 -1
- package/src/validatePresetConfig/validatePresetConfig.d.ts +6 -1
- package/src/validatePresetConfig/validatePresetConfig.js +29 -10
- package/src/validatePresetConfig/validatePresetConfig.js.map +1 -1
- package/src/generateResolverFiles/fixExistingResolvers.d.ts +0 -2
- package/src/generateResolverFiles/fixExistingResolvers.js +0 -62
- package/src/generateResolverFiles/fixExistingResolvers.js.map +0 -1
package/README.md
CHANGED
|
@@ -96,3 +96,5 @@ Running codegen will generate the following files:
|
|
|
96
96
|
| `typesPluginsConfig` | `(@graphql-codegen/typescript).TypeScriptPluginConfig & (@graphql-codegen/typescript-resolvers).TypeScriptResolversPluginConfig` | Takes [typescript config](https://www.the-guild.dev/graphql/codegen/plugins/typescript/typescript) and [typescript-resolvers config](https://www.the-guild.dev/graphql/codegen/plugins/typescript/typescript-resolvers) to override the defaults |
|
|
97
97
|
| `mappersFileExtension` | `string` | (Default: `.mappers.ts`) The files with this extension provides mappers interfaces and types for the schema files in the same dir. |
|
|
98
98
|
| `mappersSuffix` | `string` | (Default: `Mapper`) Exported interfaces and types with this suffix from `mappersFile` in each module are put into the mappers object of [@graphql-codegen/typescript-resolvers](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-resolvers) . |
|
|
99
|
+
| `tsConfigFilePath` | `string` | (Default: `./tsconfig.json`) Project's TypeScript config, relative from project root. This helps type analysis such as resolving custom module paths. |
|
|
100
|
+
| `fixObjectTypeResolvers` | `smart` or `disabled` | (Default: `smart`) (Experimental) Statically compares object type's mapper types' field against schema types' fields, creating resolvers if required |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eddeee888/gcg-typescript-resolver-files",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/eddeee888/graphql-code-generator-plugins.git",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"graphql": "^15.0.0 || ^16.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@graphql-codegen/add": "^
|
|
31
|
-
"@graphql-codegen/plugin-helpers": "^
|
|
32
|
-
"@graphql-codegen/typescript": "^
|
|
33
|
-
"@graphql-codegen/typescript-resolvers": "^
|
|
30
|
+
"@graphql-codegen/add": "^4.0.0",
|
|
31
|
+
"@graphql-codegen/plugin-helpers": "^4.0.0",
|
|
32
|
+
"@graphql-codegen/typescript": "^3.0.0",
|
|
33
|
+
"@graphql-codegen/typescript-resolvers": "^3.0.0",
|
|
34
34
|
"graphql-scalars": "^1.20.1",
|
|
35
35
|
"ts-morph": "^16.0.0"
|
|
36
36
|
},
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { type SourceFile, Project } from 'ts-morph';
|
|
3
|
+
export declare const addVirtualTypesFileToTsMorphProject: ({ tsMorphProject, schemaAst, resolverTypesPath, resolverTypesConfig, }: {
|
|
4
|
+
tsMorphProject: Project;
|
|
5
|
+
schemaAst: GraphQLSchema;
|
|
6
|
+
resolverTypesPath: string;
|
|
7
|
+
resolverTypesConfig: Record<string, unknown>;
|
|
8
|
+
}) => Promise<SourceFile>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addVirtualTypesFileToTsMorphProject = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const typeScriptPlugin = require("@graphql-codegen/typescript");
|
|
6
|
+
const typeScriptResolversPlugin = require("@graphql-codegen/typescript-resolvers");
|
|
7
|
+
const addVirtualTypesFileToTsMorphProject = ({ tsMorphProject, schemaAst, resolverTypesPath, resolverTypesConfig, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
+
const typesFile = yield generateVirtualTypesFile({
|
|
9
|
+
schemaAst,
|
|
10
|
+
resolverTypesPath,
|
|
11
|
+
resolverTypesConfig,
|
|
12
|
+
});
|
|
13
|
+
const typesSourceFile = tsMorphProject.createSourceFile(typesFile.filePath, typesFile.content, { overwrite: true });
|
|
14
|
+
return typesSourceFile;
|
|
15
|
+
});
|
|
16
|
+
exports.addVirtualTypesFileToTsMorphProject = addVirtualTypesFileToTsMorphProject;
|
|
17
|
+
/**
|
|
18
|
+
* getVirtualTypesFile generates a virtual types.generated.ts file
|
|
19
|
+
* This is used to statically detect and compare types in the parse and post-process steps
|
|
20
|
+
*/
|
|
21
|
+
const generateVirtualTypesFile = ({ schemaAst, resolverTypesPath, resolverTypesConfig, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const [typescriptResult, typescriptResolversResult] = yield Promise.all([
|
|
24
|
+
typeScriptPlugin.plugin(schemaAst, [], resolverTypesConfig),
|
|
25
|
+
typeScriptResolversPlugin.plugin(schemaAst, [], resolverTypesConfig),
|
|
26
|
+
]);
|
|
27
|
+
return {
|
|
28
|
+
filePath: resolverTypesPath,
|
|
29
|
+
content: `
|
|
30
|
+
${(_a = typescriptResult.prepend) === null || _a === void 0 ? void 0 : _a.join('\n')}
|
|
31
|
+
${(_b = typescriptResolversResult.prepend) === null || _b === void 0 ? void 0 : _b.join('\n')}
|
|
32
|
+
${typescriptResult.content}${typescriptResolversResult.content}`,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=addVirtualTypesFileToTsMorphProject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addVirtualTypesFileToTsMorphProject.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.ts"],"names":[],"mappings":";;;;AAAA,gEAAgE;AAChE,mFAAmF;AAI5E,MAAM,mCAAmC,GAAG,CAAO,EACxD,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,mBAAmB,GAMpB,EAAuB,EAAE;IACxB,MAAM,SAAS,GAAG,MAAM,wBAAwB,CAAC;QAC/C,SAAS;QACT,iBAAiB;QACjB,mBAAmB;KACpB,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,CAAC;AACzB,CAAC,CAAA,CAAC;AAxBW,QAAA,mCAAmC,uCAwB9C;AAEF;;;GAGG;AACH,MAAM,wBAAwB,GAAG,CAAO,EACtC,SAAS,EACT,iBAAiB,EACjB,mBAAmB,GAKpB,EAGE,EAAE;;IACH,MAAM,CAAC,gBAAgB,EAAE,yBAAyB,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACtE,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,mBAAmB,CAAC;QAC3D,yBAAyB,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,mBAAmB,CAAC;KACrE,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ,EAAE,iBAAiB;QAC3B,OAAO,EAAE;MACP,MAAA,gBAAgB,CAAC,OAAO,0CAAE,IAAI,CAAC,IAAI,CAAC;MACpC,MAAA,yBAAyB,CAAC,OAAO,0CAAE,IAAI,CAAC,IAAI,CAAC;MAC7C,gBAAgB,CAAC,OAAO,GAAG,yBAAyB,CAAC,OAAO,EAAE;KACjE,CAAC;AACJ,CAAC,CAAA,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './addVirtualTypesFileToTsMorphProject';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/addVirtualTypesFileToTsMorphProject/index.ts"],"names":[],"mappings":";;;AAAA,gFAAsD"}
|
|
@@ -12,7 +12,8 @@ const addResolverMainFile = ({ config: { baseOutputDir, resolverTypesPath, resol
|
|
|
12
12
|
return res;
|
|
13
13
|
}
|
|
14
14
|
// Non Root Object fields that was generated
|
|
15
|
-
if (
|
|
15
|
+
if (file.__filetype === 'objectType' ||
|
|
16
|
+
file.__filetype === 'generalResolver') {
|
|
16
17
|
res.importLines.push((0, utils_1.printImportLine)({
|
|
17
18
|
isTypeImport: false,
|
|
18
19
|
module: (0, utils_1.relativeModulePath)(outputDir, filepath),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addResolverMainFile.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/addResolverMainFile.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,oCAKkB;AAGX,MAAM,mBAAmB,GAAG,CAAC,EAClC,MAAM,EAAE,EAAE,aAAa,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,EAC9D,MAAM,GACuB,EAAQ,EAAE;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CACxB,aAAa,EACb,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAC3C,CAAC;IACF,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEzC,MAAM,2BAA2B,GAAG,IAAA,0BAAkB,EACpD,SAAS,EACT,iBAAiB,CAClB,CAAC;IAEF,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAO1D,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;QACxB,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE;YAC9B,OAAO,GAAG,CAAC;SACZ;QAED,4CAA4C;QAC5C,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"addResolverMainFile.js","sourceRoot":"","sources":["../../../../../packages/typesc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C;AACJ,CAAC,CAAC;AAlKW,QAAA,mBAAmB,uBAkK9B;AAMF,MAAM,kBAAkB,GAAG,CAAC,EAC1B,YAAY,EACZ,cAAc,GACK,EAAU,EAAE,CAAC,GAAG,YAAY,KAAK,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type SourceFile } from 'ts-morph';
|
|
2
|
+
import type { ObjectTypeFile } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Ensure objectTypeResolver files have all the resolvers due to mismatched types
|
|
5
|
+
*/
|
|
6
|
+
export declare const ensureObjectTypeResolversAreGenerated: (sourceFile: SourceFile, resolverFile: ObjectTypeFile) => void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureObjectTypeResolversAreGenerated = 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 ensureObjectTypeResolversAreGenerated = (sourceFile, resolverFile) => {
|
|
10
|
+
const resolversToGenerate = resolverFile.meta.resolversToGenerate || {};
|
|
11
|
+
if (!Object.keys(resolversToGenerate).length) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const { variableStatement } = (0, getVariableStatementWithExpectedIdentifier_1.getVariableStatementWithExpectedIdentifier)(sourceFile, resolverFile);
|
|
15
|
+
if (!variableStatement) {
|
|
16
|
+
throw new Error('Missing variableStatement in ensureObjectTypeResolversAreGenerated.');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* FIXME: TS API does not expose `.isAssignable(Type, Type)` so we cannot use it to compare a field's type in schema type vs mapper type
|
|
20
|
+
*
|
|
21
|
+
* In this workaround, we try to put the type together and use TS's diagnostic tool to see if there's error:
|
|
22
|
+
* 1. If there's error, it means the mapper field cannot be safely mapped to schema field using GraphQL's default behaviour i.e. there will be runtime error
|
|
23
|
+
* In this case, we leave the resolver function as-is. There should be an error message from the parsing phrase explaining the types cannot be mapped.
|
|
24
|
+
* 2. If there's no error, it means we can safely remove the resolver and let GraphQL handle the mapping.
|
|
25
|
+
*
|
|
26
|
+
* Note: this only looks at fields that's not declared by the user. If it's already declared, we assume TS will report naturally if there's an error.
|
|
27
|
+
*/
|
|
28
|
+
// 1. Check to see which generated to-be-generated resolvers are implemented
|
|
29
|
+
const resolversData = Object.assign({}, resolversToGenerate);
|
|
30
|
+
variableStatement
|
|
31
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
|
|
32
|
+
.forEach((propertyAssignment) => {
|
|
33
|
+
const resolverName = propertyAssignment.getName();
|
|
34
|
+
if (resolversData[resolverName]) {
|
|
35
|
+
resolversData[resolverName].implemented = true;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
variableStatement
|
|
39
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.MethodDeclaration)
|
|
40
|
+
.forEach((methodDeclaration) => {
|
|
41
|
+
const resolverName = methodDeclaration.getName();
|
|
42
|
+
if (resolversData[resolverName]) {
|
|
43
|
+
resolversData[resolverName].implemented = true;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
// 2. Add missing resolver properties if they haven't been implemented
|
|
47
|
+
const addedPropertyAssignmentNodes = [];
|
|
48
|
+
Object.values(resolversData).forEach(({ resolverName, resolverDeclaration, implemented }) => {
|
|
49
|
+
if (!implemented) {
|
|
50
|
+
const addedNode = variableStatement
|
|
51
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)[0]
|
|
52
|
+
.addPropertyAssignment({
|
|
53
|
+
name: resolverName,
|
|
54
|
+
initializer: resolverDeclaration,
|
|
55
|
+
});
|
|
56
|
+
addedPropertyAssignmentNodes[addedNode.getStartLineNumber()] = {
|
|
57
|
+
node: addedNode,
|
|
58
|
+
__toBeRemoved: true,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
// 3. Check to see if there's error at the newly added properties:
|
|
63
|
+
// a. If there's error, leave it as user needs to manually map mapper type to schema type
|
|
64
|
+
// b. If there's no error, remove the node because GraphQL default mapping behaviour should work
|
|
65
|
+
sourceFile.getPreEmitDiagnostics().forEach((d) => {
|
|
66
|
+
const lineNumberWithError = d.getLineNumber();
|
|
67
|
+
// If erroring on a recently added line, do not remove as user needs to implement it
|
|
68
|
+
if (lineNumberWithError &&
|
|
69
|
+
addedPropertyAssignmentNodes[lineNumberWithError]) {
|
|
70
|
+
addedPropertyAssignmentNodes[lineNumberWithError].__toBeRemoved = false;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
Object.values(addedPropertyAssignmentNodes).forEach(({ node, __toBeRemoved }) => {
|
|
74
|
+
if (__toBeRemoved) {
|
|
75
|
+
node.remove();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
exports.ensureObjectTypeResolversAreGenerated = ensureObjectTypeResolversAreGenerated;
|
|
80
|
+
//# sourceMappingURL=ensureObjectTypeResolversAreGenerated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureObjectTypeResolversAreGenerated.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/ensureObjectTypeResolversAreGenerated.ts"],"names":[],"mappings":";;;AAAA,uCAA2E;AAE3E,6GAA0G;AAE1G;;GAEG;AACI,MAAM,qCAAqC,GAAG,CACnD,UAAsB,EACtB,YAA4B,EACtB,EAAE;IACR,MAAM,mBAAmB,GAAG,YAAY,CAAC,IAAI,CAAC,mBAAmB,IAAI,EAAE,CAAC;IACxE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,EAAE;QAC5C,OAAO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;aACjC,CAAC,CAAC;YAEL,4BAA4B,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC,GAAG;gBAC7D,IAAI,EAAE,SAAS;gBACf,aAAa,EAAE,IAAI;aACpB,CAAC;SACH;IACH,CAAC,CACF,CAAC;IAEF,kEAAkE;IAClE,4FAA4F;IAC5F,mGAAmG;IACnG,UAAU,CAAC,qBAAqB,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC/C,MAAM,mBAAmB,GAAG,CAAC,CAAC,aAAa,EAAE,CAAC;QAC9C,oFAAoF;QACpF,IACE,mBAAmB;YACnB,4BAA4B,CAAC,mBAAmB,CAAC,EACjD;YACA,4BAA4B,CAAC,mBAAmB,CAAC,CAAC,aAAa,GAAG,KAAK,CAAC;SACzE;IACH,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC,OAAO,CACjD,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE;QAC1B,IAAI,aAAa,EAAE;YACjB,IAAI,CAAC,MAAM,EAAE,CAAC;SACf;IACH,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAtGW,QAAA,qCAAqC,yCAsGhD"}
|
|
@@ -4,7 +4,7 @@ exports.generateResolverFiles = void 0;
|
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const addResolverMainFile_1 = require("./addResolverMainFile");
|
|
7
|
-
const
|
|
7
|
+
const postProcessFiles_1 = require("./postProcessFiles");
|
|
8
8
|
const handleGraphQLRootObjectTypeField_1 = require("./handleGraphQLRootObjectTypeField");
|
|
9
9
|
const handleGraphQLObjectType_1 = require("./handleGraphQLObjectType");
|
|
10
10
|
const handleGraphQLUninionType_1 = require("./handleGraphQLUninionType");
|
|
@@ -46,8 +46,8 @@ const generateResolverFiles = (ctx) => {
|
|
|
46
46
|
visitor,
|
|
47
47
|
}, ctx);
|
|
48
48
|
});
|
|
49
|
-
//
|
|
50
|
-
(0,
|
|
49
|
+
// Post process generated files (could be existing files or files to be generated)
|
|
50
|
+
(0, postProcessFiles_1.postProcessFiles)(ctx);
|
|
51
51
|
// Put all resolvers into a barrel file (or main file)
|
|
52
52
|
(0, addResolverMainFile_1.addResolverMainFile)(ctx);
|
|
53
53
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateResolverFiles.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/generateResolverFiles.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AACvC,oCAA+D;AAC/D,+DAA4D;AAC5D,
|
|
1
|
+
{"version":3,"file":"generateResolverFiles.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/generateResolverFiles.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AACvC,oCAA+D;AAC/D,+DAA4D;AAC5D,yDAAsD;AACtD,yFAAsF;AACtF,uEAAoE;AACpE,yEAAsE;AACtE,uEAAoE;AACpE,qDAAwE;AAGjE,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;YAChC,OAAO;SACR;QAED,EAAE;QACF,oBAAoB;QACpB,EAAE;QACF,MAAM,OAAO,GAAoC;YAC/C,mBAAmB,EAAE,mEAAgC;YACrD,UAAU,EAAE,iDAAuB;YACnC,SAAS,EAAE,mDAAwB;YACnC,UAAU,EAAE,iDAAuB;SACpC,CAAC;QAEF,IAAI,IAAA,wBAAgB,EAAC,UAAU,CAAC,IAAI,IAAA,sBAAY,EAAC,SAAS,CAAC,EAAE;YAC3D,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,CAAC;YACF,OAAO;SACR;QAED,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,sDAAsD;IACtD,IAAA,yCAAmB,EAAC,GAAG,CAAC,CAAC;AAC3B,CAAC,CAAC;AAtDW,QAAA,qBAAqB,yBAsDhC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceFile, VariableStatement } from 'ts-morph';
|
|
2
|
+
import type { ResolverFile } from './types';
|
|
3
|
+
export declare const getVariableStatementWithExpectedIdentifier: (sourceFile: SourceFile, resolverFile: ResolverFile) => {
|
|
4
|
+
variableStatement: VariableStatement | undefined;
|
|
5
|
+
isExported: boolean;
|
|
6
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVariableStatementWithExpectedIdentifier = void 0;
|
|
4
|
+
const getVariableStatementWithExpectedIdentifier = (sourceFile, resolverFile) => {
|
|
5
|
+
let isExported = false;
|
|
6
|
+
const variableStatementWithExpectedIdentifier = sourceFile.getVariableStatement((statement) => {
|
|
7
|
+
let hasExpectedIdentifier = false;
|
|
8
|
+
statement
|
|
9
|
+
.getDeclarationList()
|
|
10
|
+
.getDeclarations()
|
|
11
|
+
.forEach((declarationNode) => {
|
|
12
|
+
if (declarationNode.getName() === resolverFile.mainImportIdentifier) {
|
|
13
|
+
hasExpectedIdentifier = true;
|
|
14
|
+
if (statement.isExported()) {
|
|
15
|
+
isExported = true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return hasExpectedIdentifier;
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
variableStatement: variableStatementWithExpectedIdentifier,
|
|
23
|
+
isExported,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.getVariableStatementWithExpectedIdentifier = getVariableStatementWithExpectedIdentifier;
|
|
27
|
+
//# sourceMappingURL=getVariableStatementWithExpectedIdentifier.js.map
|
|
@@ -0,0 +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;gBACnE,qBAAqB,GAAG,IAAI,CAAC;gBAC7B,IAAI,SAAS,CAAC,UAAU,EAAE,EAAE;oBAC1B,UAAU,GAAG,IAAI,CAAC;iBACnB;aACF;QACH,CAAC,CAAC,CAAC;QACL,OAAO,qBAAqB,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEL,OAAO;QACL,iBAAiB,EAAE,uCAAuC;QAC1D,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,0CAA0C,8CA6BrD"}
|
|
@@ -2,22 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handleGraphQLObjectType = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
const handleGraphQLObjectType = ({ fieldFilePath, resolverName, normalizedResolverName, resolversTypeMeta }, { result }) => {
|
|
6
|
-
const
|
|
5
|
+
const handleGraphQLObjectType = ({ fieldFilePath, resolverName, normalizedResolverName, resolversTypeMeta }, { result, config: { graphQLObjectTypeResolversToGenerate } }) => {
|
|
6
|
+
const variableStatement = `export const ${resolverName}: ${resolversTypeMeta.typeString} = {
|
|
7
|
+
/* Implement ${resolverName} resolver logic here */
|
|
8
|
+
};`;
|
|
7
9
|
result.files[fieldFilePath] = {
|
|
8
|
-
__filetype: '
|
|
10
|
+
__filetype: 'objectType',
|
|
9
11
|
content: `
|
|
10
12
|
${(0, utils_1.printImportLine)({
|
|
11
13
|
isTypeImport: true,
|
|
12
14
|
module: resolversTypeMeta.module,
|
|
13
15
|
namedImports: [resolversTypeMeta.typeNamedImport],
|
|
14
16
|
})}
|
|
15
|
-
${
|
|
17
|
+
${variableStatement}`,
|
|
16
18
|
mainImportIdentifier: resolverName,
|
|
17
19
|
meta: {
|
|
18
|
-
belongsToRootObject: null,
|
|
19
20
|
normalizedResolverName,
|
|
20
|
-
|
|
21
|
+
variableStatement,
|
|
22
|
+
resolversToGenerate: graphQLObjectTypeResolversToGenerate[resolverName], // Array of all resolvers that may need type checking
|
|
21
23
|
},
|
|
22
24
|
};
|
|
23
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleGraphQLObjectType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLObjectType.ts"],"names":[],"mappings":";;;AACA,oCAA2C;AAEpC,MAAM,uBAAuB,GAAuB,CACzD,EAAE,aAAa,EAAE,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,EAC1E,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"handleGraphQLObjectType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLObjectType.ts"],"names":[],"mappings":";;;AACA,oCAA2C;AAEpC,MAAM,uBAAuB,GAAuB,CACzD,EAAE,aAAa,EAAE,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,EAC1E,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,oCAAoC,EAAE,EAAE,EAC5D,EAAE;IACF,MAAM,iBAAiB,GAAG,gBAAgB,YAAY,KAAK,iBAAiB,CAAC,UAAU;mBACtE,YAAY;KAC1B,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,YAAY,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC;SAClD,CAAC;MACA,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,sBAAsB;YACtB,iBAAiB;YACjB,mBAAmB,EAAE,oCAAoC,CAAC,YAAY,CAAC,EAAE,qDAAqD;SAC/H;KACF,CAAC;AACJ,CAAC,CAAC;AAxBW,QAAA,uBAAuB,2BAwBlC"}
|
|
@@ -3,20 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.handleGraphQLRootObjectTypeField = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const handleGraphQLRootObjectTypeField = ({ fieldFilePath, resolverName, belongsToRootObject, normalizedResolverName, resolversTypeMeta, }, { result }) => {
|
|
6
|
-
const
|
|
6
|
+
const variableStatement = `export const ${resolverName}: NonNullable<${resolversTypeMeta.typeString}> = async (_parent, _arg, _ctx) => { /* Implement ${normalizedResolverName} resolver logic here */ };`;
|
|
7
7
|
result.files[fieldFilePath] = {
|
|
8
|
-
__filetype: '
|
|
8
|
+
__filetype: 'rootObjectTypeFieldResolver',
|
|
9
9
|
content: `
|
|
10
10
|
${(0, utils_1.printImportLine)({
|
|
11
11
|
isTypeImport: true,
|
|
12
12
|
module: resolversTypeMeta.module,
|
|
13
13
|
namedImports: [resolversTypeMeta.typeNamedImport],
|
|
14
14
|
})}
|
|
15
|
-
${
|
|
15
|
+
${variableStatement}`,
|
|
16
16
|
mainImportIdentifier: resolverName,
|
|
17
17
|
meta: {
|
|
18
18
|
belongsToRootObject,
|
|
19
|
-
|
|
19
|
+
variableStatement,
|
|
20
20
|
normalizedResolverName,
|
|
21
21
|
},
|
|
22
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleGraphQLRootObjectTypeField.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLRootObjectTypeField.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"handleGraphQLRootObjectTypeField.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLRootObjectTypeField.ts"],"names":[],"mappings":";;;AAAA,oCAAgE;AAGzD,MAAM,gCAAgC,GAEzC,CACF,EACE,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,GAClB,EACD,EAAE,MAAM,EAAE,EACV,EAAE;IACF,MAAM,iBAAiB,GAAG,gBAAgB,YAAY,iBAAiB,iBAAiB,CAAC,UAAU,qDAAqD,sBAAsB,4BAA4B,CAAC;IAE3M,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,YAAY,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC;SAClD,CAAC;UACA,iBAAiB,EAAE;QACzB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,mBAAmB;YACnB,iBAAiB;YACjB,sBAAsB;SACvB;KACF,CAAC;AACJ,CAAC,CAAC;AA9BW,QAAA,gCAAgC,oCA8B3C"}
|
|
@@ -4,21 +4,20 @@ exports.handleGraphQLScalarType = void 0;
|
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const graphQLScalarType = 'GraphQLScalarType';
|
|
6
6
|
const handleGraphQLScalarType = ({ fieldFilePath, resolverName, normalizedResolverName }, { result }) => {
|
|
7
|
-
const
|
|
7
|
+
const variableStatement = `export const ${resolverName}: ${graphQLScalarType} = { /* Implement ${resolverName} scalar logic here */ };`;
|
|
8
8
|
result.files[fieldFilePath] = {
|
|
9
|
-
__filetype: '
|
|
9
|
+
__filetype: 'generalResolver',
|
|
10
10
|
content: `
|
|
11
11
|
${(0, utils_1.printImportLine)({
|
|
12
12
|
isTypeImport: true,
|
|
13
13
|
module: 'graphql',
|
|
14
14
|
namedImports: [graphQLScalarType],
|
|
15
15
|
})}
|
|
16
|
-
${
|
|
16
|
+
${variableStatement}`,
|
|
17
17
|
mainImportIdentifier: resolverName,
|
|
18
18
|
meta: {
|
|
19
|
-
belongsToRootObject: null,
|
|
20
19
|
normalizedResolverName,
|
|
21
|
-
|
|
20
|
+
variableStatement,
|
|
22
21
|
},
|
|
23
22
|
};
|
|
24
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleGraphQLScalarType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLScalarType.ts"],"names":[],"mappings":";;;AAAA,oCAA2C;AAG3C,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAEvC,MAAM,uBAAuB,GAAuB,CACzD,EAAE,aAAa,EAAE,YAAY,EAAE,sBAAsB,EAAE,EACvD,EAAE,MAAM,EAAE,EACV,EAAE;IACF,MAAM,
|
|
1
|
+
{"version":3,"file":"handleGraphQLScalarType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLScalarType.ts"],"names":[],"mappings":";;;AAAA,oCAA2C;AAG3C,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAEvC,MAAM,uBAAuB,GAAuB,CACzD,EAAE,aAAa,EAAE,YAAY,EAAE,sBAAsB,EAAE,EACvD,EAAE,MAAM,EAAE,EACV,EAAE;IACF,MAAM,iBAAiB,GAAG,gBAAgB,YAAY,KAAK,iBAAiB,qBAAqB,YAAY,0BAA0B,CAAC;IAExI,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,SAAS;YACjB,YAAY,EAAE,CAAC,iBAAiB,CAAC;SAClC,CAAC;MACA,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,sBAAsB;YACtB,iBAAiB;SAClB;KACF,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,uBAAuB,2BAqBlC"}
|
|
@@ -3,21 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.handleGraphQLUninionType = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const handleGraphQLUninionType = ({ fieldFilePath, resolverName, normalizedResolverName, resolversTypeMeta }, { result }) => {
|
|
6
|
-
const
|
|
6
|
+
const variableStatement = `export const ${resolverName}: ${resolversTypeMeta.typeString} = { __resolveType: (parent) => parent.__typename };`;
|
|
7
7
|
result.files[fieldFilePath] = {
|
|
8
|
-
__filetype: '
|
|
8
|
+
__filetype: 'generalResolver',
|
|
9
9
|
content: `
|
|
10
10
|
${(0, utils_1.printImportLine)({
|
|
11
11
|
isTypeImport: true,
|
|
12
12
|
module: resolversTypeMeta.module,
|
|
13
13
|
namedImports: [resolversTypeMeta.typeNamedImport],
|
|
14
14
|
})}
|
|
15
|
-
${
|
|
15
|
+
${variableStatement}`,
|
|
16
16
|
mainImportIdentifier: resolverName,
|
|
17
17
|
meta: {
|
|
18
|
-
belongsToRootObject: null,
|
|
19
18
|
normalizedResolverName,
|
|
20
|
-
|
|
19
|
+
variableStatement,
|
|
21
20
|
},
|
|
22
21
|
};
|
|
23
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleGraphQLUninionType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLUninionType.ts"],"names":[],"mappings":";;;AAAA,oCAA2C;AAGpC,MAAM,wBAAwB,GAAuB,CAC1D,EAAE,aAAa,EAAE,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,EAC1E,EAAE,MAAM,EAAE,EACV,EAAE;IACF,MAAM,
|
|
1
|
+
{"version":3,"file":"handleGraphQLUninionType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLUninionType.ts"],"names":[],"mappings":";;;AAAA,oCAA2C;AAGpC,MAAM,wBAAwB,GAAuB,CAC1D,EAAE,aAAa,EAAE,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,EAC1E,EAAE,MAAM,EAAE,EACV,EAAE;IACF,MAAM,iBAAiB,GAAG,gBAAgB,YAAY,KAAK,iBAAiB,CAAC,UAAU,sDAAsD,CAAC;IAE9I,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,YAAY,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC;SAClD,CAAC;MACA,iBAAiB,EAAE;QACrB,oBAAoB,EAAE,YAAY;QAClC,IAAI,EAAE;YACJ,sBAAsB;YACtB,iBAAiB;SAClB;KACF,CAAC;AACJ,CAAC,CAAC;AArBW,QAAA,wBAAwB,4BAqBnC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GenerateResolverFilesContext } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* postProcessFiles does static analysis on existing files OR to-be-generated files
|
|
4
|
+
* e.g.
|
|
5
|
+
* - Make sure correct variables are exported
|
|
6
|
+
* - Make sure object types have field resolvers if mapper type's field cannot be used as schema type's field
|
|
7
|
+
*/
|
|
8
|
+
export declare const postProcessFiles: ({ config: { tsMorph: { project }, fixObjectTypeResolvers, }, result, }: GenerateResolverFilesContext) => void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postProcessFiles = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const getVariableStatementWithExpectedIdentifier_1 = require("./getVariableStatementWithExpectedIdentifier");
|
|
6
|
+
const ensureObjectTypeResolversAreGenerated_1 = require("./ensureObjectTypeResolversAreGenerated");
|
|
7
|
+
/**
|
|
8
|
+
* postProcessFiles does static analysis on existing files OR to-be-generated files
|
|
9
|
+
* e.g.
|
|
10
|
+
* - Make sure correct variables are exported
|
|
11
|
+
* - Make sure object types have field resolvers if mapper type's field cannot be used as schema type's field
|
|
12
|
+
*/
|
|
13
|
+
const postProcessFiles = ({ config: { tsMorph: { project }, fixObjectTypeResolvers, }, result, }) => {
|
|
14
|
+
const sourceFilesToProcess = [];
|
|
15
|
+
Object.entries(result.files).forEach(([filePath, file]) => {
|
|
16
|
+
if (file.__filetype === 'file') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const existingSourceFile = project.addSourceFileAtPathIfExists(filePath);
|
|
20
|
+
if (existingSourceFile) {
|
|
21
|
+
sourceFilesToProcess.push({
|
|
22
|
+
sourceFile: existingSourceFile,
|
|
23
|
+
resolverFile: file,
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// If cannot find existing source files, load files that need post-processing into sourceFilesToProcess
|
|
28
|
+
if (file.__filetype === 'objectType') {
|
|
29
|
+
const virtualSourceFile = project.createSourceFile(filePath, file.content);
|
|
30
|
+
sourceFilesToProcess.push({
|
|
31
|
+
sourceFile: virtualSourceFile,
|
|
32
|
+
resolverFile: file,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
sourceFilesToProcess.forEach(({ sourceFile, resolverFile }) => {
|
|
37
|
+
const normalizedRelativePath = path.relative(process.cwd(), sourceFile.getFilePath());
|
|
38
|
+
// TODO: Check missing import
|
|
39
|
+
// ...
|
|
40
|
+
ensureExportedResolver(sourceFile, resolverFile);
|
|
41
|
+
if (fixObjectTypeResolvers === 'smart' &&
|
|
42
|
+
resolverFile.__filetype === 'objectType') {
|
|
43
|
+
(0, ensureObjectTypeResolversAreGenerated_1.ensureObjectTypeResolversAreGenerated)(sourceFile, resolverFile);
|
|
44
|
+
}
|
|
45
|
+
// Overwrite existing files with fixes
|
|
46
|
+
result.files[normalizedRelativePath] = Object.assign(Object.assign({}, resolverFile), { content: sourceFile.getText() });
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
exports.postProcessFiles = postProcessFiles;
|
|
50
|
+
/**
|
|
51
|
+
* Ensure correctly named resolvers are exported
|
|
52
|
+
*/
|
|
53
|
+
const ensureExportedResolver = (sourceFile, resolverFile) => {
|
|
54
|
+
const { variableStatement, isExported } = (0, getVariableStatementWithExpectedIdentifier_1.getVariableStatementWithExpectedIdentifier)(sourceFile, resolverFile);
|
|
55
|
+
if (!variableStatement) {
|
|
56
|
+
// Did not find variable statement with expected identifier, add it to the end with a warning
|
|
57
|
+
sourceFile.addStatements('/* WARNING: The following resolver was missing from this file. Make sure it is properly implemented or there could be runtime errors. */');
|
|
58
|
+
sourceFile.addStatements(resolverFile.meta.variableStatement);
|
|
59
|
+
}
|
|
60
|
+
else if (variableStatement && !isExported) {
|
|
61
|
+
// If has identifier but not exported
|
|
62
|
+
// Add export keyword to statement
|
|
63
|
+
const isExpectedIdentifierExported = Boolean(sourceFile
|
|
64
|
+
.getExportedDeclarations()
|
|
65
|
+
.get(resolverFile.mainImportIdentifier));
|
|
66
|
+
if (!isExpectedIdentifierExported) {
|
|
67
|
+
variableStatement.setIsExported(true);
|
|
68
|
+
}
|
|
69
|
+
// else, if identifier's been exported do nothing
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=postProcessFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postProcessFiles.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/postProcessFiles.ts"],"names":[],"mappings":";;;AACA,6BAA6B;AAE7B,6GAA0G;AAC1G,mGAAgG;AAEhG;;;;;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,UAAU,KAAK,MAAM,EAAE;YAC9B,OAAO;SACR;QAED,MAAM,kBAAkB,GAAG,OAAO,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC;QACzE,IAAI,kBAAkB,EAAE;YACt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,6FAA6F;QAC7F,UAAU,CAAC,aAAa,CACtB,0IAA0I,CAC3I,CAAC;QACF,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;KAC/D;SAAM,IAAI,iBAAiB,IAAI,CAAC,UAAU,EAAE;QAC3C,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;YACjC,iBAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;SACvC;QACD,iDAAiD;KAClD;AACH,CAAC,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { type SourceFile, Project } from 'ts-morph';
|
|
3
|
+
import type { GraphQLObjectTypeResolversToGenerate } from '../getGraphQLObjectTypeResolversToGenerate';
|
|
2
4
|
import type { ParseSourcesResult } from '../parseSources';
|
|
3
5
|
import type { ImportLineMeta, RootObjectType } from '../utils';
|
|
4
6
|
interface BaseVirtualFile {
|
|
@@ -9,14 +11,30 @@ interface BaseVirtualFile {
|
|
|
9
11
|
export interface StandardFile extends BaseVirtualFile {
|
|
10
12
|
__filetype: 'file';
|
|
11
13
|
}
|
|
12
|
-
export interface
|
|
13
|
-
__filetype: '
|
|
14
|
+
export interface GeneralResolverFile extends BaseVirtualFile {
|
|
15
|
+
__filetype: 'generalResolver';
|
|
14
16
|
meta: {
|
|
15
|
-
|
|
16
|
-
resolverVariableStatement: string;
|
|
17
|
+
variableStatement: string;
|
|
17
18
|
normalizedResolverName: string;
|
|
18
19
|
};
|
|
19
20
|
}
|
|
21
|
+
export interface RootObjectTypeFieldResolverFile extends BaseVirtualFile {
|
|
22
|
+
__filetype: 'rootObjectTypeFieldResolver';
|
|
23
|
+
meta: {
|
|
24
|
+
belongsToRootObject: RootObjectType;
|
|
25
|
+
variableStatement: string;
|
|
26
|
+
normalizedResolverName: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface ObjectTypeFile extends BaseVirtualFile {
|
|
30
|
+
__filetype: 'objectType';
|
|
31
|
+
meta: {
|
|
32
|
+
variableStatement: string;
|
|
33
|
+
normalizedResolverName: string;
|
|
34
|
+
resolversToGenerate?: GraphQLObjectTypeResolversToGenerate[number];
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export declare type ResolverFile = GeneralResolverFile | RootObjectTypeFieldResolverFile | ObjectTypeFile;
|
|
20
38
|
export interface GenerateResolverFilesContext {
|
|
21
39
|
config: {
|
|
22
40
|
schema: GraphQLSchema;
|
|
@@ -29,6 +47,12 @@ export interface GenerateResolverFilesContext {
|
|
|
29
47
|
whitelistedModules: string[];
|
|
30
48
|
blacklistedModules: string[];
|
|
31
49
|
externalResolvers: Record<string, string>;
|
|
50
|
+
tsMorph: {
|
|
51
|
+
project: Project;
|
|
52
|
+
typesSourceFile: SourceFile;
|
|
53
|
+
};
|
|
54
|
+
graphQLObjectTypeResolversToGenerate: GraphQLObjectTypeResolversToGenerate;
|
|
55
|
+
fixObjectTypeResolvers: 'smart' | 'disabled';
|
|
32
56
|
};
|
|
33
57
|
result: {
|
|
34
58
|
files: Record<string, StandardFile | ResolverFile>;
|
|
@@ -41,10 +65,10 @@ export interface GenerateResolverFilesContext {
|
|
|
41
65
|
}>;
|
|
42
66
|
};
|
|
43
67
|
}
|
|
44
|
-
export interface GraphQLTypeHandlerParams {
|
|
68
|
+
export interface GraphQLTypeHandlerParams<BelongsToRootObject = null> {
|
|
45
69
|
fieldFilePath: string;
|
|
46
70
|
resolverName: string;
|
|
47
|
-
belongsToRootObject:
|
|
71
|
+
belongsToRootObject: BelongsToRootObject;
|
|
48
72
|
normalizedResolverName: string;
|
|
49
73
|
resolversTypeMeta: {
|
|
50
74
|
typeNamedImport: `${string}Resolvers`;
|
|
@@ -52,5 +76,5 @@ export interface GraphQLTypeHandlerParams {
|
|
|
52
76
|
typeString: `${string}Resolvers` | `${RootObjectType}Resolvers['${string}']`;
|
|
53
77
|
};
|
|
54
78
|
}
|
|
55
|
-
export declare type GraphQLTypeHandler = (params: GraphQLTypeHandlerParams
|
|
79
|
+
export declare type GraphQLTypeHandler<BelongsToRootObject = null> = (params: GraphQLTypeHandlerParams<BelongsToRootObject>, ctx: GenerateResolverFilesContext) => void;
|
|
56
80
|
export {};
|