-
Notifications
You must be signed in to change notification settings - Fork 242
/
providesFieldsMissingExternals.test.ts
109 lines (98 loc) 路 2.87 KB
/
providesFieldsMissingExternals.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
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { providesFieldsMissingExternal as validateProdivesFieldsMissingExternal } from '../';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';
import { assertCompositionSuccess } from '../../../utils';
expect.addSnapshotSerializer(graphqlErrorSerializer);
describe('providesFieldsMissingExternal', () => {
it('does not warn with proper @provides usage', () => {
const serviceA = {
typeDefs: gql`
type Product @key(fields: "sku") {
sku: String!
upc: String!
id: ID!
}
`,
name: 'serviceA',
};
const serviceB = {
typeDefs: gql`
type User @key(fields: "id") {
id: ID!
username: String
}
`,
name: 'serviceB',
};
const serviceC = {
typeDefs: gql`
type Review @key(fields: "id") {
id: ID!
product: Product @provides(fields: "id")
author: User @provides(fields: "username")
}
extend type Product @key(fields: "sku") {
sku: String! @external
id: ID! @external
price: Int!
}
extend type User @key(fields: "id") {
id: ID! @external
username: String @external
}
`,
name: 'serviceC',
};
const serviceList = [serviceA, serviceB, serviceC];
const compositionResult = composeServices(serviceList);
assertCompositionSuccess(compositionResult);
const { schema } = compositionResult;
const warnings = validateProdivesFieldsMissingExternal({
schema,
serviceList,
});
expect(warnings).toEqual([]);
});
it('warns when there is a @provides with no matching @external field', () => {
const serviceA = {
typeDefs: gql`
type Product @key(fields: "sku") {
sku: String!
upc: String!
id: ID!
}
`,
name: 'serviceA',
};
const serviceB = {
typeDefs: gql`
type Review @key(fields: "id") {
id: ID!
product: Product @provides(fields: "id")
}
extend type Product @key(fields: "sku") {
sku: String! @external
price: Int!
}
`,
name: 'serviceB',
};
const serviceList = [serviceA, serviceB];
const compositionResult = composeServices(serviceList);
assertCompositionSuccess(compositionResult);
const { schema } = compositionResult;
const warnings = validateProdivesFieldsMissingExternal({
schema,
serviceList,
});
expect(warnings).toMatchInlineSnapshot(`
Array [
Object {
"code": "PROVIDES_FIELDS_MISSING_EXTERNAL",
"message": "[serviceB] Review.product -> provides the field \`id\` and requires Product.id to be marked as @external.",
},
]
`);
});
});