@apollo/gateway 0.45.1 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +42 -16
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +28 -18
- package/dist/config.js.map +1 -1
- package/dist/datasources/LocalGraphQLDataSource.js.map +1 -1
- package/dist/datasources/RemoteGraphQLDataSource.d.ts.map +1 -1
- package/dist/datasources/RemoteGraphQLDataSource.js +4 -1
- package/dist/datasources/RemoteGraphQLDataSource.js.map +1 -1
- package/dist/executeQueryPlan.d.ts.map +1 -1
- package/dist/executeQueryPlan.js +1 -1
- package/dist/executeQueryPlan.js.map +1 -1
- package/dist/index.d.ts +35 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +205 -308
- package/dist/index.js.map +1 -1
- package/dist/schema-helper/addResolversToSchema.d.ts +4 -0
- package/dist/schema-helper/addResolversToSchema.d.ts.map +1 -0
- package/dist/schema-helper/addResolversToSchema.js +62 -0
- package/dist/schema-helper/addResolversToSchema.js.map +1 -0
- package/dist/schema-helper/error.d.ts +6 -0
- package/dist/schema-helper/error.d.ts.map +1 -0
- package/dist/schema-helper/error.js +14 -0
- package/dist/schema-helper/error.js.map +1 -0
- package/dist/schema-helper/index.d.ts +4 -0
- package/dist/schema-helper/index.d.ts.map +1 -0
- package/dist/schema-helper/index.js +16 -0
- package/dist/schema-helper/index.js.map +1 -0
- package/dist/schema-helper/resolverMap.d.ts +16 -0
- package/dist/schema-helper/resolverMap.d.ts.map +1 -0
- package/dist/schema-helper/resolverMap.js +3 -0
- package/dist/schema-helper/resolverMap.js.map +1 -0
- package/dist/supergraphManagers/IntrospectAndCompose/index.d.ts +31 -0
- package/dist/supergraphManagers/IntrospectAndCompose/index.d.ts.map +1 -0
- package/dist/supergraphManagers/IntrospectAndCompose/index.js +112 -0
- package/dist/supergraphManagers/IntrospectAndCompose/index.js.map +1 -0
- package/dist/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.d.ts +12 -0
- package/dist/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.d.ts.map +1 -0
- package/dist/{loadServicesFromRemoteEndpoint.js → supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.js} +6 -6
- package/dist/supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.js.map +1 -0
- package/dist/supergraphManagers/LegacyFetcher/index.d.ts +33 -0
- package/dist/supergraphManagers/LegacyFetcher/index.d.ts.map +1 -0
- package/dist/supergraphManagers/LegacyFetcher/index.js +149 -0
- package/dist/supergraphManagers/LegacyFetcher/index.js.map +1 -0
- package/dist/supergraphManagers/LocalCompose/index.d.ts +19 -0
- package/dist/supergraphManagers/LocalCompose/index.d.ts.map +1 -0
- package/dist/supergraphManagers/LocalCompose/index.js +55 -0
- package/dist/supergraphManagers/LocalCompose/index.js.map +1 -0
- package/dist/supergraphManagers/UplinkFetcher/index.d.ts +32 -0
- package/dist/supergraphManagers/UplinkFetcher/index.d.ts.map +1 -0
- package/dist/supergraphManagers/UplinkFetcher/index.js +96 -0
- package/dist/supergraphManagers/UplinkFetcher/index.js.map +1 -0
- package/dist/{loadSupergraphSdlFromStorage.d.ts → supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.d.ts} +1 -1
- package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.d.ts.map +1 -0
- package/dist/{loadSupergraphSdlFromStorage.js → supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.js} +1 -1
- package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.js.map +1 -0
- package/dist/{outOfBandReporter.d.ts → supergraphManagers/UplinkFetcher/outOfBandReporter.d.ts} +0 -0
- package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.d.ts.map +1 -0
- package/dist/{outOfBandReporter.js → supergraphManagers/UplinkFetcher/outOfBandReporter.js} +2 -2
- package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.js.map +1 -0
- package/dist/supergraphManagers/index.d.ts +5 -0
- package/dist/supergraphManagers/index.d.ts.map +1 -0
- package/dist/supergraphManagers/index.js +12 -0
- package/dist/supergraphManagers/index.js.map +1 -0
- package/dist/utilities/createHash.d.ts +2 -0
- package/dist/utilities/createHash.d.ts.map +1 -0
- package/dist/utilities/createHash.js +15 -0
- package/dist/utilities/createHash.js.map +1 -0
- package/dist/utilities/isNodeLike.d.ts +3 -0
- package/dist/utilities/isNodeLike.d.ts.map +1 -0
- package/dist/utilities/isNodeLike.js +8 -0
- package/dist/utilities/isNodeLike.js.map +1 -0
- package/package.json +12 -10
- package/src/__mocks__/make-fetch-happen-fetcher.ts +3 -1
- package/src/__tests__/executeQueryPlan.test.ts +1 -1
- package/src/__tests__/execution-utils.ts +3 -3
- package/src/__tests__/gateway/buildService.test.ts +3 -3
- package/src/__tests__/gateway/endToEnd.test.ts +1 -1
- package/src/__tests__/gateway/executor.test.ts +1 -1
- package/src/__tests__/gateway/lifecycle-hooks.test.ts +58 -99
- package/src/__tests__/gateway/opentelemetry.test.ts +8 -3
- package/src/__tests__/gateway/queryPlanCache.test.ts +25 -9
- package/src/__tests__/gateway/reporting.test.ts +44 -19
- package/src/__tests__/gateway/supergraphSdl.test.ts +394 -0
- package/src/__tests__/integration/aliases.test.ts +9 -3
- package/src/__tests__/integration/configuration.test.ts +109 -12
- package/src/__tests__/integration/logger.test.ts +1 -1
- package/src/__tests__/integration/networkRequests.test.ts +81 -118
- package/src/__tests__/integration/nockMocks.ts +15 -8
- package/src/config.ts +149 -40
- package/src/datasources/LocalGraphQLDataSource.ts +1 -1
- package/src/datasources/RemoteGraphQLDataSource.ts +8 -2
- package/src/datasources/__tests__/LocalGraphQLDataSource.test.ts +1 -1
- package/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts +4 -4
- package/src/executeQueryPlan.ts +3 -1
- package/src/index.ts +314 -485
- package/src/schema-helper/addResolversToSchema.ts +83 -0
- package/src/schema-helper/error.ts +11 -0
- package/src/schema-helper/index.ts +3 -0
- package/src/schema-helper/resolverMap.ts +23 -0
- package/src/supergraphManagers/IntrospectAndCompose/__tests__/IntrospectAndCompose.test.ts +370 -0
- package/src/{__tests__ → supergraphManagers/IntrospectAndCompose/__tests__}/loadServicesFromRemoteEndpoint.test.ts +5 -5
- package/src/supergraphManagers/IntrospectAndCompose/__tests__/tsconfig.json +8 -0
- package/src/supergraphManagers/IntrospectAndCompose/index.ts +163 -0
- package/src/{loadServicesFromRemoteEndpoint.ts → supergraphManagers/IntrospectAndCompose/loadServicesFromRemoteEndpoint.ts} +6 -6
- package/src/supergraphManagers/LegacyFetcher/index.ts +229 -0
- package/src/supergraphManagers/LocalCompose/index.ts +83 -0
- package/src/{__tests__ → supergraphManagers/UplinkFetcher/__tests__}/loadSupergraphSdlFromStorage.test.ts +4 -4
- package/src/supergraphManagers/UplinkFetcher/__tests__/tsconfig.json +8 -0
- package/src/supergraphManagers/UplinkFetcher/index.ts +128 -0
- package/src/{loadSupergraphSdlFromStorage.ts → supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.ts} +3 -3
- package/src/{outOfBandReporter.ts → supergraphManagers/UplinkFetcher/outOfBandReporter.ts} +2 -2
- package/src/supergraphManagers/index.ts +4 -0
- package/src/utilities/__tests__/cleanErrorOfInaccessibleElements.test.ts +5 -5
- package/src/utilities/createHash.ts +10 -0
- package/src/utilities/isNodeLike.ts +11 -0
- package/CHANGELOG.md +0 -474
- package/dist/loadServicesFromRemoteEndpoint.d.ts +0 -13
- package/dist/loadServicesFromRemoteEndpoint.d.ts.map +0 -1
- package/dist/loadServicesFromRemoteEndpoint.js.map +0 -1
- package/dist/loadSupergraphSdlFromStorage.d.ts.map +0 -1
- package/dist/loadSupergraphSdlFromStorage.js.map +0 -1
- package/dist/outOfBandReporter.d.ts.map +0 -1
- package/dist/outOfBandReporter.js.map +0 -1
- package/src/__tests__/gateway/composedSdl.test.ts +0 -44
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApolloGateway,
|
|
3
|
+
RemoteGraphQLDataSource,
|
|
4
|
+
SubgraphHealthCheckFunction,
|
|
5
|
+
SupergraphSdlUpdateFunction,
|
|
6
|
+
} from '@apollo/gateway';
|
|
7
|
+
import { fixturesWithUpdate } from 'apollo-federation-integration-testsuite';
|
|
8
|
+
import { createHash } from '../../utilities/createHash';
|
|
9
|
+
import { ApolloServer } from 'apollo-server';
|
|
10
|
+
import { Logger } from 'apollo-server-types';
|
|
11
|
+
import { fetch } from '../../__mocks__/make-fetch-happen-fetcher';
|
|
12
|
+
import { getTestingSupergraphSdl } from '../execution-utils';
|
|
13
|
+
import { mockAllServicesHealthCheckSuccess } from '../integration/nockMocks';
|
|
14
|
+
import resolvable from '@josephg/resolvable';
|
|
15
|
+
import { nockAfterEach, nockBeforeEach } from '../nockAssertions';
|
|
16
|
+
|
|
17
|
+
async function getSupergraphSdlGatewayServer() {
|
|
18
|
+
const server = new ApolloServer({
|
|
19
|
+
gateway: new ApolloGateway({
|
|
20
|
+
supergraphSdl: getTestingSupergraphSdl(),
|
|
21
|
+
buildService({ url }) {
|
|
22
|
+
return new RemoteGraphQLDataSource({ url, fetcher: fetch });
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await server.listen({ port: 0 });
|
|
28
|
+
return server;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let logger: Logger;
|
|
32
|
+
let gateway: ApolloGateway | null;
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
nockBeforeEach();
|
|
35
|
+
|
|
36
|
+
logger = {
|
|
37
|
+
debug: jest.fn(),
|
|
38
|
+
info: jest.fn(),
|
|
39
|
+
warn: jest.fn(),
|
|
40
|
+
error: jest.fn(),
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterEach(async () => {
|
|
45
|
+
nockAfterEach();
|
|
46
|
+
|
|
47
|
+
if (gateway) {
|
|
48
|
+
await gateway.stop();
|
|
49
|
+
gateway = null;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('Using supergraphSdl static configuration', () => {
|
|
54
|
+
it('successfully starts and serves requests to the proper services', async () => {
|
|
55
|
+
const server = await getSupergraphSdlGatewayServer();
|
|
56
|
+
|
|
57
|
+
fetch.mockJSONResponseOnce({
|
|
58
|
+
data: { me: { username: '@jbaxleyiii' } },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const result = await server.executeOperation({
|
|
62
|
+
query: '{ me { username } }',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(result.data).toMatchInlineSnapshot(`
|
|
66
|
+
Object {
|
|
67
|
+
"me": Object {
|
|
68
|
+
"username": "@jbaxleyiii",
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
`);
|
|
72
|
+
|
|
73
|
+
const [url, request] = fetch.mock.calls[0];
|
|
74
|
+
expect(url).toEqual('https://accounts.api.com');
|
|
75
|
+
expect(request?.body).toEqual(
|
|
76
|
+
JSON.stringify({ query: '{me{username}}', variables: {} }),
|
|
77
|
+
);
|
|
78
|
+
await server.stop();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('Using supergraphSdl dynamic configuration', () => {
|
|
83
|
+
it('calls the user provided function after `gateway.load()` is called', async () => {
|
|
84
|
+
const callbackSpy = jest.fn(async () => ({
|
|
85
|
+
supergraphSdl: getTestingSupergraphSdl(),
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
gateway = new ApolloGateway({
|
|
89
|
+
supergraphSdl: callbackSpy,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(callbackSpy).not.toHaveBeenCalled();
|
|
93
|
+
await gateway.load();
|
|
94
|
+
expect(callbackSpy).toHaveBeenCalled();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('starts and remains in `initialized` state until `supergraphSdl` Promise resolves', async () => {
|
|
98
|
+
const promiseGuaranteeingWeAreInTheCallback = resolvable();
|
|
99
|
+
const promiseGuaranteeingWeStayInTheCallback = resolvable();
|
|
100
|
+
|
|
101
|
+
gateway = new ApolloGateway({
|
|
102
|
+
async supergraphSdl() {
|
|
103
|
+
promiseGuaranteeingWeAreInTheCallback.resolve();
|
|
104
|
+
await promiseGuaranteeingWeStayInTheCallback;
|
|
105
|
+
return {
|
|
106
|
+
supergraphSdl: getTestingSupergraphSdl(),
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(gateway.__testing().state.phase).toEqual('initialized');
|
|
112
|
+
|
|
113
|
+
const gatewayLoaded = gateway.load();
|
|
114
|
+
await promiseGuaranteeingWeAreInTheCallback;
|
|
115
|
+
expect(gateway.__testing().state.phase).toEqual('initialized');
|
|
116
|
+
|
|
117
|
+
promiseGuaranteeingWeStayInTheCallback.resolve();
|
|
118
|
+
await gatewayLoaded;
|
|
119
|
+
expect(gateway.__testing().state.phase).toEqual('loaded');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('moves from `initialized` to `loaded` state after calling `load()` and after user Promise resolves', async () => {
|
|
123
|
+
const userPromise = resolvable<{ supergraphSdl: string }>();
|
|
124
|
+
|
|
125
|
+
gateway = new ApolloGateway({
|
|
126
|
+
async supergraphSdl() {
|
|
127
|
+
return userPromise;
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const loadPromise = gateway.load();
|
|
132
|
+
expect(gateway.__testing().state.phase).toEqual('initialized');
|
|
133
|
+
|
|
134
|
+
const supergraphSdl = getTestingSupergraphSdl();
|
|
135
|
+
const expectedCompositionId = createHash('sha256')
|
|
136
|
+
.update(supergraphSdl)
|
|
137
|
+
.digest('hex');
|
|
138
|
+
userPromise.resolve({ supergraphSdl });
|
|
139
|
+
|
|
140
|
+
await loadPromise;
|
|
141
|
+
const { state, compositionId } = gateway.__testing();
|
|
142
|
+
expect(state.phase).toEqual('loaded');
|
|
143
|
+
expect(compositionId).toEqual(expectedCompositionId);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('updates its supergraph after user calls update function', async () => {
|
|
147
|
+
const userPromise = resolvable<{ supergraphSdl: string }>();
|
|
148
|
+
|
|
149
|
+
let userUpdateFn: SupergraphSdlUpdateFunction;
|
|
150
|
+
gateway = new ApolloGateway({
|
|
151
|
+
async supergraphSdl({ update }) {
|
|
152
|
+
userUpdateFn = update;
|
|
153
|
+
return userPromise;
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const supergraphSdl = getTestingSupergraphSdl();
|
|
158
|
+
const expectedId = createHash('sha256').update(supergraphSdl).digest('hex');
|
|
159
|
+
userPromise.resolve({ supergraphSdl: getTestingSupergraphSdl() });
|
|
160
|
+
await gateway.load();
|
|
161
|
+
expect(gateway.__testing().compositionId).toEqual(expectedId);
|
|
162
|
+
|
|
163
|
+
const updatedSupergraphSdl = getTestingSupergraphSdl(fixturesWithUpdate);
|
|
164
|
+
const expectedUpdatedId = createHash('sha256')
|
|
165
|
+
.update(updatedSupergraphSdl)
|
|
166
|
+
.digest('hex');
|
|
167
|
+
|
|
168
|
+
userUpdateFn!(updatedSupergraphSdl);
|
|
169
|
+
expect(gateway.__testing().compositionId).toEqual(expectedUpdatedId);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('calls user-provided `cleanup` function when stopped', async () => {
|
|
173
|
+
const cleanup = jest.fn(() => Promise.resolve());
|
|
174
|
+
gateway = new ApolloGateway({
|
|
175
|
+
async supergraphSdl() {
|
|
176
|
+
return {
|
|
177
|
+
supergraphSdl: getTestingSupergraphSdl(),
|
|
178
|
+
cleanup,
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
await gateway.load();
|
|
184
|
+
const { state, compositionId } = gateway.__testing();
|
|
185
|
+
expect(state.phase).toEqual('loaded');
|
|
186
|
+
expect(compositionId).toEqual(
|
|
187
|
+
'562c22b3382b56b1651944a96e89a361fe847b9b32660eae5ecbd12adc20bf8b',
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
await gateway.stop();
|
|
191
|
+
expect(cleanup).toHaveBeenCalledTimes(1);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('performs a successful health check on subgraphs', async () => {
|
|
195
|
+
mockAllServicesHealthCheckSuccess();
|
|
196
|
+
|
|
197
|
+
let healthCheckCallback: SubgraphHealthCheckFunction;
|
|
198
|
+
const supergraphSdl = getTestingSupergraphSdl();
|
|
199
|
+
gateway = new ApolloGateway({
|
|
200
|
+
async supergraphSdl({ healthCheck }) {
|
|
201
|
+
healthCheckCallback = healthCheck;
|
|
202
|
+
return {
|
|
203
|
+
supergraphSdl,
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
await gateway.load();
|
|
209
|
+
const { state, compositionId } = gateway.__testing();
|
|
210
|
+
expect(state.phase).toEqual('loaded');
|
|
211
|
+
expect(compositionId).toEqual(
|
|
212
|
+
'562c22b3382b56b1651944a96e89a361fe847b9b32660eae5ecbd12adc20bf8b',
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
await expect(healthCheckCallback!(supergraphSdl)).resolves.toBeUndefined();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('calls `initialize` on an object provided to `supergraphSdl`', async () => {
|
|
219
|
+
const MockSdlUpdatingClass = {
|
|
220
|
+
initialize() {
|
|
221
|
+
return Promise.resolve({
|
|
222
|
+
supergraphSdl: getTestingSupergraphSdl(),
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
const initializeSpy = jest.spyOn(MockSdlUpdatingClass, 'initialize');
|
|
227
|
+
|
|
228
|
+
gateway = new ApolloGateway({
|
|
229
|
+
supergraphSdl: MockSdlUpdatingClass,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
expect(initializeSpy).not.toHaveBeenCalled();
|
|
233
|
+
await gateway.load();
|
|
234
|
+
expect(initializeSpy).toHaveBeenCalled();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe('errors', () => {
|
|
238
|
+
it('fails to load if `SupergraphManager` throws on initialization', async () => {
|
|
239
|
+
const failureMessage = 'Error from supergraphSdl function';
|
|
240
|
+
gateway = new ApolloGateway({
|
|
241
|
+
async supergraphSdl() {
|
|
242
|
+
throw new Error(failureMessage);
|
|
243
|
+
},
|
|
244
|
+
logger,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await expect(gateway.load()).rejects.toThrowError(failureMessage);
|
|
248
|
+
|
|
249
|
+
expect(gateway.__testing().state.phase).toEqual('failed to load');
|
|
250
|
+
// we don't want the `afterEach` to call `gateway.stop()` in this case
|
|
251
|
+
// since it would throw an error due to the gateway's failed to load state
|
|
252
|
+
gateway = null;
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('gracefully handles Promise rejections from user `cleanup` function', async () => {
|
|
256
|
+
const rejectionMessage = 'thrown from cleanup function';
|
|
257
|
+
const cleanup = jest.fn(() => Promise.reject(rejectionMessage));
|
|
258
|
+
gateway = new ApolloGateway({
|
|
259
|
+
async supergraphSdl() {
|
|
260
|
+
return {
|
|
261
|
+
supergraphSdl: getTestingSupergraphSdl(),
|
|
262
|
+
cleanup,
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
logger,
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
await gateway.load();
|
|
269
|
+
await expect(gateway.stop()).resolves.toBeUndefined();
|
|
270
|
+
expect(cleanup).toHaveBeenCalledTimes(1);
|
|
271
|
+
expect(logger.error).toHaveBeenCalledWith(
|
|
272
|
+
'Error occured while calling user provided `cleanup` function: ' +
|
|
273
|
+
rejectionMessage,
|
|
274
|
+
);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('throws an error when `healthCheck` rejects', async () => {
|
|
278
|
+
// no mocks, so nock will reject
|
|
279
|
+
let healthCheckCallback: SubgraphHealthCheckFunction;
|
|
280
|
+
const supergraphSdl = getTestingSupergraphSdl();
|
|
281
|
+
gateway = new ApolloGateway({
|
|
282
|
+
async supergraphSdl({ healthCheck }) {
|
|
283
|
+
healthCheckCallback = healthCheck;
|
|
284
|
+
return {
|
|
285
|
+
supergraphSdl,
|
|
286
|
+
};
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
await gateway.load();
|
|
291
|
+
const { state, compositionId } = gateway.__testing();
|
|
292
|
+
expect(state.phase).toEqual('loaded');
|
|
293
|
+
expect(compositionId).toEqual(
|
|
294
|
+
'562c22b3382b56b1651944a96e89a361fe847b9b32660eae5ecbd12adc20bf8b',
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
await expect(healthCheckCallback!(supergraphSdl)).rejects.toThrowError(
|
|
298
|
+
/The gateway subgraphs health check failed\. Updating to the provided `supergraphSdl` will likely result in future request failures to subgraphs\. The following error occurred during the health check/,
|
|
299
|
+
);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('throws an error when `update` is called after gateway fails to load', async () => {
|
|
303
|
+
let updateCallback: SupergraphSdlUpdateFunction;
|
|
304
|
+
const supergraphSdl = getTestingSupergraphSdl();
|
|
305
|
+
gateway = new ApolloGateway({
|
|
306
|
+
async supergraphSdl({ update }) {
|
|
307
|
+
updateCallback = update;
|
|
308
|
+
return {
|
|
309
|
+
supergraphSdl: 'invalid SDL',
|
|
310
|
+
};
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
try {
|
|
315
|
+
await gateway.load();
|
|
316
|
+
} catch {}
|
|
317
|
+
|
|
318
|
+
expect(() =>
|
|
319
|
+
updateCallback!(supergraphSdl),
|
|
320
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
321
|
+
`"Can't call \`update\` callback after gateway failed to load."`,
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
// gateway failed to load, so we don't want the `afterEach` to call `gateway.stop()`
|
|
325
|
+
gateway = null;
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('throws an error when `update` is called while an update is in progress', async () => {
|
|
329
|
+
let updateCallback: SupergraphSdlUpdateFunction;
|
|
330
|
+
const supergraphSdl = getTestingSupergraphSdl();
|
|
331
|
+
gateway = new ApolloGateway({
|
|
332
|
+
async supergraphSdl({ update }) {
|
|
333
|
+
updateCallback = update;
|
|
334
|
+
return {
|
|
335
|
+
supergraphSdl,
|
|
336
|
+
};
|
|
337
|
+
},
|
|
338
|
+
experimental_didUpdateSupergraph() {
|
|
339
|
+
updateCallback(getTestingSupergraphSdl(fixturesWithUpdate));
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
await expect(gateway.load()).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
344
|
+
`"Can't call \`update\` callback while supergraph update is in progress."`,
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
// gateway failed to load, so we don't want the `afterEach` to call `gateway.stop()`
|
|
348
|
+
gateway = null;
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('throws an error when `update` is called after gateway is stopped', async () => {
|
|
352
|
+
let updateCallback: SupergraphSdlUpdateFunction;
|
|
353
|
+
const supergraphSdl = getTestingSupergraphSdl();
|
|
354
|
+
gateway = new ApolloGateway({
|
|
355
|
+
async supergraphSdl({ update }) {
|
|
356
|
+
updateCallback = update;
|
|
357
|
+
return {
|
|
358
|
+
supergraphSdl,
|
|
359
|
+
};
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
await gateway.load();
|
|
364
|
+
await gateway.stop();
|
|
365
|
+
|
|
366
|
+
expect(() =>
|
|
367
|
+
updateCallback!(getTestingSupergraphSdl(fixturesWithUpdate)),
|
|
368
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
369
|
+
`"Can't call \`update\` callback after gateway has been stopped."`,
|
|
370
|
+
);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('throws an error when `update` is called with an invalid supergraph', async () => {
|
|
374
|
+
let updateCallback: SupergraphSdlUpdateFunction;
|
|
375
|
+
const supergraphSdl = getTestingSupergraphSdl();
|
|
376
|
+
gateway = new ApolloGateway({
|
|
377
|
+
async supergraphSdl({ update }) {
|
|
378
|
+
updateCallback = update;
|
|
379
|
+
return {
|
|
380
|
+
supergraphSdl,
|
|
381
|
+
};
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
await gateway.load();
|
|
386
|
+
|
|
387
|
+
expect(() =>
|
|
388
|
+
updateCallback!('invalid SDL'),
|
|
389
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
390
|
+
`"Syntax Error: Unexpected Name \\"invalid\\"."`,
|
|
391
|
+
);
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
});
|
|
@@ -141,11 +141,17 @@ it('supports aliases of nested fields on subservices', async () => {
|
|
|
141
141
|
|
|
142
142
|
// TODO after we remove GraphQLExtensions from ApolloServer, this can go away
|
|
143
143
|
it('supports aliases when using ApolloServer', async () => {
|
|
144
|
+
const localDataSources = Object.fromEntries(
|
|
145
|
+
fixtures.map((f) => [
|
|
146
|
+
f.name,
|
|
147
|
+
new LocalGraphQLDataSource(buildSubgraphSchema(f)),
|
|
148
|
+
]),
|
|
149
|
+
);
|
|
150
|
+
|
|
144
151
|
const gateway = new ApolloGateway({
|
|
145
152
|
localServiceList: fixtures,
|
|
146
|
-
buildService
|
|
147
|
-
|
|
148
|
-
return new LocalGraphQLDataSource(buildSubgraphSchema([service]));
|
|
153
|
+
buildService(service) {
|
|
154
|
+
return localDataSources[service.name];
|
|
149
155
|
},
|
|
150
156
|
});
|
|
151
157
|
|
|
@@ -12,11 +12,11 @@ import {
|
|
|
12
12
|
mockCloudConfigUrl3,
|
|
13
13
|
} from './nockMocks';
|
|
14
14
|
import { getTestingSupergraphSdl } from '../execution-utils';
|
|
15
|
-
import {
|
|
15
|
+
import { fixtures, Fixture } from 'apollo-federation-integration-testsuite';
|
|
16
16
|
|
|
17
17
|
let logger: Logger;
|
|
18
18
|
|
|
19
|
-
const service:
|
|
19
|
+
const service: Fixture = {
|
|
20
20
|
name: 'accounts',
|
|
21
21
|
url: 'http://localhost:4001',
|
|
22
22
|
typeDefs: gql`
|
|
@@ -326,14 +326,17 @@ describe('gateway config / env behavior', () => {
|
|
|
326
326
|
APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT: 'env-config',
|
|
327
327
|
});
|
|
328
328
|
|
|
329
|
-
|
|
329
|
+
const config = {
|
|
330
330
|
logger,
|
|
331
331
|
uplinkEndpoints: [mockCloudConfigUrl1, mockCloudConfigUrl2, mockCloudConfigUrl3],
|
|
332
|
-
}
|
|
332
|
+
};
|
|
333
|
+
gateway = new ApolloGateway(config);
|
|
333
334
|
|
|
334
|
-
expect(gateway['
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
expect(gateway['getUplinkEndpoints'](config)).toEqual([
|
|
336
|
+
mockCloudConfigUrl1,
|
|
337
|
+
mockCloudConfigUrl2,
|
|
338
|
+
mockCloudConfigUrl3,
|
|
339
|
+
]);
|
|
337
340
|
|
|
338
341
|
gateway = null;
|
|
339
342
|
});
|
|
@@ -345,16 +348,110 @@ describe('gateway config / env behavior', () => {
|
|
|
345
348
|
APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT: 'env-config',
|
|
346
349
|
});
|
|
347
350
|
|
|
348
|
-
|
|
351
|
+
const config = {
|
|
349
352
|
logger,
|
|
350
353
|
schemaConfigDeliveryEndpoint: 'code-config',
|
|
351
|
-
}
|
|
354
|
+
};
|
|
355
|
+
gateway = new ApolloGateway(config);
|
|
352
356
|
|
|
353
|
-
expect(gateway['
|
|
354
|
-
['code-config'],
|
|
355
|
-
);
|
|
357
|
+
expect(gateway['getUplinkEndpoints'](config)).toEqual(['code-config']);
|
|
356
358
|
|
|
357
359
|
gateway = null;
|
|
358
360
|
});
|
|
359
361
|
});
|
|
360
362
|
});
|
|
363
|
+
|
|
364
|
+
describe('deprecation warnings', () => {
|
|
365
|
+
it('warns with `experimental_updateSupergraphSdl` option set', async () => {
|
|
366
|
+
const gateway = new ApolloGateway({
|
|
367
|
+
async experimental_updateSupergraphSdl() {
|
|
368
|
+
return {
|
|
369
|
+
id: 'supergraph',
|
|
370
|
+
supergraphSdl: getTestingSupergraphSdl(),
|
|
371
|
+
};
|
|
372
|
+
},
|
|
373
|
+
logger,
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
await gateway.load();
|
|
377
|
+
|
|
378
|
+
expect(logger.warn).toHaveBeenCalledWith(
|
|
379
|
+
'The `experimental_updateSupergraphSdl` option is deprecated and will be removed in a future version of `@apollo/gateway`. Please migrate to the function form of the `supergraphSdl` configuration option.',
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
await gateway.stop();
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('warns with `experimental_updateServiceDefinitions` option set', async () => {
|
|
386
|
+
const gateway = new ApolloGateway({
|
|
387
|
+
async experimental_updateServiceDefinitions() {
|
|
388
|
+
return {
|
|
389
|
+
isNewSchema: false,
|
|
390
|
+
};
|
|
391
|
+
},
|
|
392
|
+
logger,
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
try {
|
|
396
|
+
await gateway.load();
|
|
397
|
+
// gateway will throw since we're not providing an actual service list, disregard
|
|
398
|
+
} catch {}
|
|
399
|
+
|
|
400
|
+
expect(logger.warn).toHaveBeenCalledWith(
|
|
401
|
+
'The `experimental_updateServiceDefinitions` option is deprecated and will be removed in a future version of `@apollo/gateway`. Please migrate to the function form of the `supergraphSdl` configuration option.',
|
|
402
|
+
);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it('warns with `serviceList` option set', async () => {
|
|
406
|
+
const gateway = new ApolloGateway({
|
|
407
|
+
serviceList: [{ name: 'accounts', url: 'http://localhost:4001' }],
|
|
408
|
+
logger,
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
try {
|
|
412
|
+
await gateway.load();
|
|
413
|
+
// gateway will throw since we haven't mocked these requests, unimportant for this test
|
|
414
|
+
} catch {}
|
|
415
|
+
|
|
416
|
+
expect(logger.warn).toHaveBeenCalledWith(
|
|
417
|
+
'The `serviceList` option is deprecated and will be removed in a future version of `@apollo/gateway`. Please migrate to its replacement `IntrospectAndCompose`. More information on `IntrospectAndCompose` can be found in the documentation.',
|
|
418
|
+
);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it('warns with `localServiceList` option set', async () => {
|
|
422
|
+
const gateway = new ApolloGateway({
|
|
423
|
+
localServiceList: fixtures,
|
|
424
|
+
logger,
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
await gateway.load();
|
|
428
|
+
|
|
429
|
+
expect(logger.warn).toHaveBeenCalledWith(
|
|
430
|
+
'The `localServiceList` option is deprecated and will be removed in a future version of `@apollo/gateway`. Please migrate to the `LocalCompose` supergraph manager exported by `@apollo/gateway`.',
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
await gateway.stop();
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it('warns with `schemaConfigDeliveryEndpoint` option set', async () => {
|
|
437
|
+
new ApolloGateway({
|
|
438
|
+
schemaConfigDeliveryEndpoint: 'test',
|
|
439
|
+
logger,
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
expect(logger.warn).toHaveBeenCalledWith(
|
|
443
|
+
'The `schemaConfigDeliveryEndpoint` option is deprecated and will be removed in a future version of `@apollo/gateway`. Please migrate to the equivalent (array form) `uplinkEndpoints` configuration option.',
|
|
444
|
+
);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it('warns with `experimental_pollInterval` option set', async () => {
|
|
448
|
+
new ApolloGateway({
|
|
449
|
+
experimental_pollInterval: 10000,
|
|
450
|
+
logger,
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
expect(logger.warn).toHaveBeenCalledWith(
|
|
454
|
+
'The `experimental_pollInterval` option is deprecated and will be removed in a future version of `@apollo/gateway`. Please migrate to the equivalent `pollIntervalInMs` configuration option.',
|
|
455
|
+
);
|
|
456
|
+
});
|
|
457
|
+
});
|
|
@@ -10,7 +10,7 @@ import * as log4js from "log4js";
|
|
|
10
10
|
|
|
11
11
|
const LOWEST_LOG_LEVEL = "debug";
|
|
12
12
|
|
|
13
|
-
const KNOWN_DEBUG_MESSAGE = "
|
|
13
|
+
const KNOWN_DEBUG_MESSAGE = "Gateway successfully initialized (but not yet loaded)";
|
|
14
14
|
|
|
15
15
|
async function triggerKnownDebugMessage(logger: Logger) {
|
|
16
16
|
// Trigger a known error.
|