@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,706 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type RawPresetConfig,
|
|
3
|
-
type ParsedPresetConfig,
|
|
4
|
-
validatePresetConfig,
|
|
5
|
-
} from './validatePresetConfig.js';
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
vi.resetAllMocks();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const defaultExpected: ParsedPresetConfig = {
|
|
12
|
-
mode: 'modules',
|
|
13
|
-
resolverMainFile: 'resolvers.generated.ts',
|
|
14
|
-
resolverMainFileMode: 'merged',
|
|
15
|
-
resolverRelativeTargetDir: 'resolvers',
|
|
16
|
-
resolverTypesPath: './types.generated.ts',
|
|
17
|
-
resolverGeneration: {
|
|
18
|
-
query: '*',
|
|
19
|
-
mutation: '*',
|
|
20
|
-
subscription: '*',
|
|
21
|
-
scalar: '*',
|
|
22
|
-
object: '*',
|
|
23
|
-
union: '',
|
|
24
|
-
interface: '',
|
|
25
|
-
enum: '',
|
|
26
|
-
},
|
|
27
|
-
mergeSchema: {
|
|
28
|
-
path: 'schema.generated.graphqls',
|
|
29
|
-
config: {},
|
|
30
|
-
},
|
|
31
|
-
typeDefsFilePath: './typeDefs.generated.ts',
|
|
32
|
-
typeDefsFileMode: 'merged',
|
|
33
|
-
mappersRelativeTargetDir: './',
|
|
34
|
-
mappersFileExtension: '.mappers.ts',
|
|
35
|
-
mappersSuffix: 'Mapper',
|
|
36
|
-
moduleNamingMode: -1,
|
|
37
|
-
scalarsModule: 'graphql-scalars',
|
|
38
|
-
scalarsOverrides: {},
|
|
39
|
-
externalResolvers: {},
|
|
40
|
-
typesPluginsConfig: {},
|
|
41
|
-
whitelistedModules: [],
|
|
42
|
-
blacklistedModules: [],
|
|
43
|
-
tsMorphProjectOptions: {
|
|
44
|
-
skipAddingFilesFromTsConfig: true,
|
|
45
|
-
tsConfigFilePath: expect.any(String), // this'd be a local path, so no need to test
|
|
46
|
-
},
|
|
47
|
-
fixObjectTypeResolvers: {
|
|
48
|
-
object: 'fast',
|
|
49
|
-
enum: 'fast',
|
|
50
|
-
},
|
|
51
|
-
emitLegacyCommonJSImports: true,
|
|
52
|
-
importExtension: '',
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
describe('validatePresetConfig - general', () => {
|
|
56
|
-
it('returns correct default config', () => {
|
|
57
|
-
const parsed = validatePresetConfig({});
|
|
58
|
-
|
|
59
|
-
expect(parsed).toEqual(defaultExpected);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('throws if wrong mode is provided', () => {
|
|
63
|
-
expect(() => validatePresetConfig({ mode: 'this_will_never_be' })).toThrow(
|
|
64
|
-
'Validation - presetConfig.mode must be "merged" or "modules" (default is "modules")'
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("returns result.typeDefsFileMode = 'modules' if config.typeDefsFileMode == modules", () => {
|
|
69
|
-
const parsed = validatePresetConfig({ typeDefsFileMode: 'modules' });
|
|
70
|
-
|
|
71
|
-
expect(parsed).toEqual({
|
|
72
|
-
...defaultExpected,
|
|
73
|
-
typeDefsFileMode: 'modules',
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("returns result.resolverMainFileMode = 'merged' if config.resolverMainFileMode == merged", () => {
|
|
78
|
-
const parsed = validatePresetConfig({ resolverMainFileMode: 'merged' });
|
|
79
|
-
|
|
80
|
-
expect(parsed).toEqual({
|
|
81
|
-
...defaultExpected,
|
|
82
|
-
resolverMainFileMode: 'merged',
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("returns result.resolverMainFileMode = 'modules' if config.resolverMainFileMode == modules", () => {
|
|
87
|
-
const parsed = validatePresetConfig({ resolverMainFileMode: 'modules' });
|
|
88
|
-
|
|
89
|
-
expect(parsed).toEqual({
|
|
90
|
-
...defaultExpected,
|
|
91
|
-
resolverMainFileMode: 'modules',
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('throws if result.resolverMainFileMode is not expected', () => {
|
|
96
|
-
expect(() =>
|
|
97
|
-
validatePresetConfig({ resolverMainFileMode: 'not_valid_value' })
|
|
98
|
-
).toThrow(
|
|
99
|
-
'Validation - presetConfig.resolverMainFileMode must be "merged" or "modules" (default is "merged")'
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("returns result.typeDefsFileMode = 'mergedWhitelisted' if config.typeDefsFileMode == mergedWhitelisted", () => {
|
|
104
|
-
const parsed = validatePresetConfig({
|
|
105
|
-
typeDefsFileMode: 'mergedWhitelisted',
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
expect(parsed).toEqual({
|
|
109
|
-
...defaultExpected,
|
|
110
|
-
typeDefsFileMode: 'mergedWhitelisted',
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('throws if result.typeDefsFileMode is not expected', () => {
|
|
115
|
-
expect(() => validatePresetConfig({ typeDefsFileMode: '' })).toThrow(
|
|
116
|
-
'presetConfig.typeDefsFileMode must be "merged", "mergedWhitelisted" or "modules" (default is "merged")'
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("returns result.typeDefsFilePath = './typeDefs.generated.ts' if config.typeDefsFilePath == true", () => {
|
|
121
|
-
const parsed = validatePresetConfig({ typeDefsFilePath: true });
|
|
122
|
-
|
|
123
|
-
expect(parsed).toEqual({
|
|
124
|
-
...defaultExpected,
|
|
125
|
-
typeDefsFilePath: './typeDefs.generated.ts',
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
it('returns result.typeDefsFilePath = false if config.typeDefsFilePath == false', () => {
|
|
129
|
-
const parsed = validatePresetConfig({ typeDefsFilePath: false });
|
|
130
|
-
|
|
131
|
-
expect(parsed).toEqual({
|
|
132
|
-
...defaultExpected,
|
|
133
|
-
typeDefsFilePath: false,
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
it("returns result.typeDefsFilePath = '' if config.typeDefsFilePath == '' ", () => {
|
|
137
|
-
const parsed = validatePresetConfig({ typeDefsFilePath: '' });
|
|
138
|
-
|
|
139
|
-
expect(parsed).toEqual({
|
|
140
|
-
...defaultExpected,
|
|
141
|
-
typeDefsFilePath: '',
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('returns custom result.resolverTypesPath = config.resolverTypesPath if config.resolverTypesPath is not falsy', () => {
|
|
146
|
-
const parsed = validatePresetConfig({
|
|
147
|
-
resolverTypesPath: './types.gen.ts',
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
expect(parsed).toEqual({
|
|
151
|
-
...defaultExpected,
|
|
152
|
-
resolverTypesPath: './types.gen.ts',
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
it('throws if if config.resolverTypesPath is falsy', () => {
|
|
156
|
-
expect(() => validatePresetConfig({ resolverTypesPath: '' })).toThrow(
|
|
157
|
-
'Validation - presetConfig.resolverTypesPath is required'
|
|
158
|
-
);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('returns custom result.resolverRelativeTargetDir = config.resolverRelativeTargetDir', () => {
|
|
162
|
-
const parsed = validatePresetConfig({ resolverRelativeTargetDir: '' });
|
|
163
|
-
|
|
164
|
-
expect(parsed).toEqual({
|
|
165
|
-
...defaultExpected,
|
|
166
|
-
resolverRelativeTargetDir: '',
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('returns custom result.resolverMainFile = config.resolverMainFile', () => {
|
|
171
|
-
const parsed = validatePresetConfig({
|
|
172
|
-
resolverMainFile: 'resolvers.gen.ts',
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
expect(parsed).toEqual({
|
|
176
|
-
...defaultExpected,
|
|
177
|
-
resolverMainFile: 'resolvers.gen.ts',
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
it('throws if config.resolverMainFile is not a valid filename', () => {
|
|
181
|
-
expect(() => validatePresetConfig({ resolverMainFile: 'aaa' })).toThrow(
|
|
182
|
-
'presetConfig.mainFile must be a valid file name'
|
|
183
|
-
);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('returns custom result.mappersFileExtension = config.mappersFileExtension', () => {
|
|
187
|
-
const parsed = validatePresetConfig({ mappersFileExtension: '.map.ts' });
|
|
188
|
-
|
|
189
|
-
expect(parsed).toEqual({
|
|
190
|
-
...defaultExpected,
|
|
191
|
-
mappersFileExtension: '.map.ts',
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('returns custom result.mappersSuffix = config.mappersSuffix', () => {
|
|
196
|
-
const parsed = validatePresetConfig({ mappersSuffix: '_Map' });
|
|
197
|
-
|
|
198
|
-
expect(parsed).toEqual({
|
|
199
|
-
...defaultExpected,
|
|
200
|
-
mappersSuffix: '_Map',
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('returns result.fixObjectTypeResolvers object with every key set as "smart" if input is set as "smart"', () => {
|
|
205
|
-
const parsed = validatePresetConfig({ fixObjectTypeResolvers: 'smart' });
|
|
206
|
-
|
|
207
|
-
expect(parsed).toEqual({
|
|
208
|
-
...defaultExpected,
|
|
209
|
-
fixObjectTypeResolvers: {
|
|
210
|
-
object: 'smart',
|
|
211
|
-
enum: 'smart',
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('returns result.fixObjectTypeResolvers object with every key set as "disabled" if input is set as "disabled"', () => {
|
|
217
|
-
const parsed = validatePresetConfig({ fixObjectTypeResolvers: 'disabled' });
|
|
218
|
-
|
|
219
|
-
expect(parsed).toEqual({
|
|
220
|
-
...defaultExpected,
|
|
221
|
-
fixObjectTypeResolvers: {
|
|
222
|
-
object: 'disabled',
|
|
223
|
-
enum: 'disabled',
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('returns result.fixObjectTypeResolvers object when input is an object', () => {
|
|
229
|
-
const parsed = validatePresetConfig({
|
|
230
|
-
fixObjectTypeResolvers: {
|
|
231
|
-
object: 'smart',
|
|
232
|
-
enum: 'disabled',
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
expect(parsed).toEqual({
|
|
237
|
-
...defaultExpected,
|
|
238
|
-
fixObjectTypeResolvers: {
|
|
239
|
-
object: 'smart',
|
|
240
|
-
enum: 'disabled',
|
|
241
|
-
},
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it('returns result.fixObjectTypeResolvers fields as "disabled" if the input object fields are not "smart" or "disabled"', () => {
|
|
246
|
-
const parsed = validatePresetConfig({
|
|
247
|
-
fixObjectTypeResolvers: {
|
|
248
|
-
object: 'never_an_option',
|
|
249
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
250
|
-
enum: undefined as any,
|
|
251
|
-
},
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
expect(parsed).toEqual({
|
|
255
|
-
...defaultExpected,
|
|
256
|
-
fixObjectTypeResolvers: {
|
|
257
|
-
object: 'disabled',
|
|
258
|
-
enum: 'disabled',
|
|
259
|
-
},
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it('returns result.emitLegacyCommonJSImports = false if set to false', () => {
|
|
264
|
-
const parsed = validatePresetConfig({ emitLegacyCommonJSImports: false });
|
|
265
|
-
|
|
266
|
-
expect(parsed).toEqual({
|
|
267
|
-
...defaultExpected,
|
|
268
|
-
emitLegacyCommonJSImports: false,
|
|
269
|
-
importExtension: '.js',
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it('throws if config.typesPluginsConfig.emitLegacyCommonJSImports is used', () => {
|
|
274
|
-
expect(() =>
|
|
275
|
-
validatePresetConfig({
|
|
276
|
-
typesPluginsConfig: {
|
|
277
|
-
emitLegacyCommonJSImports: false,
|
|
278
|
-
},
|
|
279
|
-
})
|
|
280
|
-
).toThrow(
|
|
281
|
-
'Validation - presetConfig.typesPluginsConfig.emitLegacyCommonJSImports is not supported. Use presetConfig.emitLegacyCommonJSImports instead.'
|
|
282
|
-
);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it('throws if result.fixObjectTypeResolvers is not valid', () => {
|
|
286
|
-
expect(() =>
|
|
287
|
-
validatePresetConfig({ fixObjectTypeResolvers: 'not-valid-for-sure' })
|
|
288
|
-
).toThrow(
|
|
289
|
-
'Validation - presetConfig.fixObjectTypeResolvers must be an object, "smart", "fast" or "disabled" (default is "fast")'
|
|
290
|
-
);
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('throws if config.typesPluginsConfig.scalars is used', () => {
|
|
294
|
-
expect(() =>
|
|
295
|
-
validatePresetConfig({ typesPluginsConfig: { scalars: 'asdas' } })
|
|
296
|
-
).toThrow(
|
|
297
|
-
'presetConfig.typesPluginsConfig.scalars is not supported. Use presetConfig.scalarsOverrides instead.'
|
|
298
|
-
);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it('returns result.scalarsModule = false if config.scalarsModule == false', () => {
|
|
302
|
-
const parsed = validatePresetConfig({ scalarsModule: false });
|
|
303
|
-
|
|
304
|
-
expect(parsed).toEqual({
|
|
305
|
-
...defaultExpected,
|
|
306
|
-
scalarsModule: false,
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
it('returns custom result.scalarsModule = false if config.scalarsModule == false', () => {
|
|
310
|
-
const parsed = validatePresetConfig({
|
|
311
|
-
scalarsModule: '@someother/graphql-scalars',
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
expect(parsed).toEqual({
|
|
315
|
-
...defaultExpected,
|
|
316
|
-
scalarsModule: '@someother/graphql-scalars',
|
|
317
|
-
});
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
it('returns correct result if config.externalResolvers and config.scalarsOverrides are used together', () => {
|
|
321
|
-
const parsed = validatePresetConfig({
|
|
322
|
-
externalResolvers: {
|
|
323
|
-
DateTime: 'module#DateTimeResolver',
|
|
324
|
-
},
|
|
325
|
-
scalarsOverrides: {
|
|
326
|
-
Currency: {
|
|
327
|
-
resolver: 'module#CurrencyResolver',
|
|
328
|
-
type: 'unknown',
|
|
329
|
-
},
|
|
330
|
-
},
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
expect(parsed).toEqual({
|
|
334
|
-
...defaultExpected,
|
|
335
|
-
externalResolvers: {
|
|
336
|
-
DateTime: 'module#DateTimeResolver',
|
|
337
|
-
},
|
|
338
|
-
scalarsOverrides: {
|
|
339
|
-
Currency: {
|
|
340
|
-
resolver: 'module#CurrencyResolver',
|
|
341
|
-
type: 'unknown',
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
describe('validatePresetConfig - mode: modules', () => {
|
|
349
|
-
it('returns custom result.whitelistedModules = config.whitelistedModules', () => {
|
|
350
|
-
const parsed = validatePresetConfig({ whitelistedModules: ['moduleA'] });
|
|
351
|
-
|
|
352
|
-
expect(parsed).toEqual({
|
|
353
|
-
...defaultExpected,
|
|
354
|
-
whitelistedModules: ['moduleA'],
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
it('returns result.whitelistedModules = [] if config.whitelistedModules is falsy', () => {
|
|
358
|
-
const parsed = validatePresetConfig({ whitelistedModules: undefined });
|
|
359
|
-
|
|
360
|
-
expect(parsed).toEqual({
|
|
361
|
-
...defaultExpected,
|
|
362
|
-
whitelistedModules: [],
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
it('throws if config.whitelistedModules is truthy but not an array', () => {
|
|
366
|
-
expect(() =>
|
|
367
|
-
validatePresetConfig({ whitelistedModules: true } as never)
|
|
368
|
-
).toThrow(
|
|
369
|
-
'Validation - presetConfig.whitelistedModules must be an array if provided'
|
|
370
|
-
);
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it('returns custom result.blacklistedModules = config.blacklistedModules', () => {
|
|
374
|
-
const parsed = validatePresetConfig({ blacklistedModules: ['moduleA'] });
|
|
375
|
-
|
|
376
|
-
expect(parsed).toEqual({
|
|
377
|
-
...defaultExpected,
|
|
378
|
-
blacklistedModules: ['moduleA'],
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
it('returns result.blacklistedModules = [] if config.blacklistedModules is falsy', () => {
|
|
382
|
-
const parsed = validatePresetConfig({ blacklistedModules: undefined });
|
|
383
|
-
|
|
384
|
-
expect(parsed).toEqual({
|
|
385
|
-
...defaultExpected,
|
|
386
|
-
blacklistedModules: [],
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
it('throws if config.blacklistedModules is truthy but not an array', () => {
|
|
390
|
-
expect(() =>
|
|
391
|
-
validatePresetConfig({ blacklistedModules: true } as never)
|
|
392
|
-
).toThrow(
|
|
393
|
-
'Validation - presetConfig.blacklistedModules must be an array if provided'
|
|
394
|
-
);
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
describe('validatePresetConfig - mode: merged', () => {
|
|
399
|
-
it('returns correct default config for merged mode', () => {
|
|
400
|
-
const parsed = validatePresetConfig({ mode: 'merged' });
|
|
401
|
-
expect(parsed).toEqual({
|
|
402
|
-
...defaultExpected,
|
|
403
|
-
mode: 'merged',
|
|
404
|
-
resolverRelativeTargetDir: '',
|
|
405
|
-
});
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
it('throws if config.whitelistedModules is provided', () => {
|
|
409
|
-
expect(() =>
|
|
410
|
-
validatePresetConfig({
|
|
411
|
-
mode: 'merged',
|
|
412
|
-
whitelistedModules: ['moduleA'],
|
|
413
|
-
})
|
|
414
|
-
).toThrow(
|
|
415
|
-
'Validation - presetConfig.whitelistedModules can only be used with presetConfig.mode == "modules"'
|
|
416
|
-
);
|
|
417
|
-
});
|
|
418
|
-
it('throws if config.blacklistedModules is provided', () => {
|
|
419
|
-
expect(() =>
|
|
420
|
-
validatePresetConfig({
|
|
421
|
-
mode: 'merged',
|
|
422
|
-
blacklistedModules: ['moduleA'],
|
|
423
|
-
})
|
|
424
|
-
).toThrow(
|
|
425
|
-
'Validation - presetConfig.blacklistedModules can only be used with presetConfig.mode == "modules"'
|
|
426
|
-
);
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
describe('validatePresetConfig - importExtension', () => {
|
|
431
|
-
it('returns importExtension: ".js" when explicitly set', () => {
|
|
432
|
-
const parsed = validatePresetConfig({ importExtension: '.js' });
|
|
433
|
-
|
|
434
|
-
expect(parsed).toEqual({
|
|
435
|
-
...defaultExpected,
|
|
436
|
-
importExtension: '.js',
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
it('returns importExtension: "" when explicitly set to empty string', () => {
|
|
441
|
-
const parsed = validatePresetConfig({ importExtension: '' });
|
|
442
|
-
|
|
443
|
-
expect(parsed).toEqual({
|
|
444
|
-
...defaultExpected,
|
|
445
|
-
importExtension: '',
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
it('returns custom importExtension when provided', () => {
|
|
450
|
-
const parsed = validatePresetConfig({ importExtension: '.mjs' });
|
|
451
|
-
|
|
452
|
-
expect(parsed).toEqual({
|
|
453
|
-
...defaultExpected,
|
|
454
|
-
importExtension: '.mjs',
|
|
455
|
-
});
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
it('importExtension takes precedence over emitLegacyCommonJSImports when both are set', () => {
|
|
459
|
-
const parsed = validatePresetConfig({
|
|
460
|
-
importExtension: '.mjs',
|
|
461
|
-
emitLegacyCommonJSImports: false,
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
expect(parsed).toEqual({
|
|
465
|
-
...defaultExpected,
|
|
466
|
-
importExtension: '.mjs',
|
|
467
|
-
emitLegacyCommonJSImports: false,
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
it('returns importExtension: "" when emitLegacyCommonJSImports is true (backward compatibility)', () => {
|
|
472
|
-
const parsed = validatePresetConfig({ emitLegacyCommonJSImports: true });
|
|
473
|
-
|
|
474
|
-
expect(parsed).toEqual({
|
|
475
|
-
...defaultExpected,
|
|
476
|
-
emitLegacyCommonJSImports: true,
|
|
477
|
-
importExtension: '',
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
describe('base config inheritance', () => {
|
|
482
|
-
it('inherits importExtension from base config when not specified in preset', () => {
|
|
483
|
-
const parsed = validatePresetConfig({}, { importExtension: '.ts' });
|
|
484
|
-
|
|
485
|
-
expect(parsed).toEqual({
|
|
486
|
-
...defaultExpected,
|
|
487
|
-
importExtension: '.ts',
|
|
488
|
-
emitLegacyCommonJSImports: true,
|
|
489
|
-
});
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
it('preset importExtension overrides base config', () => {
|
|
493
|
-
const parsed = validatePresetConfig(
|
|
494
|
-
{ importExtension: '.mjs' },
|
|
495
|
-
{ importExtension: '.ts' }
|
|
496
|
-
);
|
|
497
|
-
|
|
498
|
-
expect(parsed).toEqual({
|
|
499
|
-
...defaultExpected,
|
|
500
|
-
importExtension: '.mjs',
|
|
501
|
-
});
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
it('inherits emitLegacyCommonJSImports from base config', () => {
|
|
505
|
-
const parsed = validatePresetConfig(
|
|
506
|
-
{},
|
|
507
|
-
{ emitLegacyCommonJSImports: false }
|
|
508
|
-
);
|
|
509
|
-
|
|
510
|
-
expect(parsed).toEqual({
|
|
511
|
-
...defaultExpected,
|
|
512
|
-
emitLegacyCommonJSImports: false,
|
|
513
|
-
importExtension: '.js',
|
|
514
|
-
});
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
it('preset emitLegacyCommonJSImports overrides base config', () => {
|
|
518
|
-
const parsed = validatePresetConfig(
|
|
519
|
-
{ emitLegacyCommonJSImports: true },
|
|
520
|
-
{ emitLegacyCommonJSImports: false }
|
|
521
|
-
);
|
|
522
|
-
|
|
523
|
-
expect(parsed).toEqual({
|
|
524
|
-
...defaultExpected,
|
|
525
|
-
emitLegacyCommonJSImports: true,
|
|
526
|
-
importExtension: '',
|
|
527
|
-
});
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
it('uses defaults when base config is not provided', () => {
|
|
531
|
-
const parsed = validatePresetConfig({});
|
|
532
|
-
|
|
533
|
-
expect(parsed).toEqual(defaultExpected);
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
it('uses defaults when base config is undefined', () => {
|
|
537
|
-
const parsed = validatePresetConfig({}, undefined);
|
|
538
|
-
|
|
539
|
-
expect(parsed).toEqual(defaultExpected);
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
it('preset importExtension takes precedence over base emitLegacyCommonJSImports', () => {
|
|
543
|
-
const parsed = validatePresetConfig(
|
|
544
|
-
{ importExtension: '.ts' },
|
|
545
|
-
{ emitLegacyCommonJSImports: false }
|
|
546
|
-
);
|
|
547
|
-
|
|
548
|
-
expect(parsed).toEqual({
|
|
549
|
-
...defaultExpected,
|
|
550
|
-
emitLegacyCommonJSImports: false,
|
|
551
|
-
importExtension: '.ts',
|
|
552
|
-
});
|
|
553
|
-
});
|
|
554
|
-
|
|
555
|
-
it('base importExtension takes precedence over base emitLegacyCommonJSImports', () => {
|
|
556
|
-
const parsed = validatePresetConfig(
|
|
557
|
-
{},
|
|
558
|
-
{ importExtension: '.mts', emitLegacyCommonJSImports: false }
|
|
559
|
-
);
|
|
560
|
-
|
|
561
|
-
expect(parsed).toEqual({
|
|
562
|
-
...defaultExpected,
|
|
563
|
-
emitLegacyCommonJSImports: false,
|
|
564
|
-
importExtension: '.mts',
|
|
565
|
-
});
|
|
566
|
-
});
|
|
567
|
-
});
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
describe('validatePresetConfig - resolverGeneration', () => {
|
|
571
|
-
it.each<{
|
|
572
|
-
input: 'disabled' | 'recommended' | 'all' | 'minimal';
|
|
573
|
-
expected: ParsedPresetConfig['resolverGeneration'];
|
|
574
|
-
}>([
|
|
575
|
-
{
|
|
576
|
-
input: 'disabled',
|
|
577
|
-
expected: {
|
|
578
|
-
query: '',
|
|
579
|
-
mutation: '',
|
|
580
|
-
subscription: '',
|
|
581
|
-
scalar: '',
|
|
582
|
-
object: '',
|
|
583
|
-
union: '',
|
|
584
|
-
interface: '',
|
|
585
|
-
enum: '',
|
|
586
|
-
},
|
|
587
|
-
},
|
|
588
|
-
{
|
|
589
|
-
input: 'minimal',
|
|
590
|
-
expected: {
|
|
591
|
-
query: '*',
|
|
592
|
-
mutation: '*',
|
|
593
|
-
subscription: '*',
|
|
594
|
-
scalar: '*',
|
|
595
|
-
object: '',
|
|
596
|
-
union: '',
|
|
597
|
-
interface: '',
|
|
598
|
-
enum: '',
|
|
599
|
-
},
|
|
600
|
-
},
|
|
601
|
-
{
|
|
602
|
-
input: 'recommended',
|
|
603
|
-
expected: {
|
|
604
|
-
query: '*',
|
|
605
|
-
mutation: '*',
|
|
606
|
-
subscription: '*',
|
|
607
|
-
scalar: '*',
|
|
608
|
-
object: '*',
|
|
609
|
-
union: '',
|
|
610
|
-
interface: '',
|
|
611
|
-
enum: '',
|
|
612
|
-
},
|
|
613
|
-
},
|
|
614
|
-
{
|
|
615
|
-
input: 'all',
|
|
616
|
-
expected: {
|
|
617
|
-
query: '*',
|
|
618
|
-
mutation: '*',
|
|
619
|
-
subscription: '*',
|
|
620
|
-
scalar: '*',
|
|
621
|
-
object: '*',
|
|
622
|
-
union: '*',
|
|
623
|
-
interface: '*',
|
|
624
|
-
enum: '*',
|
|
625
|
-
},
|
|
626
|
-
},
|
|
627
|
-
])(
|
|
628
|
-
'correctly returns the parsed "$input" resolverGeneration object',
|
|
629
|
-
({ input, expected }) => {
|
|
630
|
-
const result = validatePresetConfig({ resolverGeneration: input });
|
|
631
|
-
|
|
632
|
-
expect(result.resolverGeneration).toEqual(expected);
|
|
633
|
-
}
|
|
634
|
-
);
|
|
635
|
-
|
|
636
|
-
it('correctly returns provided resolverGeneration object', () => {
|
|
637
|
-
const result = validatePresetConfig({
|
|
638
|
-
resolverGeneration: {
|
|
639
|
-
query: '*.Query.*',
|
|
640
|
-
mutation: '!*.Mutation.*',
|
|
641
|
-
},
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
expect(result.resolverGeneration).toEqual({
|
|
645
|
-
query: '*.Query.*',
|
|
646
|
-
mutation: '!*.Mutation.*',
|
|
647
|
-
subscription: '',
|
|
648
|
-
scalar: '',
|
|
649
|
-
object: '',
|
|
650
|
-
union: '',
|
|
651
|
-
interface: '',
|
|
652
|
-
enum: '',
|
|
653
|
-
});
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
it('throws if invalid resolverGeneration is provided', () => {
|
|
657
|
-
expect(() =>
|
|
658
|
-
validatePresetConfig({ resolverGeneration: 'omg_what_is_this' })
|
|
659
|
-
).toThrow(
|
|
660
|
-
'Validation - presetConfig.resolverGeneration must be an object, "disabled", "recommended", "minimal" or "all" (default is "recommended")'
|
|
661
|
-
);
|
|
662
|
-
});
|
|
663
|
-
|
|
664
|
-
describe('validatePresetConfig - mergeSchema', () => {
|
|
665
|
-
it.each<{
|
|
666
|
-
input: RawPresetConfig['mergeSchema'];
|
|
667
|
-
expected: ParsedPresetConfig['mergeSchema'];
|
|
668
|
-
}>([
|
|
669
|
-
{
|
|
670
|
-
input: false,
|
|
671
|
-
expected: false,
|
|
672
|
-
},
|
|
673
|
-
{
|
|
674
|
-
input: true,
|
|
675
|
-
expected: {
|
|
676
|
-
path: 'schema.generated.graphqls',
|
|
677
|
-
config: {},
|
|
678
|
-
},
|
|
679
|
-
},
|
|
680
|
-
{
|
|
681
|
-
input: 'schema.gen.gql',
|
|
682
|
-
expected: {
|
|
683
|
-
path: 'schema.gen.gql',
|
|
684
|
-
config: {},
|
|
685
|
-
},
|
|
686
|
-
},
|
|
687
|
-
{
|
|
688
|
-
input: {
|
|
689
|
-
path: 'omg.graphql',
|
|
690
|
-
config: { sort: true },
|
|
691
|
-
},
|
|
692
|
-
expected: {
|
|
693
|
-
path: 'omg.graphql',
|
|
694
|
-
config: { sort: true },
|
|
695
|
-
},
|
|
696
|
-
},
|
|
697
|
-
])(
|
|
698
|
-
'correctly returns the parsed "$input" resolverGeneration object',
|
|
699
|
-
({ input, expected }) => {
|
|
700
|
-
const result = validatePresetConfig({ mergeSchema: input });
|
|
701
|
-
|
|
702
|
-
expect(result.mergeSchema).toEqual(expected);
|
|
703
|
-
}
|
|
704
|
-
);
|
|
705
|
-
});
|
|
706
|
-
});
|