-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathconfig.spec.ts
More file actions
122 lines (106 loc) · 3.04 KB
/
config.spec.ts
File metadata and controls
122 lines (106 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { buildSchema } from 'graphql';
import { createContext, ensureContext, CodegenContext } from '../src/index.js';
describe('Codegen config - Context', () => {
it('loads and merge multiple schemas when using GraphQL config', async () => {
const context = await createContext({
config: './tests/test-files/graphql.config.js',
project: 'prj1',
errorsOnly: true,
overwrite: true,
profile: true,
require: [],
silent: false,
watch: false,
});
const schema1 = /* GraphQL */ `
type Query
scalar Date
`;
const schema2 = /* GraphQL */ `
extend type Query {
me: User
}
type User {
id: ID!
name: String!
createdAt: Date!
}
`;
const schema3 = /* GraphQL */ `
extend type Query {
media: Media
}
interface Media {
id: ID!
}
type Image implements Media {
id: ID!
url: String!
}
type Book implements Media {
id: ID!
title: String!
}
`;
const mergedSchema = await context.loadSchema([schema1, schema2, schema3]);
const typeMap = mergedSchema.getTypeMap();
expect(typeMap['Query']).toBeDefined();
expect(typeMap['Date']).toBeDefined();
expect(typeMap['User']).toBeDefined();
expect(typeMap['Media']).toBeDefined();
expect(typeMap['Image']).toBeDefined();
expect(typeMap['Book']).toBeDefined();
});
it('loads and merge multiple schemas when using input config', async () => {
const context = ensureContext({
generates: {},
});
const schema1 = /* GraphQL */ `
type Mutation
scalar DateTime
`;
const schema2 = /* GraphQL */ `
extend type Mutation {
createUser: User
}
type User {
id: ID!
createdAt: DateTime!
}
`;
const mergedSchema = await context.loadSchema([schema1, schema2]);
const typeMap = mergedSchema.getTypeMap();
expect(typeMap['Mutation']).toBeDefined();
expect(typeMap['DateTime']).toBeDefined();
expect(typeMap['User']).toBeDefined();
});
it('passes nested config values to graphql-config schema loader', async () => {
const loadSchemaSpy = vi.fn().mockResolvedValue(buildSchema('type Query { _: Boolean }'));
const project = {
extension: vi.fn().mockReturnValue({
generates: {},
config: {
inputValueDeprecation: true,
},
}),
schema: ['http://example.com/graphql'],
documents: [],
loadSchema: loadSchemaSpy,
loadDocuments: vi.fn(),
};
const graphqlConfig = {
filepath: '/tmp/graphql.config.ts',
dirpath: '/tmp',
getProject: vi.fn().mockReturnValue(project),
} as any;
const context = new CodegenContext({ graphqlConfig });
await context.loadSchema(['http://example.com/graphql']);
expect(loadSchemaSpy).toHaveBeenCalledWith(
['http://example.com/graphql'],
'GraphQLSchema',
expect.objectContaining({
inputValueDeprecation: true,
})
);
});
});