-
Notifications
You must be signed in to change notification settings - Fork 242
/
executableDirectivesIdentical.test.ts
122 lines (108 loc) 路 3.78 KB
/
executableDirectivesIdentical.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
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 gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { executableDirectivesIdentical } from '../';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';
expect.addSnapshotSerializer(graphqlErrorSerializer);
describe('executableDirectivesIdentical', () => {
it('throws no errors when custom, executable directives are defined identically every service', () => {
const serviceA = {
typeDefs: gql`
directive @stream on FIELD
directive @instrument(tag: String!) on FIELD
`,
name: 'serviceA',
};
const serviceB = {
typeDefs: gql`
directive @stream on FIELD
directive @instrument(tag: String!) on FIELD
`,
name: 'serviceB',
};
const serviceList = [serviceA, serviceB];
const { schema } = composeServices(serviceList);
const errors = executableDirectivesIdentical({ schema, serviceList });
expect(errors).toHaveLength(0);
});
it('throws no errors when directives (excluding their TypeSystemDirectiveLocations) are identical for every service', () => {
const serviceA = {
typeDefs: gql`
directive @stream on FIELD
directive @instrument(tag: String!) on FIELD | FIELD_DEFINITION
`,
name: 'serviceA',
};
const serviceB = {
typeDefs: gql`
directive @stream on FIELD
directive @instrument(tag: String!) on FIELD
`,
name: 'serviceB',
};
const serviceList = [serviceA, serviceB];
const { schema } = composeServices(serviceList);
const errors = executableDirectivesIdentical({ schema, serviceList });
expect(errors).toHaveLength(0);
});
it("throws errors when custom, executable directives aren't defined with the same locations in every service", () => {
const serviceA = {
typeDefs: gql`
directive @stream on FIELD
`,
name: 'serviceA',
};
const serviceB = {
typeDefs: gql`
directive @stream on FIELD | QUERY
`,
name: 'serviceB',
};
const serviceC = {
typeDefs: gql`
directive @stream on INLINE_FRAGMENT
`,
name: 'serviceC',
};
const serviceList = [serviceA, serviceB, serviceC];
const { schema } = composeServices(serviceList);
const errors = executableDirectivesIdentical({ schema, serviceList });
expect(errors).toMatchInlineSnapshot(`
Array [
Object {
"code": "EXECUTABLE_DIRECTIVES_IDENTICAL",
"message": "[@stream] -> custom directives must be defined identically across all services. See below for a list of current implementations:
serviceA: directive @stream on FIELD
serviceB: directive @stream on FIELD | QUERY
serviceC: directive @stream on INLINE_FRAGMENT",
},
]
`);
});
it("throws errors when custom, executable directives aren't defined with the same arguments in every service", () => {
const serviceA = {
typeDefs: gql`
directive @instrument(tag: String!) on FIELD
`,
name: 'serviceA',
};
const serviceB = {
typeDefs: gql`
directive @instrument(tag: Boolean) on FIELD
`,
name: 'serviceB',
};
const serviceList = [serviceA, serviceB];
const { schema } = composeServices(serviceList);
const errors = executableDirectivesIdentical({ schema, serviceList });
expect(errors).toMatchInlineSnapshot(`
Array [
Object {
"code": "EXECUTABLE_DIRECTIVES_IDENTICAL",
"message": "[@instrument] -> custom directives must be defined identically across all services. See below for a list of current implementations:
serviceA: directive @instrument(tag: String!) on FIELD
serviceB: directive @instrument(tag: Boolean) on FIELD",
},
]
`);
});
});