-
Notifications
You must be signed in to change notification settings - Fork 242
/
duplicateEnumOrScalar.test.ts
97 lines (84 loc) 路 2.46 KB
/
duplicateEnumOrScalar.test.ts
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
import gql from 'graphql-tag';
import { duplicateEnumOrScalar as validateDuplicateEnumOrScalar } from '../';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';
expect.addSnapshotSerializer(graphqlErrorSerializer);
describe('duplicateEnumOrScalar', () => {
it('does not error with proper enum and scalar usage', () => {
const serviceA = {
typeDefs: gql`
type Product @key(fields: "color { id value }") {
sku: String!
upc: String!
shippingDate: Date
type: ProductType
}
enum ProductType {
BOOK
FURNITURE
}
extend enum ProductType {
DIGITAL
}
scalar Date
`,
name: 'serviceA',
};
const warnings = validateDuplicateEnumOrScalar(serviceA);
expect(warnings).toEqual([]);
});
it('errors when there are multiple definitions of the same enum', () => {
const serviceA = {
typeDefs: gql`
type Product @key(fields: "color { id value }") {
sku: String!
upc: String!
color: Color!
}
type Color {
id: ID!
value: String!
}
enum ProductType {
BOOK
FURNITURE
}
enum ProductType {
DIGITAL
}
`,
name: 'serviceA',
};
const warnings = validateDuplicateEnumOrScalar(serviceA);
expect(warnings).toMatchInlineSnapshot(`
Array [
Object {
"code": "DUPLICATE_ENUM_DEFINITION",
"message": "[serviceA] ProductType -> The enum, \`ProductType\` was defined multiple times in this service. Remove one of the definitions for \`ProductType\`",
},
]
`);
});
it('errors when there are multiple definitions of the same scalar', () => {
const serviceA = {
typeDefs: gql`
scalar Date
type Product @key(fields: "color { id value }") {
sku: String!
upc: String!
deliveryDate: Date
}
scalar Date
`,
name: 'serviceA',
};
const warnings = validateDuplicateEnumOrScalar(serviceA);
expect(warnings).toMatchInlineSnapshot(`
Array [
Object {
"code": "DUPLICATE_SCALAR_DEFINITION",
"message": "[serviceA] Date -> The scalar, \`Date\` was defined multiple times in this service. Remove one of the definitions for \`Date\`",
},
]
`);
});
});