-
Notifications
You must be signed in to change notification settings - Fork 242
/
executableDirectivesInAllServices.test.ts
91 lines (80 loc) 路 2.57 KB
/
executableDirectivesInAllServices.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
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { executableDirectivesInAllServices } from '../';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';
expect.addSnapshotSerializer(graphqlErrorSerializer);
describe('executableDirectivesInAllServices', () => {
it('throws no errors when custom, executable directives are defined in every service', () => {
const serviceA = {
typeDefs: gql`
directive @stream on FIELD
`,
name: 'serviceA',
};
const serviceB = {
typeDefs: gql`
directive @stream on FIELD
`,
name: 'serviceB',
};
const serviceList = [serviceA, serviceB];
const { schema } = composeServices(serviceList);
const errors = executableDirectivesInAllServices({ schema, serviceList });
expect(errors).toHaveLength(0);
});
it("throws no errors when type system directives aren't defined in every service", () => {
const serviceA = {
typeDefs: gql`
directive @stream on FIELD
`,
name: 'serviceA',
};
const serviceB = {
typeDefs: gql`
directive @stream on FIELD
# This directive is ignored by composition and therefore post-composition validators
directive @ignored on FIELD_DEFINITION
`,
name: 'serviceB',
};
const serviceList = [serviceA, serviceB];
const { schema } = composeServices(serviceList);
const errors = executableDirectivesInAllServices({ schema, serviceList });
expect(errors).toHaveLength(0);
});
it("throws errors when custom, executable directives aren't defined in every service", () => {
const serviceA = {
typeDefs: gql`
directive @stream on FIELD
`,
name: 'serviceA',
};
const serviceB = {
typeDefs: gql`
extend type Query {
thing: String
}
`,
name: 'serviceB',
};
const serviceC = {
typeDefs: gql`
extend type Query {
otherThing: String
}
`,
name: 'serviceC',
};
const serviceList = [serviceA, serviceB, serviceC];
const { schema } = composeServices(serviceList);
const errors = executableDirectivesInAllServices({ schema, serviceList });
expect(errors).toMatchInlineSnapshot(`
Array [
Object {
"code": "EXECUTABLE_DIRECTIVES_IN_ALL_SERVICES",
"message": "[@stream] -> Custom directives must be implemented in every service. The following services do not implement the @stream directive: serviceB, serviceC.",
},
]
`);
});
});