@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,571 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import type { AddPluginConfig } from '@graphql-codegen/add';
|
|
4
|
-
import type * as typeScriptPlugin from '@graphql-codegen/typescript';
|
|
5
|
-
import type * as typeScriptResolversPlugin from '@graphql-codegen/typescript-resolvers';
|
|
6
|
-
import type * as schemaAstPlugin from '@graphql-codegen/schema-ast';
|
|
7
|
-
import type { ProjectOptions } from 'ts-morph';
|
|
8
|
-
import {
|
|
9
|
-
cwd,
|
|
10
|
-
fmt,
|
|
11
|
-
logger,
|
|
12
|
-
normalizeImportExtension,
|
|
13
|
-
type ImportExtension,
|
|
14
|
-
} from '../utils/index.js';
|
|
15
|
-
|
|
16
|
-
const defaultResolverRelativeTargetDirMap: Record<
|
|
17
|
-
ParsedPresetConfig['mode'],
|
|
18
|
-
string
|
|
19
|
-
> = {
|
|
20
|
-
modules: 'resolvers',
|
|
21
|
-
merged: '',
|
|
22
|
-
};
|
|
23
|
-
const defaultTypeDefsFilePath = './typeDefs.generated.ts';
|
|
24
|
-
const defaultScalarsModule = 'graphql-scalars';
|
|
25
|
-
|
|
26
|
-
type ParsedTypesPluginsConfig = Omit<
|
|
27
|
-
typeScriptPlugin.TypeScriptPluginConfig &
|
|
28
|
-
typeScriptResolversPlugin.TypeScriptResolversPluginConfig,
|
|
29
|
-
'scalars' | 'emitLegacyCommonJSImports' | 'importExtension'
|
|
30
|
-
>;
|
|
31
|
-
type ConfigMode = 'merged' | 'modules';
|
|
32
|
-
type ResolverMainFileMode = 'merged' | 'modules';
|
|
33
|
-
export type TypeDefsFileMode = 'merged' | 'mergedWhitelisted' | 'modules';
|
|
34
|
-
type StringFixObjectTypeResolvers = 'smart' | 'fast' | 'disabled';
|
|
35
|
-
type NormalizedFixObjectTypeResolvers = {
|
|
36
|
-
object: 'smart' | 'fast' | 'disabled';
|
|
37
|
-
enum: 'smart' | 'fast' | 'disabled';
|
|
38
|
-
};
|
|
39
|
-
type StringResolverGeneration = 'disabled' | 'recommended' | 'minimal' | 'all';
|
|
40
|
-
type NormalizedResolverGeneration = {
|
|
41
|
-
query: string | string[];
|
|
42
|
-
mutation: string | string[];
|
|
43
|
-
subscription: string | string[];
|
|
44
|
-
scalar: string | string[];
|
|
45
|
-
object: string | string[];
|
|
46
|
-
union: string | string[];
|
|
47
|
-
interface: string | string[];
|
|
48
|
-
enum: string | string[];
|
|
49
|
-
};
|
|
50
|
-
export type ModuleNamingMode = number | 'all';
|
|
51
|
-
|
|
52
|
-
export type ScalarsOverridesType = string | { input: string; output: string };
|
|
53
|
-
|
|
54
|
-
export interface ParsedPresetConfig {
|
|
55
|
-
add?: Record<string, AddPluginConfig>;
|
|
56
|
-
resolverTypesPath: string;
|
|
57
|
-
resolverRelativeTargetDir: string;
|
|
58
|
-
resolverMainFile: string;
|
|
59
|
-
resolverMainFileMode: ResolverMainFileMode;
|
|
60
|
-
resolverGeneration: NormalizedResolverGeneration;
|
|
61
|
-
typeDefsFilePath: string | false;
|
|
62
|
-
typeDefsFileMode: TypeDefsFileMode;
|
|
63
|
-
mappersRelativeTargetDir: string;
|
|
64
|
-
mappersFileExtension: string;
|
|
65
|
-
mappersSuffix: string;
|
|
66
|
-
moduleNamingMode: ModuleNamingMode;
|
|
67
|
-
scalarsModule: string | false;
|
|
68
|
-
scalarsOverrides: Record<
|
|
69
|
-
string,
|
|
70
|
-
{ resolver?: string; type?: ScalarsOverridesType }
|
|
71
|
-
>;
|
|
72
|
-
mergeSchema:
|
|
73
|
-
| { path: string; config: schemaAstPlugin.SchemaASTConfig }
|
|
74
|
-
| false;
|
|
75
|
-
mode: ConfigMode;
|
|
76
|
-
whitelistedModules: string[];
|
|
77
|
-
blacklistedModules: string[];
|
|
78
|
-
externalResolvers: Record<string, string>;
|
|
79
|
-
typesPluginsConfig: ParsedTypesPluginsConfig;
|
|
80
|
-
tsMorphProjectOptions: ProjectOptions;
|
|
81
|
-
fixObjectTypeResolvers: NormalizedFixObjectTypeResolvers;
|
|
82
|
-
/** @deprecated Use importExtension instead */
|
|
83
|
-
emitLegacyCommonJSImports: boolean;
|
|
84
|
-
importExtension: ImportExtension;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface RawPresetConfig {
|
|
88
|
-
add?: Record<string, unknown>;
|
|
89
|
-
resolverTypesPath?: string;
|
|
90
|
-
resolverRelativeTargetDir?: string;
|
|
91
|
-
resolverMainFile?: string;
|
|
92
|
-
resolverMainFileMode?: string;
|
|
93
|
-
resolverGeneration?: string | Record<string, string | string[]>;
|
|
94
|
-
typeDefsFilePath?: string | boolean;
|
|
95
|
-
typeDefsFileMode?: string;
|
|
96
|
-
mappersRelativeTargetDir?: string;
|
|
97
|
-
mappersFileExtension?: string;
|
|
98
|
-
mappersSuffix?: string;
|
|
99
|
-
moduleNamingMode?: string | number;
|
|
100
|
-
scalarsModule?: string | boolean;
|
|
101
|
-
scalarsOverrides?: Record<
|
|
102
|
-
string,
|
|
103
|
-
{ resolver?: string; type?: ScalarsOverridesType }
|
|
104
|
-
>;
|
|
105
|
-
mergeSchema?: boolean | string | { path: string; config: unknown };
|
|
106
|
-
mode?: string;
|
|
107
|
-
whitelistedModules?: string[];
|
|
108
|
-
blacklistedModules?: string[];
|
|
109
|
-
externalResolvers?: Record<string, string>;
|
|
110
|
-
typesPluginsConfig?: typeScriptPlugin.TypeScriptPluginConfig &
|
|
111
|
-
typeScriptResolversPlugin.TypeScriptResolversPluginConfig;
|
|
112
|
-
tsConfigFilePath?: string;
|
|
113
|
-
fixObjectTypeResolvers?: string | Record<string, string>;
|
|
114
|
-
/** @deprecated Use importExtension instead */
|
|
115
|
-
emitLegacyCommonJSImports?: boolean;
|
|
116
|
-
importExtension?: ImportExtension;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export interface TypedPresetConfig extends RawPresetConfig {
|
|
120
|
-
add?: Record<string, AddPluginConfig>;
|
|
121
|
-
mode?: ConfigMode;
|
|
122
|
-
resolverMainFileMode?: ResolverMainFileMode;
|
|
123
|
-
typeDefsFileMode?: TypeDefsFileMode;
|
|
124
|
-
fixObjectTypeResolvers?:
|
|
125
|
-
| StringFixObjectTypeResolvers
|
|
126
|
-
| NormalizedFixObjectTypeResolvers;
|
|
127
|
-
typesPluginsConfig?: ParsedTypesPluginsConfig;
|
|
128
|
-
resolverGeneration?: StringResolverGeneration | NormalizedResolverGeneration;
|
|
129
|
-
mergeSchema?:
|
|
130
|
-
| boolean
|
|
131
|
-
| string
|
|
132
|
-
| { path: string; config: schemaAstPlugin.SchemaASTConfig };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export const validatePresetConfig = (
|
|
136
|
-
{
|
|
137
|
-
add,
|
|
138
|
-
resolverTypesPath = './types.generated.ts',
|
|
139
|
-
resolverRelativeTargetDir,
|
|
140
|
-
resolverMainFile = 'resolvers.generated.ts',
|
|
141
|
-
resolverMainFileMode = 'merged',
|
|
142
|
-
resolverGeneration = 'recommended',
|
|
143
|
-
typeDefsFilePath = defaultTypeDefsFilePath,
|
|
144
|
-
typeDefsFileMode: inputTypeDefsFileMode = 'merged',
|
|
145
|
-
mappersRelativeTargetDir = './',
|
|
146
|
-
mappersFileExtension = '.mappers.ts',
|
|
147
|
-
mappersSuffix = 'Mapper',
|
|
148
|
-
moduleNamingMode = 'last',
|
|
149
|
-
mergeSchema,
|
|
150
|
-
scalarsModule = 'graphql-scalars',
|
|
151
|
-
scalarsOverrides = {},
|
|
152
|
-
mode = 'modules',
|
|
153
|
-
whitelistedModules,
|
|
154
|
-
blacklistedModules,
|
|
155
|
-
externalResolvers = {},
|
|
156
|
-
typesPluginsConfig = {},
|
|
157
|
-
tsConfigFilePath = './tsconfig.json',
|
|
158
|
-
fixObjectTypeResolvers = 'fast',
|
|
159
|
-
emitLegacyCommonJSImports,
|
|
160
|
-
importExtension,
|
|
161
|
-
}: RawPresetConfig,
|
|
162
|
-
baseConfig?: {
|
|
163
|
-
emitLegacyCommonJSImports?: boolean;
|
|
164
|
-
importExtension?: ImportExtension;
|
|
165
|
-
}
|
|
166
|
-
): ParsedPresetConfig => {
|
|
167
|
-
const finalEmitLegacyCommonJSImports =
|
|
168
|
-
emitLegacyCommonJSImports ?? baseConfig?.emitLegacyCommonJSImports ?? true;
|
|
169
|
-
|
|
170
|
-
const baseImportExtension = baseConfig?.importExtension || undefined;
|
|
171
|
-
const finalImportExtension = importExtension ?? baseImportExtension;
|
|
172
|
-
|
|
173
|
-
if (mode !== 'merged' && mode !== 'modules') {
|
|
174
|
-
throw new Error(
|
|
175
|
-
fmt.error(
|
|
176
|
-
'presetConfig.mode must be "merged" or "modules" (default is "modules")',
|
|
177
|
-
'Validation'
|
|
178
|
-
)
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (
|
|
183
|
-
typeof fixObjectTypeResolvers !== 'object' &&
|
|
184
|
-
fixObjectTypeResolvers !== 'smart' &&
|
|
185
|
-
fixObjectTypeResolvers !== 'fast' &&
|
|
186
|
-
fixObjectTypeResolvers !== 'disabled'
|
|
187
|
-
) {
|
|
188
|
-
throw new Error(
|
|
189
|
-
fmt.error(
|
|
190
|
-
'presetConfig.fixObjectTypeResolvers must be an object, "smart", "fast" or "disabled" (default is "fast")',
|
|
191
|
-
'Validation'
|
|
192
|
-
)
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
typeof resolverGeneration !== 'object' &&
|
|
198
|
-
resolverGeneration !== 'disabled' &&
|
|
199
|
-
resolverGeneration !== 'recommended' &&
|
|
200
|
-
resolverGeneration !== 'minimal' &&
|
|
201
|
-
resolverGeneration !== 'all'
|
|
202
|
-
) {
|
|
203
|
-
throw new Error(
|
|
204
|
-
fmt.error(
|
|
205
|
-
'presetConfig.resolverGeneration must be an object, "disabled", "recommended", "minimal" or "all" (default is "recommended")',
|
|
206
|
-
'Validation'
|
|
207
|
-
)
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (resolverMainFileMode !== 'merged' && resolverMainFileMode !== 'modules') {
|
|
212
|
-
throw new Error(
|
|
213
|
-
fmt.error(
|
|
214
|
-
'presetConfig.resolverMainFileMode must be "merged" or "modules" (default is "merged")',
|
|
215
|
-
'Validation'
|
|
216
|
-
)
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
let typeDefsFileMode = inputTypeDefsFileMode;
|
|
221
|
-
if (mode === 'merged') {
|
|
222
|
-
// If mode is `merged`, `typeDefsFileMode` is also `merged` because there's no whitelisted or modules concepts
|
|
223
|
-
typeDefsFileMode = 'merged';
|
|
224
|
-
logger.warn(
|
|
225
|
-
`presetConfig.typeDefsFileMode has automatically been set to "merged" because presetConfig.mode is "merged"`
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
if (
|
|
229
|
-
typeDefsFileMode !== 'merged' &&
|
|
230
|
-
typeDefsFileMode !== 'modules' &&
|
|
231
|
-
typeDefsFileMode !== 'mergedWhitelisted'
|
|
232
|
-
) {
|
|
233
|
-
throw new Error(
|
|
234
|
-
fmt.error(
|
|
235
|
-
'presetConfig.typeDefsFileMode must be "merged", "mergedWhitelisted" or "modules" (default is "merged")',
|
|
236
|
-
'Validation'
|
|
237
|
-
)
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const finalModuleNamingMode = parseModuleNamingMode(moduleNamingMode);
|
|
242
|
-
|
|
243
|
-
if (!resolverTypesPath) {
|
|
244
|
-
throw new Error(
|
|
245
|
-
fmt.error('presetConfig.resolverTypesPath is required', 'Validation')
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const finalResolverRelativeTargetDir =
|
|
250
|
-
resolverRelativeTargetDir === undefined
|
|
251
|
-
? defaultResolverRelativeTargetDirMap[mode]
|
|
252
|
-
: resolverRelativeTargetDir;
|
|
253
|
-
|
|
254
|
-
if (path.extname(resolverMainFile) === '') {
|
|
255
|
-
throw new Error(
|
|
256
|
-
fmt.error('presetConfig.mainFile must be a valid file name', 'Validation')
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (whitelistedModules) {
|
|
261
|
-
if (!Array.isArray(whitelistedModules)) {
|
|
262
|
-
throw new Error(
|
|
263
|
-
fmt.error(
|
|
264
|
-
'presetConfig.whitelistedModules must be an array if provided',
|
|
265
|
-
'Validation'
|
|
266
|
-
)
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (mode !== 'modules') {
|
|
271
|
-
throw new Error(
|
|
272
|
-
fmt.error(
|
|
273
|
-
'presetConfig.whitelistedModules can only be used with presetConfig.mode == "modules"',
|
|
274
|
-
'Validation'
|
|
275
|
-
)
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (blacklistedModules) {
|
|
281
|
-
if (!Array.isArray(blacklistedModules)) {
|
|
282
|
-
throw new Error(
|
|
283
|
-
fmt.error(
|
|
284
|
-
'presetConfig.blacklistedModules must be an array if provided',
|
|
285
|
-
'Validation'
|
|
286
|
-
)
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (mode !== 'modules') {
|
|
291
|
-
throw new Error(
|
|
292
|
-
fmt.error(
|
|
293
|
-
'presetConfig.blacklistedModules can only be used with presetConfig.mode == "modules"',
|
|
294
|
-
'Validation'
|
|
295
|
-
)
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const validatedTypesPluginsConfig =
|
|
301
|
-
validateTypesPluginsConfig(typesPluginsConfig);
|
|
302
|
-
|
|
303
|
-
let finalTypeDefsFilePath = typeDefsFilePath;
|
|
304
|
-
if (finalTypeDefsFilePath === true) {
|
|
305
|
-
finalTypeDefsFilePath = defaultTypeDefsFilePath;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
let finalScalarsModule = scalarsModule;
|
|
309
|
-
if (finalScalarsModule === true) {
|
|
310
|
-
finalScalarsModule = defaultScalarsModule;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const tsMorphProjectOptions: ProjectOptions = {
|
|
314
|
-
skipAddingFilesFromTsConfig: true, // avoid long startup time by NOT loading files included by tsconfig.json. We only use this virtually anyways so we don't need all the files
|
|
315
|
-
};
|
|
316
|
-
if (tsConfigFilePath) {
|
|
317
|
-
const absoluteTsConfigFilePath = path.join(cwd(), tsConfigFilePath);
|
|
318
|
-
|
|
319
|
-
if (fs.existsSync(absoluteTsConfigFilePath)) {
|
|
320
|
-
tsMorphProjectOptions.tsConfigFilePath = absoluteTsConfigFilePath;
|
|
321
|
-
} else {
|
|
322
|
-
logger.warn(
|
|
323
|
-
`Unable to find TypeScript config at ${absoluteTsConfigFilePath}. Use presetConfig.tsConfigFilePath to set a custom value. Otherwise, type analysis may not work correctly.`
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const validatedAdd = validateAddOption(add);
|
|
329
|
-
|
|
330
|
-
const normalizedImportExtension = normalizeImportExtension(
|
|
331
|
-
finalImportExtension,
|
|
332
|
-
finalEmitLegacyCommonJSImports
|
|
333
|
-
);
|
|
334
|
-
|
|
335
|
-
return {
|
|
336
|
-
add: validatedAdd,
|
|
337
|
-
resolverTypesPath,
|
|
338
|
-
resolverRelativeTargetDir: finalResolverRelativeTargetDir,
|
|
339
|
-
resolverMainFile,
|
|
340
|
-
resolverMainFileMode,
|
|
341
|
-
resolverGeneration: parseResolverGeneration(resolverGeneration),
|
|
342
|
-
typeDefsFilePath: finalTypeDefsFilePath,
|
|
343
|
-
typeDefsFileMode,
|
|
344
|
-
mergeSchema: parseMergeSchema(mergeSchema),
|
|
345
|
-
mode,
|
|
346
|
-
mappersRelativeTargetDir,
|
|
347
|
-
mappersFileExtension,
|
|
348
|
-
mappersSuffix,
|
|
349
|
-
moduleNamingMode: finalModuleNamingMode,
|
|
350
|
-
scalarsModule: finalScalarsModule,
|
|
351
|
-
scalarsOverrides,
|
|
352
|
-
whitelistedModules: whitelistedModules || [],
|
|
353
|
-
blacklistedModules: blacklistedModules || [],
|
|
354
|
-
externalResolvers,
|
|
355
|
-
typesPluginsConfig: validatedTypesPluginsConfig,
|
|
356
|
-
tsMorphProjectOptions,
|
|
357
|
-
fixObjectTypeResolvers: parseFixObjectTypeResolvers(fixObjectTypeResolvers),
|
|
358
|
-
emitLegacyCommonJSImports: finalEmitLegacyCommonJSImports,
|
|
359
|
-
importExtension: normalizedImportExtension,
|
|
360
|
-
};
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
const validateTypesPluginsConfig = (
|
|
364
|
-
config: NonNullable<RawPresetConfig['typesPluginsConfig']>
|
|
365
|
-
): ParsedPresetConfig['typesPluginsConfig'] => {
|
|
366
|
-
if ('scalars' in config) {
|
|
367
|
-
throw new Error(
|
|
368
|
-
fmt.error(
|
|
369
|
-
'presetConfig.typesPluginsConfig.scalars is not supported. Use presetConfig.scalarsOverrides instead.',
|
|
370
|
-
'Validation'
|
|
371
|
-
)
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if ('emitLegacyCommonJSImports' in config) {
|
|
376
|
-
throw new Error(
|
|
377
|
-
fmt.error(
|
|
378
|
-
'presetConfig.typesPluginsConfig.emitLegacyCommonJSImports is not supported. Use presetConfig.emitLegacyCommonJSImports instead.',
|
|
379
|
-
'Validation'
|
|
380
|
-
)
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if ('importExtension' in config) {
|
|
385
|
-
throw new Error(
|
|
386
|
-
fmt.error(
|
|
387
|
-
'presetConfig.typesPluginsConfig.importExtension is not supported. Use presetConfig.importExtension instead.',
|
|
388
|
-
'Validation'
|
|
389
|
-
)
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const { scalars: _, emitLegacyCommonJSImports: __, ...rest } = config;
|
|
394
|
-
|
|
395
|
-
return rest;
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
const parseResolverGeneration = (
|
|
399
|
-
resolverGeneration:
|
|
400
|
-
| StringResolverGeneration
|
|
401
|
-
| Record<string, string | string[]>
|
|
402
|
-
): ParsedPresetConfig['resolverGeneration'] => {
|
|
403
|
-
if (resolverGeneration === 'all') {
|
|
404
|
-
return {
|
|
405
|
-
query: '*',
|
|
406
|
-
mutation: '*',
|
|
407
|
-
subscription: '*',
|
|
408
|
-
scalar: '*',
|
|
409
|
-
object: '*',
|
|
410
|
-
union: '*',
|
|
411
|
-
interface: '*',
|
|
412
|
-
enum: '*',
|
|
413
|
-
};
|
|
414
|
-
} else if (resolverGeneration === 'minimal') {
|
|
415
|
-
return {
|
|
416
|
-
query: '*',
|
|
417
|
-
mutation: '*',
|
|
418
|
-
subscription: '*',
|
|
419
|
-
scalar: '*',
|
|
420
|
-
object: '',
|
|
421
|
-
union: '',
|
|
422
|
-
interface: '',
|
|
423
|
-
enum: '',
|
|
424
|
-
};
|
|
425
|
-
} else if (resolverGeneration === 'recommended') {
|
|
426
|
-
return {
|
|
427
|
-
query: '*',
|
|
428
|
-
mutation: '*',
|
|
429
|
-
subscription: '*',
|
|
430
|
-
scalar: '*',
|
|
431
|
-
object: '*',
|
|
432
|
-
union: '',
|
|
433
|
-
interface: '',
|
|
434
|
-
enum: '',
|
|
435
|
-
};
|
|
436
|
-
} else if (resolverGeneration === 'disabled') {
|
|
437
|
-
return {
|
|
438
|
-
query: '',
|
|
439
|
-
mutation: '',
|
|
440
|
-
subscription: '',
|
|
441
|
-
scalar: '',
|
|
442
|
-
object: '',
|
|
443
|
-
union: '',
|
|
444
|
-
interface: '',
|
|
445
|
-
enum: '',
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
return {
|
|
450
|
-
query: resolverGeneration.query || '',
|
|
451
|
-
mutation: resolverGeneration.mutation || '',
|
|
452
|
-
subscription: resolverGeneration.subscription || '',
|
|
453
|
-
scalar: resolverGeneration.scalar || '',
|
|
454
|
-
object: resolverGeneration.object || '',
|
|
455
|
-
union: resolverGeneration.union || '',
|
|
456
|
-
interface: resolverGeneration.interface || '',
|
|
457
|
-
enum: resolverGeneration.enum || '',
|
|
458
|
-
};
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
const parseFixObjectTypeResolvers = (
|
|
462
|
-
fixObjectTypeResolvers: StringFixObjectTypeResolvers | Record<string, string>
|
|
463
|
-
): NormalizedFixObjectTypeResolvers => {
|
|
464
|
-
if (typeof fixObjectTypeResolvers === 'string') {
|
|
465
|
-
return {
|
|
466
|
-
object: fixObjectTypeResolvers,
|
|
467
|
-
enum: fixObjectTypeResolvers,
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
const allowedOptions: Record<string, 'smart' | 'fast' | 'disabled'> = {
|
|
472
|
-
smart: 'smart',
|
|
473
|
-
fast: 'fast',
|
|
474
|
-
disabled: 'disabled',
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
return {
|
|
478
|
-
object: allowedOptions[fixObjectTypeResolvers.object] || 'disabled',
|
|
479
|
-
enum: allowedOptions[fixObjectTypeResolvers.enum] || 'disabled',
|
|
480
|
-
};
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
const validateAddOption = (
|
|
484
|
-
add: RawPresetConfig['add']
|
|
485
|
-
): ParsedPresetConfig['add'] => {
|
|
486
|
-
if (!add) {
|
|
487
|
-
return undefined;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
Object.entries(add).forEach(([_, pluginConfig]) => {
|
|
491
|
-
if (typeof pluginConfig !== 'object' || pluginConfig === null) {
|
|
492
|
-
throw new Error(
|
|
493
|
-
fmt.error('presetConfig.add must be an object', 'Validation')
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
if (!('content' in pluginConfig)) {
|
|
498
|
-
throw new Error(
|
|
499
|
-
fmt.error(
|
|
500
|
-
'presetConfig.add must contain a "content" property',
|
|
501
|
-
'Validation'
|
|
502
|
-
)
|
|
503
|
-
);
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
// TODO: a bit hacky here but what's a good way to coerce this type? 🤔
|
|
508
|
-
return add as ParsedPresetConfig['add'];
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
const parseMergeSchema = (
|
|
512
|
-
mergeSchema: RawPresetConfig['mergeSchema']
|
|
513
|
-
): ParsedPresetConfig['mergeSchema'] => {
|
|
514
|
-
const defaultPath = 'schema.generated.graphqls';
|
|
515
|
-
|
|
516
|
-
if (mergeSchema === false) {
|
|
517
|
-
return false;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
if (mergeSchema === true || mergeSchema === undefined) {
|
|
521
|
-
return { path: defaultPath, config: {} };
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
if (typeof mergeSchema === 'string') {
|
|
525
|
-
return { path: mergeSchema, config: {} };
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return {
|
|
529
|
-
path: mergeSchema.path,
|
|
530
|
-
config: mergeSchema.config as schemaAstPlugin.SchemaASTConfig,
|
|
531
|
-
};
|
|
532
|
-
};
|
|
533
|
-
|
|
534
|
-
const parseModuleNamingMode = (
|
|
535
|
-
moduleNamingMode: RawPresetConfig['moduleNamingMode']
|
|
536
|
-
): ParsedPresetConfig['moduleNamingMode'] => {
|
|
537
|
-
if (moduleNamingMode == null) {
|
|
538
|
-
// By default, for backwards compatibility prior to `moduleNamingMode`, we
|
|
539
|
-
// select the last directory in a path.
|
|
540
|
-
return -1;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
if (moduleNamingMode === 'all') {
|
|
544
|
-
return 'all';
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
if (typeof moduleNamingMode === 'string') {
|
|
548
|
-
// As a convenience we support the keywords "first" and "last".
|
|
549
|
-
if (moduleNamingMode === 'first') {
|
|
550
|
-
return 0;
|
|
551
|
-
} else if (moduleNamingMode === 'last') {
|
|
552
|
-
return -1;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const parsedNumber = parseInt(moduleNamingMode);
|
|
556
|
-
if (!isNaN(parsedNumber)) {
|
|
557
|
-
return parsedNumber;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
if (typeof moduleNamingMode === 'number') {
|
|
562
|
-
return moduleNamingMode;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
throw new Error(
|
|
566
|
-
fmt.error(
|
|
567
|
-
'presetConfig.moduleNamingMode must be "first" or "last" or a number (default is "last")',
|
|
568
|
-
'Validation'
|
|
569
|
-
)
|
|
570
|
-
);
|
|
571
|
-
};
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "src",
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
|
7
|
-
"emitDeclarationOnly": false,
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"types": ["node"]
|
|
10
|
-
},
|
|
11
|
-
"exclude": ["vite.config.ts", "src/**/*.spec.ts"],
|
|
12
|
-
"include": ["src/**/*.ts"],
|
|
13
|
-
"references": [
|
|
14
|
-
{
|
|
15
|
-
"path": "../server-config/tsconfig.lib.json"
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
}
|
package/tsconfig.spec.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./out-tsc/vitest",
|
|
5
|
-
"types": [
|
|
6
|
-
"vitest/globals",
|
|
7
|
-
"vitest/importMeta",
|
|
8
|
-
"vite/client",
|
|
9
|
-
"node",
|
|
10
|
-
"vitest"
|
|
11
|
-
],
|
|
12
|
-
"rootDir": "."
|
|
13
|
-
},
|
|
14
|
-
"include": ["vite.config.ts", "src/**/*.spec.ts"],
|
|
15
|
-
"references": [
|
|
16
|
-
{
|
|
17
|
-
"path": "./tsconfig.lib.json"
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
3
|
-
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
|
|
4
|
-
|
|
5
|
-
export default defineConfig(() => ({
|
|
6
|
-
root: __dirname,
|
|
7
|
-
cacheDir: '../../node_modules/.vite/packages/typescript-resolver-files',
|
|
8
|
-
plugins: [nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])],
|
|
9
|
-
// Uncomment this if you are using workers.
|
|
10
|
-
// worker: {
|
|
11
|
-
// plugins: [ nxViteTsPaths() ],
|
|
12
|
-
// },
|
|
13
|
-
test: {
|
|
14
|
-
watch: false,
|
|
15
|
-
globals: true,
|
|
16
|
-
environment: 'node',
|
|
17
|
-
include: ['src/**/*.spec.ts'],
|
|
18
|
-
reporters: ['default'],
|
|
19
|
-
coverage: {
|
|
20
|
-
reportsDirectory: '../../coverage/packages/typescript-resolver-files',
|
|
21
|
-
provider: 'v8',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
}));
|