@eddeee888/gcg-typescript-resolver-files 0.18.0 → 0.18.2
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/dist/defineConfig.d.ts +1 -1
- package/dist/defineConfig.js +8 -0
- package/package.json +7 -3
- package/CHANGELOG.md +0 -816
- package/DEVELOPMENT.md +0 -49
- package/dist/tsconfig.lib.tsbuildinfo +0 -1
- package/eslint.config.mjs +0 -22
- package/project.json +0 -8
- package/src/addVirtualTypesFileToTsMorphProject/addVirtualTypesFileToTsMorphProject.ts +0 -109
- package/src/addVirtualTypesFileToTsMorphProject/index.ts +0 -1
- package/src/defineConfig.spec.ts +0 -76
- package/src/defineConfig.ts +0 -37
- package/src/generateResolverFiles/addExternalResolverImport.ts +0 -185
- package/src/generateResolverFiles/addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.spec.ts +0 -1174
- package/src/generateResolverFiles/addObjectTypeResolversPropertyAssignmentNodesIfNotImplemented.ts +0 -144
- package/src/generateResolverFiles/addResolverMainFiles.ts +0 -343
- package/src/generateResolverFiles/ensureEnumTypeResolversAreGenerated.ts +0 -51
- package/src/generateResolverFiles/generateResolverFiles.ts +0 -148
- package/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.spec.ts +0 -127
- package/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.ts +0 -25
- package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.spec.ts +0 -147
- package/src/generateResolverFiles/getVariableStatementWithExpectedIdentifier.ts +0 -34
- package/src/generateResolverFiles/handleGraphQLEnumType.ts +0 -100
- package/src/generateResolverFiles/handleGraphQLInterfaceType.ts +0 -70
- package/src/generateResolverFiles/handleGraphQLObjectType.ts +0 -171
- package/src/generateResolverFiles/handleGraphQLRootObjectTypeField.ts +0 -105
- package/src/generateResolverFiles/handleGraphQLScalarType.ts +0 -81
- package/src/generateResolverFiles/handleGraphQLUnionType.ts +0 -68
- package/src/generateResolverFiles/index.ts +0 -2
- package/src/generateResolverFiles/postProcessFiles.ts +0 -287
- package/src/generateResolverFiles/types.ts +0 -203
- package/src/generateResolverFiles/visitNamedType.ts +0 -66
- package/src/generateTypeDefsFiles/generateTypeDefsContent.ts +0 -15
- package/src/generateTypeDefsFiles/generateTypeDefsFiles.ts +0 -100
- package/src/generateTypeDefsFiles/index.ts +0 -1
- package/src/getGraphQLObjectTypeResolversToGenerate/getGraphQLObjectTypeResolversToGenerate.ts +0 -361
- package/src/getGraphQLObjectTypeResolversToGenerate/getNodePropertyMap.spec.ts +0 -115
- package/src/getGraphQLObjectTypeResolversToGenerate/getNodePropertyMap.ts +0 -88
- package/src/getGraphQLObjectTypeResolversToGenerate/index.ts +0 -1
- package/src/index.ts +0 -3
- package/src/normalizeAddConfigPath/index.ts +0 -1
- package/src/normalizeAddConfigPath/normalizeAddConfigPath.ts +0 -29
- package/src/parseGraphQLSchema/index.ts +0 -2
- package/src/parseGraphQLSchema/normalizeResolverName.ts +0 -28
- package/src/parseGraphQLSchema/parseGraphQLSchema.ts +0 -531
- package/src/parseGraphQLSchema/parseLocationForOutputDir.ts +0 -76
- package/src/parseSources/index.ts +0 -1
- package/src/parseSources/parseSources.ts +0 -83
- package/src/parseTypeMappers/collectTypeMappersFromSourceFile.spec.ts +0 -789
- package/src/parseTypeMappers/collectTypeMappersFromSourceFile.ts +0 -197
- package/src/parseTypeMappers/index.ts +0 -1
- package/src/parseTypeMappers/parseTypeMappers.ts +0 -75
- package/src/preset.ts +0 -317
- package/src/utils/cwd.ts +0 -8
- package/src/utils/fmt.ts +0 -16
- package/src/utils/index.ts +0 -12
- package/src/utils/isMatchResolverNamePattern.ts +0 -27
- package/src/utils/isNativeNamedType.ts +0 -21
- package/src/utils/isRootObjectType.ts +0 -8
- package/src/utils/isWhitelistedModule.spec.ts +0 -71
- package/src/utils/isWhitelistedModule.ts +0 -21
- package/src/utils/logger.ts +0 -14
- package/src/utils/normalizeImportExtension.spec.ts +0 -42
- package/src/utils/normalizeImportExtension.ts +0 -16
- package/src/utils/normalizeRelativePath.ts +0 -6
- package/src/utils/parseLocationForWhitelistedModule.spec.ts +0 -130
- package/src/utils/parseLocationForWhitelistedModule.ts +0 -38
- package/src/utils/printImportLine.spec.ts +0 -150
- package/src/utils/printImportLine.ts +0 -78
- package/src/utils/relativeModulePath.ts +0 -7
- package/src/validateAndMergeParsedConfigs/index.ts +0 -1
- package/src/validateAndMergeParsedConfigs/validateAndMergeParsedConfigs.spec.ts +0 -211
- package/src/validateAndMergeParsedConfigs/validateAndMergeParsedConfigs.ts +0 -92
- package/src/validatePresetConfig/index.ts +0 -1
- package/src/validatePresetConfig/validatePresetConfig.spec.ts +0 -706
- package/src/validatePresetConfig/validatePresetConfig.ts +0 -571
- package/tsconfig.json +0 -14
- package/tsconfig.lib.json +0 -18
- package/tsconfig.spec.json +0 -20
- package/vite.config.ts +0 -24
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { type SourceFile, type Identifier, SyntaxKind } from 'ts-morph';
|
|
3
|
-
import {
|
|
4
|
-
normalizeRelativePath,
|
|
5
|
-
normalizeImportExtension,
|
|
6
|
-
type ImportExtension,
|
|
7
|
-
} from '../utils/index.js';
|
|
8
|
-
import type { TypeMappersMap } from './parseTypeMappers.js';
|
|
9
|
-
|
|
10
|
-
export const collectTypeMappersFromSourceFile = (
|
|
11
|
-
{
|
|
12
|
-
typeMappersSourceFile,
|
|
13
|
-
typeMappersSuffix,
|
|
14
|
-
resolverTypesPath,
|
|
15
|
-
emitLegacyCommonJSImports,
|
|
16
|
-
importExtension,
|
|
17
|
-
}: {
|
|
18
|
-
typeMappersSourceFile: SourceFile;
|
|
19
|
-
typeMappersSuffix: string;
|
|
20
|
-
resolverTypesPath: string;
|
|
21
|
-
emitLegacyCommonJSImports: boolean;
|
|
22
|
-
importExtension?: ImportExtension;
|
|
23
|
-
},
|
|
24
|
-
result: TypeMappersMap
|
|
25
|
-
): void => {
|
|
26
|
-
// Look for interfaces with exported keywords
|
|
27
|
-
typeMappersSourceFile.getInterfaces().forEach((interfaceDeclaration) => {
|
|
28
|
-
if (!interfaceDeclaration.hasExportKeyword()) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
addTypeMapperDetailsIfValid(
|
|
33
|
-
{
|
|
34
|
-
kind: SyntaxKind.InterfaceDeclaration,
|
|
35
|
-
identifierNode: interfaceDeclaration.getNameNode(),
|
|
36
|
-
typeMappersSuffix,
|
|
37
|
-
typeMappersFilePath: typeMappersSourceFile.getFilePath(),
|
|
38
|
-
resolverTypesPath,
|
|
39
|
-
emitLegacyCommonJSImports,
|
|
40
|
-
importExtension,
|
|
41
|
-
},
|
|
42
|
-
result
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// Look for exported types with exported keywords
|
|
47
|
-
typeMappersSourceFile.getTypeAliases().forEach((typeAlias) => {
|
|
48
|
-
if (!typeAlias.hasExportKeyword()) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const identifierNode = typeAlias.getNameNode();
|
|
53
|
-
|
|
54
|
-
addTypeMapperDetailsIfValid(
|
|
55
|
-
{
|
|
56
|
-
kind: SyntaxKind.TypeAliasDeclaration,
|
|
57
|
-
identifierNode,
|
|
58
|
-
typeMappersSuffix,
|
|
59
|
-
typeMappersFilePath: typeMappersSourceFile.getFilePath(),
|
|
60
|
-
resolverTypesPath,
|
|
61
|
-
emitLegacyCommonJSImports,
|
|
62
|
-
importExtension,
|
|
63
|
-
},
|
|
64
|
-
result
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Look for named exports e.g.
|
|
69
|
-
// - export { something } from 'module';
|
|
70
|
-
// - export type { something } from 'module';
|
|
71
|
-
// - export { something, somethingelse as somethingelse2 }'
|
|
72
|
-
|
|
73
|
-
typeMappersSourceFile.getExportDeclarations().forEach((exportDeclaration) => {
|
|
74
|
-
exportDeclaration.getNamedExports().forEach((namedExport) => {
|
|
75
|
-
let identifierNode = namedExport.getNameNode();
|
|
76
|
-
const aliasNode = namedExport.getAliasNode();
|
|
77
|
-
if (aliasNode) {
|
|
78
|
-
identifierNode = aliasNode;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
addTypeMapperDetailsIfValid(
|
|
82
|
-
{
|
|
83
|
-
kind: SyntaxKind.ExportSpecifier,
|
|
84
|
-
identifierNode,
|
|
85
|
-
typeMappersSuffix,
|
|
86
|
-
typeMappersFilePath: typeMappersSourceFile.getFilePath(),
|
|
87
|
-
resolverTypesPath,
|
|
88
|
-
emitLegacyCommonJSImports,
|
|
89
|
-
importExtension,
|
|
90
|
-
},
|
|
91
|
-
result
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
typeMappersSourceFile.getClasses().forEach((classDeclaration) => {
|
|
97
|
-
if (!classDeclaration.hasExportKeyword()) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const identifierNode = classDeclaration.getNameNode();
|
|
101
|
-
if (!identifierNode) {
|
|
102
|
-
// Anonymous class is skipped
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
addTypeMapperDetailsIfValid(
|
|
107
|
-
{
|
|
108
|
-
kind: SyntaxKind.ClassDeclaration,
|
|
109
|
-
identifierNode,
|
|
110
|
-
typeMappersSuffix,
|
|
111
|
-
typeMappersFilePath: typeMappersSourceFile.getFilePath(),
|
|
112
|
-
resolverTypesPath,
|
|
113
|
-
emitLegacyCommonJSImports,
|
|
114
|
-
importExtension,
|
|
115
|
-
},
|
|
116
|
-
result
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const addTypeMapperDetailsIfValid = (
|
|
122
|
-
{
|
|
123
|
-
kind,
|
|
124
|
-
identifierNode,
|
|
125
|
-
typeMappersSuffix,
|
|
126
|
-
typeMappersFilePath,
|
|
127
|
-
resolverTypesPath,
|
|
128
|
-
emitLegacyCommonJSImports,
|
|
129
|
-
importExtension,
|
|
130
|
-
}: {
|
|
131
|
-
kind:
|
|
132
|
-
| SyntaxKind.InterfaceDeclaration
|
|
133
|
-
| SyntaxKind.TypeAliasDeclaration
|
|
134
|
-
| SyntaxKind.ExportSpecifier
|
|
135
|
-
| SyntaxKind.ClassDeclaration;
|
|
136
|
-
identifierNode: Identifier;
|
|
137
|
-
typeMappersSuffix: string;
|
|
138
|
-
typeMappersFilePath: string;
|
|
139
|
-
resolverTypesPath: string;
|
|
140
|
-
emitLegacyCommonJSImports: boolean;
|
|
141
|
-
importExtension?: ImportExtension;
|
|
142
|
-
},
|
|
143
|
-
result: TypeMappersMap
|
|
144
|
-
): void => {
|
|
145
|
-
const identifierName = identifierNode.getText();
|
|
146
|
-
if (!identifierName.endsWith(typeMappersSuffix)) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const [schemaType] = identifierName.split(typeMappersSuffix);
|
|
151
|
-
if (!schemaType) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* We MUST use path.relative() instead of path.posix.relative() here
|
|
157
|
-
* Reason being `typeMappersFilePath` is a file system path e.g. C://Windows/Path/To/File or /Unix/path/to/file
|
|
158
|
-
* path.relative works correctly but returns inconsistent path seperator e.g. relative\\path\\windows or relative/path/unix
|
|
159
|
-
*
|
|
160
|
-
* Therefore, we need to split/join to normalise the path to posix path e.g relative/path/unix
|
|
161
|
-
*/
|
|
162
|
-
const relativePath = path
|
|
163
|
-
.relative(path.dirname(resolverTypesPath), typeMappersFilePath)
|
|
164
|
-
.split(path.sep)
|
|
165
|
-
.join(path.posix.sep);
|
|
166
|
-
|
|
167
|
-
const parsedRelativePathFromResolverTypesToSourceFile =
|
|
168
|
-
path.parse(relativePath);
|
|
169
|
-
const relativeImportPathFromResolverTypesToSourceFile = normalizeRelativePath(
|
|
170
|
-
path.posix.join(
|
|
171
|
-
parsedRelativePathFromResolverTypesToSourceFile.dir,
|
|
172
|
-
parsedRelativePathFromResolverTypesToSourceFile.name
|
|
173
|
-
)
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
const fileExtension = normalizeImportExtension(
|
|
177
|
-
importExtension,
|
|
178
|
-
emitLegacyCommonJSImports
|
|
179
|
-
);
|
|
180
|
-
const configImportPath = `${relativeImportPathFromResolverTypesToSourceFile}${fileExtension}#${identifierName}`;
|
|
181
|
-
|
|
182
|
-
if (result[schemaType]) {
|
|
183
|
-
throw new Error(
|
|
184
|
-
`GraphQL type "${schemaType}" has duplicated "${identifierName}" mappers:\n - ${configImportPath}\n - ${result[schemaType].configImportPath}`
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
result[schemaType] = {
|
|
189
|
-
schemaType,
|
|
190
|
-
mapper: {
|
|
191
|
-
name: identifierName,
|
|
192
|
-
filename: typeMappersFilePath,
|
|
193
|
-
kind,
|
|
194
|
-
},
|
|
195
|
-
configImportPath,
|
|
196
|
-
};
|
|
197
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './parseTypeMappers.js';
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import type { Project, SyntaxKind } from 'ts-morph';
|
|
3
|
-
import type { ParseSourcesResult } from '../parseSources/index.js';
|
|
4
|
-
import type { ImportExtension } from '../utils/index.js';
|
|
5
|
-
import { collectTypeMappersFromSourceFile } from './collectTypeMappersFromSourceFile.js';
|
|
6
|
-
|
|
7
|
-
export interface ParseTypeMappersParams {
|
|
8
|
-
sourceMap: ParseSourcesResult['sourceMap'];
|
|
9
|
-
resolverTypesPath: string;
|
|
10
|
-
typeMappersRelativeTargetDir: string;
|
|
11
|
-
typeMappersFileExtension: string;
|
|
12
|
-
typeMappersSuffix: string;
|
|
13
|
-
tsMorphProject: Project;
|
|
14
|
-
emitLegacyCommonJSImports: boolean;
|
|
15
|
-
importExtension: ImportExtension;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface TypeMapperDetails {
|
|
19
|
-
schemaType: string;
|
|
20
|
-
mapper: {
|
|
21
|
-
name: string;
|
|
22
|
-
filename: string; // e.g. /path/to/schema.mappers.ts
|
|
23
|
-
kind:
|
|
24
|
-
| SyntaxKind.InterfaceDeclaration
|
|
25
|
-
| SyntaxKind.TypeAliasDeclaration
|
|
26
|
-
| SyntaxKind.ExportSpecifier
|
|
27
|
-
| SyntaxKind.ClassDeclaration;
|
|
28
|
-
};
|
|
29
|
-
configImportPath: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type TypeMappersMap = Record<string, TypeMapperDetails>;
|
|
33
|
-
|
|
34
|
-
export const parseTypeMappers = ({
|
|
35
|
-
sourceMap,
|
|
36
|
-
resolverTypesPath,
|
|
37
|
-
typeMappersRelativeTargetDir,
|
|
38
|
-
typeMappersFileExtension,
|
|
39
|
-
typeMappersSuffix,
|
|
40
|
-
tsMorphProject,
|
|
41
|
-
emitLegacyCommonJSImports,
|
|
42
|
-
importExtension,
|
|
43
|
-
}: ParseTypeMappersParams): TypeMappersMap => {
|
|
44
|
-
const result = Object.entries(sourceMap).reduce<TypeMappersMap>(
|
|
45
|
-
(res, [_, { sourcePath }]) => {
|
|
46
|
-
const typeMapperFilePath = path.posix.join(
|
|
47
|
-
sourcePath.dir,
|
|
48
|
-
typeMappersRelativeTargetDir,
|
|
49
|
-
`${sourcePath.name}${typeMappersFileExtension}`
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const typeMappersSourceFile =
|
|
53
|
-
tsMorphProject.addSourceFileAtPathIfExists(typeMapperFilePath);
|
|
54
|
-
|
|
55
|
-
if (!typeMappersSourceFile) {
|
|
56
|
-
return res;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
collectTypeMappersFromSourceFile(
|
|
60
|
-
{
|
|
61
|
-
typeMappersSourceFile,
|
|
62
|
-
typeMappersSuffix,
|
|
63
|
-
resolverTypesPath,
|
|
64
|
-
emitLegacyCommonJSImports,
|
|
65
|
-
importExtension,
|
|
66
|
-
},
|
|
67
|
-
res
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
return res;
|
|
71
|
-
},
|
|
72
|
-
{}
|
|
73
|
-
);
|
|
74
|
-
return result;
|
|
75
|
-
};
|
package/src/preset.ts
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import * as addPlugin from '@graphql-codegen/add';
|
|
3
|
-
import * as schemaAstPlugin from '@graphql-codegen/schema-ast';
|
|
4
|
-
import * as typeScriptPlugin from '@graphql-codegen/typescript';
|
|
5
|
-
import { plugin as typeScriptResolversPlugin } from '@graphql-codegen/typescript-resolvers';
|
|
6
|
-
import {
|
|
7
|
-
type Types,
|
|
8
|
-
createNoopProfiler,
|
|
9
|
-
} from '@graphql-codegen/plugin-helpers';
|
|
10
|
-
import { Project } from 'ts-morph';
|
|
11
|
-
import { defineConfig as defineServerConfig } from '@eddeee888/gcg-server-config';
|
|
12
|
-
import { parseSources } from './parseSources/index.js';
|
|
13
|
-
import { parseGraphQLSchema } from './parseGraphQLSchema/index.js';
|
|
14
|
-
import {
|
|
15
|
-
type GenerateResolverFilesContext,
|
|
16
|
-
generateResolverFiles,
|
|
17
|
-
} from './generateResolverFiles/index.js';
|
|
18
|
-
import { generateTypeDefsFiles } from './generateTypeDefsFiles/index.js';
|
|
19
|
-
import { getGraphQLObjectTypeResolversToGenerate } from './getGraphQLObjectTypeResolversToGenerate/index.js';
|
|
20
|
-
import { addVirtualTypesFileToTsMorphProject } from './addVirtualTypesFileToTsMorphProject/index.js';
|
|
21
|
-
import { parseTypeMappers } from './parseTypeMappers/index.js';
|
|
22
|
-
import {
|
|
23
|
-
type RawPresetConfig,
|
|
24
|
-
validatePresetConfig,
|
|
25
|
-
} from './validatePresetConfig/index.js';
|
|
26
|
-
import { validateAndMergeParsedConfigs } from './validateAndMergeParsedConfigs/index.js';
|
|
27
|
-
import { normalizeAddConfigPath } from './normalizeAddConfigPath/index.js';
|
|
28
|
-
import { logger } from './utils/index.js';
|
|
29
|
-
|
|
30
|
-
export const presetName = '@eddeee888/gcg-typescript-resolver-files';
|
|
31
|
-
|
|
32
|
-
export const preset: Types.OutputPreset<RawPresetConfig> = {
|
|
33
|
-
buildGeneratesSection: async ({
|
|
34
|
-
schema,
|
|
35
|
-
schemaAst,
|
|
36
|
-
presetConfig: rawPresetConfig,
|
|
37
|
-
baseOutputDir,
|
|
38
|
-
config: baseConfig,
|
|
39
|
-
profiler = createNoopProfiler(),
|
|
40
|
-
}) => {
|
|
41
|
-
if (!schemaAst) {
|
|
42
|
-
throw new Error('Missing schemaAst');
|
|
43
|
-
}
|
|
44
|
-
const sources = schemaAst.extensions.extendedSources;
|
|
45
|
-
if (!Array.isArray(sources) || sources.length === 0) {
|
|
46
|
-
throw new Error(
|
|
47
|
-
'Empty Sources. Make sure schema files are parsed correctly.'
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const {
|
|
52
|
-
add,
|
|
53
|
-
resolverTypesPath: relativeResolverTypesPathFromBaseOutputDir,
|
|
54
|
-
resolverRelativeTargetDir,
|
|
55
|
-
mappersRelativeTargetDir: typeMappersRelativeTargetDir,
|
|
56
|
-
mappersFileExtension: typeMappersFileExtension,
|
|
57
|
-
mappersSuffix: typeMappersSuffix,
|
|
58
|
-
resolverMainFile,
|
|
59
|
-
resolverMainFileMode,
|
|
60
|
-
resolverGeneration,
|
|
61
|
-
typeDefsFilePath,
|
|
62
|
-
typeDefsFileMode,
|
|
63
|
-
mergeSchema,
|
|
64
|
-
moduleNamingMode,
|
|
65
|
-
scalarsModule,
|
|
66
|
-
scalarsOverrides,
|
|
67
|
-
mode,
|
|
68
|
-
whitelistedModules,
|
|
69
|
-
blacklistedModules,
|
|
70
|
-
externalResolvers,
|
|
71
|
-
typesPluginsConfig,
|
|
72
|
-
tsMorphProjectOptions,
|
|
73
|
-
fixObjectTypeResolvers,
|
|
74
|
-
emitLegacyCommonJSImports,
|
|
75
|
-
importExtension,
|
|
76
|
-
} = validatePresetConfig(rawPresetConfig, baseConfig);
|
|
77
|
-
|
|
78
|
-
const resolverTypesPath = path.posix.join(
|
|
79
|
-
baseOutputDir,
|
|
80
|
-
relativeResolverTypesPathFromBaseOutputDir
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const normalizedAdd = normalizeAddConfigPath({ add, baseOutputDir });
|
|
84
|
-
|
|
85
|
-
const { sourceMap } = parseSources({
|
|
86
|
-
sources,
|
|
87
|
-
baseOutputDir,
|
|
88
|
-
moduleNamingMode,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const tsMorphProject = await profiler.run(
|
|
92
|
-
async () => new Project(tsMorphProjectOptions),
|
|
93
|
-
createProfilerRunName('Initialising ts-morph project')
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
const typeMappersMap = await profiler.run(
|
|
97
|
-
async () =>
|
|
98
|
-
parseTypeMappers({
|
|
99
|
-
sourceMap,
|
|
100
|
-
resolverTypesPath,
|
|
101
|
-
typeMappersRelativeTargetDir,
|
|
102
|
-
typeMappersFileExtension,
|
|
103
|
-
typeMappersSuffix,
|
|
104
|
-
tsMorphProject,
|
|
105
|
-
emitLegacyCommonJSImports,
|
|
106
|
-
importExtension,
|
|
107
|
-
}),
|
|
108
|
-
createProfilerRunName('parseTypeMappers')
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
const generatesSection: Types.GenerateOptions[] = [];
|
|
112
|
-
|
|
113
|
-
const parsedGraphQLSchemaMeta = await profiler.run(
|
|
114
|
-
async () =>
|
|
115
|
-
parseGraphQLSchema({
|
|
116
|
-
schemaAst,
|
|
117
|
-
sourceMap,
|
|
118
|
-
resolverTypesPath,
|
|
119
|
-
scalarsModule,
|
|
120
|
-
scalarsOverrides,
|
|
121
|
-
typeMappersMap,
|
|
122
|
-
mode,
|
|
123
|
-
baseOutputDir,
|
|
124
|
-
resolverRelativeTargetDir,
|
|
125
|
-
whitelistedModules,
|
|
126
|
-
blacklistedModules,
|
|
127
|
-
}),
|
|
128
|
-
createProfilerRunName('parseGraphQLSchema')
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const mergedConfig = validateAndMergeParsedConfigs({
|
|
132
|
-
unmanagedNonScalarResolvers: externalResolvers,
|
|
133
|
-
parsedGraphQLSchemaMeta,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// typescript and typescript-resolvers plugins config
|
|
137
|
-
const resolverTypesConfig = defineServerConfig({
|
|
138
|
-
optionalResolveType: true,
|
|
139
|
-
resolversNonOptionalTypename: {
|
|
140
|
-
unionMember: true,
|
|
141
|
-
interfaceImplementingType: true,
|
|
142
|
-
},
|
|
143
|
-
namingConvention: 'keep',
|
|
144
|
-
emitLegacyCommonJSImports,
|
|
145
|
-
...typesPluginsConfig,
|
|
146
|
-
scalars: mergedConfig.scalarTypes,
|
|
147
|
-
mappers: {
|
|
148
|
-
...mergedConfig.typeMappers,
|
|
149
|
-
...typesPluginsConfig.mappers,
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
// typesSourceFile is the virtual `types.generated.ts`
|
|
154
|
-
// This is useful when we need to do static analysis as most types come from this file
|
|
155
|
-
// e.g. comparing mappers field type vs schema object field type
|
|
156
|
-
const { typesSourceFile, meta: generatedTypesFileMeta } =
|
|
157
|
-
await profiler.run(
|
|
158
|
-
() =>
|
|
159
|
-
addVirtualTypesFileToTsMorphProject({
|
|
160
|
-
tsMorphProject,
|
|
161
|
-
schemaAst,
|
|
162
|
-
resolverTypesConfig,
|
|
163
|
-
resolverTypesPath,
|
|
164
|
-
addConfig: normalizedAdd?.[resolverTypesPath],
|
|
165
|
-
}),
|
|
166
|
-
createProfilerRunName('addVirtualTypesFileToTsMorphProject')
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
const graphQLObjectTypeResolversToGenerate = await profiler.run(
|
|
170
|
-
async () =>
|
|
171
|
-
fixObjectTypeResolvers.object === 'disabled'
|
|
172
|
-
? {}
|
|
173
|
-
: getGraphQLObjectTypeResolversToGenerate({
|
|
174
|
-
mode: fixObjectTypeResolvers.object,
|
|
175
|
-
tsMorphProject,
|
|
176
|
-
typesSourceFile,
|
|
177
|
-
userDefinedSchemaObjectTypeMap:
|
|
178
|
-
mergedConfig.userDefinedSchemaTypeMap.object,
|
|
179
|
-
typeMappersMap,
|
|
180
|
-
generatedTypesFileMeta,
|
|
181
|
-
}),
|
|
182
|
-
createProfilerRunName('getGraphQLObjectTypeResolversToGenerate')
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
const resolverTypesFilePlugins: Types.PluginConfig[] = [
|
|
186
|
-
{ typescript: {} },
|
|
187
|
-
{ ['typescript-resolvers']: {} },
|
|
188
|
-
];
|
|
189
|
-
if (normalizedAdd?.[resolverTypesPath]) {
|
|
190
|
-
resolverTypesFilePlugins.push({
|
|
191
|
-
add: normalizedAdd[resolverTypesPath],
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
const resolverTypesFile: Types.GenerateOptions = {
|
|
195
|
-
filename: resolverTypesPath,
|
|
196
|
-
pluginMap: {
|
|
197
|
-
typescript: typeScriptPlugin,
|
|
198
|
-
'typescript-resolvers': { plugin: typeScriptResolversPlugin },
|
|
199
|
-
add: addPlugin,
|
|
200
|
-
},
|
|
201
|
-
plugins: resolverTypesFilePlugins,
|
|
202
|
-
config: resolverTypesConfig,
|
|
203
|
-
schema,
|
|
204
|
-
documents: [],
|
|
205
|
-
};
|
|
206
|
-
generatesSection.push(resolverTypesFile);
|
|
207
|
-
|
|
208
|
-
// typeDefs
|
|
209
|
-
if (typeDefsFilePath) {
|
|
210
|
-
const typeDefsFiles = await profiler.run(async () => {
|
|
211
|
-
return generateTypeDefsFiles({
|
|
212
|
-
baseOutputDir,
|
|
213
|
-
typeDefsFilePath,
|
|
214
|
-
typeDefsFileMode,
|
|
215
|
-
sourceMap,
|
|
216
|
-
whitelistedModules,
|
|
217
|
-
blacklistedModules,
|
|
218
|
-
});
|
|
219
|
-
}, createProfilerRunName('generateTypeDefsFiles'));
|
|
220
|
-
|
|
221
|
-
Object.entries(typeDefsFiles).forEach(([filename, meta]) => {
|
|
222
|
-
const typeDefsFile: Types.GenerateOptions = {
|
|
223
|
-
filename: filename,
|
|
224
|
-
pluginMap: { add: addPlugin },
|
|
225
|
-
plugins: [{ add: { content: meta.content } }],
|
|
226
|
-
config: {},
|
|
227
|
-
schema,
|
|
228
|
-
documents: [],
|
|
229
|
-
};
|
|
230
|
-
generatesSection.push(typeDefsFile);
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// merge schema
|
|
235
|
-
if (mergeSchema) {
|
|
236
|
-
generatesSection.push({
|
|
237
|
-
filename: path.posix.join(baseOutputDir, mergeSchema.path),
|
|
238
|
-
pluginMap: { ['schema-ast']: schemaAstPlugin },
|
|
239
|
-
plugins: [{ ['schema-ast']: {} }],
|
|
240
|
-
schema,
|
|
241
|
-
documents: [],
|
|
242
|
-
config: mergeSchema.config,
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// resolver files
|
|
247
|
-
const result: GenerateResolverFilesContext['result'] = {
|
|
248
|
-
files: {},
|
|
249
|
-
externalImports: {},
|
|
250
|
-
};
|
|
251
|
-
await profiler.run(
|
|
252
|
-
async () =>
|
|
253
|
-
generateResolverFiles({
|
|
254
|
-
config: {
|
|
255
|
-
baseOutputDir,
|
|
256
|
-
resolverTypesPath,
|
|
257
|
-
resolverRelativeTargetDir,
|
|
258
|
-
resolverMainFile,
|
|
259
|
-
resolverMainFileMode,
|
|
260
|
-
resolverGeneration,
|
|
261
|
-
typeMappersMap,
|
|
262
|
-
parsedGraphQLSchemaMeta,
|
|
263
|
-
graphQLObjectTypeResolversToGenerate,
|
|
264
|
-
tsMorph: {
|
|
265
|
-
project: tsMorphProject,
|
|
266
|
-
typesSourceFile,
|
|
267
|
-
},
|
|
268
|
-
fixObjectTypeResolvers,
|
|
269
|
-
unmanagedResolvers: {
|
|
270
|
-
...mergedConfig.unmanagedResolvers,
|
|
271
|
-
},
|
|
272
|
-
emitLegacyCommonJSImports,
|
|
273
|
-
importExtension,
|
|
274
|
-
generatedTypesFileMeta,
|
|
275
|
-
},
|
|
276
|
-
result,
|
|
277
|
-
}),
|
|
278
|
-
createProfilerRunName('generateResolverFiles')
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
const resultFilesArray = Object.entries(result.files);
|
|
282
|
-
const resolverFilesGenerateOptions: Types.GenerateOptions[] =
|
|
283
|
-
resultFilesArray
|
|
284
|
-
.filter(([_, file]) => {
|
|
285
|
-
// Only generate files that are:
|
|
286
|
-
// 1. `virtual` - because file doesn't exist yet
|
|
287
|
-
// 2. on `filesystem` and with `contentUpdated` - because file content has been updated, so we want to apply the changes
|
|
288
|
-
return (
|
|
289
|
-
file.filesystem.type === 'virtual' ||
|
|
290
|
-
(file.filesystem.type === 'filesystem' &&
|
|
291
|
-
file.filesystem.contentUpdated === true)
|
|
292
|
-
);
|
|
293
|
-
})
|
|
294
|
-
.map(([filename, { content }]) => {
|
|
295
|
-
return {
|
|
296
|
-
filename,
|
|
297
|
-
pluginMap: { add: addPlugin },
|
|
298
|
-
plugins: [{ add: { content } }],
|
|
299
|
-
config: {},
|
|
300
|
-
schema,
|
|
301
|
-
documents: [],
|
|
302
|
-
};
|
|
303
|
-
});
|
|
304
|
-
logger.debug(
|
|
305
|
-
`Applying changes to ${resolverFilesGenerateOptions.length}/${
|
|
306
|
-
resultFilesArray.length
|
|
307
|
-
} files. (${
|
|
308
|
-
resultFilesArray.length - resolverFilesGenerateOptions.length
|
|
309
|
-
} skipped files because they are already on filesystem and are not updated)`
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
return [...resolverFilesGenerateOptions, ...generatesSection];
|
|
313
|
-
},
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
const createProfilerRunName = (traceName: string): string =>
|
|
317
|
-
`[${presetName}]: ${traceName}`;
|
package/src/utils/cwd.ts
DELETED
package/src/utils/fmt.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { presetName } from '../preset.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Shared message formatter
|
|
5
|
-
*/
|
|
6
|
-
export const fmt = {
|
|
7
|
-
error: (input: string, type: 'Validation'): string => {
|
|
8
|
-
return `[${presetName}] \x1b[31mERROR:\x1b[0m ${type} - ${input}`;
|
|
9
|
-
},
|
|
10
|
-
warn: (input: string): string => {
|
|
11
|
-
return `[${presetName}] \x1b[33mWARN:\x1b[0m ${input}`;
|
|
12
|
-
},
|
|
13
|
-
debug: (input: string): string => {
|
|
14
|
-
return `[${presetName}] \x1b[35mDEBUG:\x1b[0m ${input}`;
|
|
15
|
-
},
|
|
16
|
-
};
|
package/src/utils/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from './cwd.js';
|
|
2
|
-
export * from './logger.js';
|
|
3
|
-
export * from './fmt.js';
|
|
4
|
-
export * from './parseLocationForWhitelistedModule.js';
|
|
5
|
-
export * from './isNativeNamedType.js';
|
|
6
|
-
export * from './isRootObjectType.js';
|
|
7
|
-
export * from './isWhitelistedModule.js';
|
|
8
|
-
export * from './printImportLine.js';
|
|
9
|
-
export * from './normalizeRelativePath.js';
|
|
10
|
-
export * from './relativeModulePath.js';
|
|
11
|
-
export * from './isMatchResolverNamePattern.js';
|
|
12
|
-
export * from './normalizeImportExtension.js';
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import micromatch from 'micromatch';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @description Wrapper function to return true if `value` matches on of the `pattern`s
|
|
5
|
-
*/
|
|
6
|
-
export const isMatchResolverNamePattern = ({
|
|
7
|
-
pattern,
|
|
8
|
-
value,
|
|
9
|
-
}: {
|
|
10
|
-
pattern: string | string[];
|
|
11
|
-
value: string;
|
|
12
|
-
}): boolean => {
|
|
13
|
-
const normalizedPatterns = typeof pattern === 'string' ? [pattern] : pattern;
|
|
14
|
-
const nonEmptyNormalizedPatterns = normalizedPatterns.filter(Boolean);
|
|
15
|
-
|
|
16
|
-
const matchedValues = micromatch([value], nonEmptyNormalizedPatterns, {
|
|
17
|
-
// `micromatch` mainly matches filesystems whilst we want this function
|
|
18
|
-
// to match object-like path pattern e.g.
|
|
19
|
-
// - `book.Query.books`
|
|
20
|
-
// - `book.Book`
|
|
21
|
-
// - `.BookResult` (in the case where module mode are merged i.e. `mode=merged`)
|
|
22
|
-
// so set `dot=true` to treat `.` the same as other characters
|
|
23
|
-
dot: true,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return matchedValues.length > 0;
|
|
27
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type GraphQLNamedType,
|
|
3
|
-
isIntrospectionType,
|
|
4
|
-
isSpecifiedScalarType,
|
|
5
|
-
} from 'graphql';
|
|
6
|
-
|
|
7
|
-
export const isNativeNamedType = (namedType: GraphQLNamedType): boolean => {
|
|
8
|
-
// "Native" NamedType in this context means the following:
|
|
9
|
-
// 1. introspection types i.e. with `__` prefixes
|
|
10
|
-
// 2. base scalars e.g. Boolean, Int, etc.
|
|
11
|
-
// 3. Other natives (mostly base scalars) which was not defined in the schema i.e. no `astNode`
|
|
12
|
-
if (
|
|
13
|
-
isSpecifiedScalarType(namedType) ||
|
|
14
|
-
isIntrospectionType(namedType) ||
|
|
15
|
-
!namedType.astNode
|
|
16
|
-
) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return false;
|
|
21
|
-
};
|