@apollo/gateway 2.0.0-alpha.2 → 2.0.0-alpha.3

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.
Files changed (40) hide show
  1. package/dist/config.d.ts +2 -0
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/config.js.map +1 -1
  4. package/dist/datasources/RemoteGraphQLDataSource.d.ts.map +1 -1
  5. package/dist/datasources/RemoteGraphQLDataSource.js +4 -1
  6. package/dist/datasources/RemoteGraphQLDataSource.js.map +1 -1
  7. package/dist/executeQueryPlan.d.ts.map +1 -1
  8. package/dist/executeQueryPlan.js +1 -1
  9. package/dist/executeQueryPlan.js.map +1 -1
  10. package/dist/index.d.ts +3 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +18 -6
  13. package/dist/index.js.map +1 -1
  14. package/dist/loadSupergraphSdlFromStorage.d.ts +13 -5
  15. package/dist/loadSupergraphSdlFromStorage.d.ts.map +1 -1
  16. package/dist/loadSupergraphSdlFromStorage.js +34 -7
  17. package/dist/loadSupergraphSdlFromStorage.js.map +1 -1
  18. package/dist/outOfBandReporter.d.ts +10 -12
  19. package/dist/outOfBandReporter.d.ts.map +1 -1
  20. package/dist/outOfBandReporter.js +70 -73
  21. package/dist/outOfBandReporter.js.map +1 -1
  22. package/package.json +4 -4
  23. package/src/__mocks__/make-fetch-happen-fetcher.ts +3 -1
  24. package/src/__tests__/executeQueryPlan.test.ts +598 -0
  25. package/src/__tests__/gateway/buildService.test.ts +1 -1
  26. package/src/__tests__/gateway/composedSdl.test.ts +1 -1
  27. package/src/__tests__/gateway/executor.test.ts +1 -1
  28. package/src/__tests__/gateway/reporting.test.ts +8 -5
  29. package/src/__tests__/integration/configuration.test.ts +44 -4
  30. package/src/__tests__/integration/networkRequests.test.ts +21 -19
  31. package/src/__tests__/integration/nockMocks.ts +12 -6
  32. package/src/__tests__/loadSupergraphSdlFromStorage.test.ts +101 -452
  33. package/src/__tests__/nockAssertions.ts +20 -0
  34. package/src/config.ts +3 -1
  35. package/src/datasources/RemoteGraphQLDataSource.ts +8 -2
  36. package/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts +4 -4
  37. package/src/executeQueryPlan.ts +11 -1
  38. package/src/index.ts +26 -12
  39. package/src/loadSupergraphSdlFromStorage.ts +54 -8
  40. package/src/outOfBandReporter.ts +87 -89
@@ -7,7 +7,9 @@ import {
7
7
  mockSdlQuerySuccess,
8
8
  mockSupergraphSdlRequestSuccess,
9
9
  mockApolloConfig,
10
- mockCloudConfigUrl,
10
+ mockCloudConfigUrl1,
11
+ mockCloudConfigUrl2,
12
+ mockCloudConfigUrl3,
11
13
  } from './nockMocks';
12
14
  import { getTestingSupergraphSdl } from '../execution-utils';
13
15
  import { MockService } from './networkRequests.test';
@@ -111,7 +113,26 @@ describe('gateway configuration warnings', () => {
111
113
 
112
114
  gateway = new ApolloGateway({
113
115
  logger,
114
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
116
+ uplinkEndpoints: [mockCloudConfigUrl1],
117
+ });
118
+
119
+ await gateway.load(mockApolloConfig);
120
+
121
+ await gateway.stop();
122
+
123
+ expect(logger.warn).not.toHaveBeenCalledWith(
124
+ expect.stringMatching(
125
+ /A local gateway configuration is overriding a managed federation configuration/,
126
+ ),
127
+ );
128
+ });
129
+
130
+ it('deprecated conflicting configurations are not warned about when absent', async () => {
131
+ mockSupergraphSdlRequestSuccess();
132
+
133
+ gateway = new ApolloGateway({
134
+ logger,
135
+ schemaConfigDeliveryEndpoint: mockCloudConfigUrl1,
115
136
  });
116
137
 
117
138
  await gateway.load(mockApolloConfig);
@@ -301,6 +322,25 @@ describe('gateway config / env behavior', () => {
301
322
  });
302
323
 
303
324
  describe('schema config delivery endpoint configuration', () => {
325
+ it('A code config overrides the env variable', async () => {
326
+ cleanUp = mockedEnv({
327
+ APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT: 'env-config',
328
+ });
329
+
330
+ gateway = new ApolloGateway({
331
+ logger,
332
+ uplinkEndpoints: [mockCloudConfigUrl1, mockCloudConfigUrl2, mockCloudConfigUrl3],
333
+ });
334
+
335
+ expect(gateway['uplinkEndpoints']).toEqual(
336
+ [mockCloudConfigUrl1, mockCloudConfigUrl2, mockCloudConfigUrl3],
337
+ );
338
+
339
+ gateway = null;
340
+ });
341
+ });
342
+
343
+ describe('deprecated schema config delivery endpoint configuration', () => {
304
344
  it('A code config overrides the env variable', async () => {
305
345
  cleanUp = mockedEnv({
306
346
  APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT: 'env-config',
@@ -311,8 +351,8 @@ describe('gateway config / env behavior', () => {
311
351
  schemaConfigDeliveryEndpoint: 'code-config',
312
352
  });
313
353
 
314
- expect(gateway['schemaConfigDeliveryEndpoint']).toEqual(
315
- 'code-config',
354
+ expect(gateway['uplinkEndpoints']).toEqual(
355
+ ['code-config'],
316
356
  );
317
357
 
318
358
  gateway = null;
@@ -1,4 +1,3 @@
1
- import nock from 'nock';
2
1
  import gql from 'graphql-tag';
3
2
  import { DocumentNode, GraphQLObjectType, GraphQLSchema } from 'graphql';
4
3
  import mockedEnv from 'mocked-env';
@@ -12,7 +11,7 @@ import {
12
11
  mockSupergraphSdlRequestSuccess,
13
12
  mockSupergraphSdlRequest,
14
13
  mockApolloConfig,
15
- mockCloudConfigUrl,
14
+ mockCloudConfigUrl1,
16
15
  mockSupergraphSdlRequestIfAfter,
17
16
  mockSupergraphSdlRequestSuccessIfAfter,
18
17
  } from './nockMocks';
@@ -26,6 +25,7 @@ import {
26
25
  reviews,
27
26
  } from 'apollo-federation-integration-testsuite';
28
27
  import { getTestingSupergraphSdl } from '../execution-utils';
28
+ import { nockAfterEach, nockBeforeEach } from '../nockAssertions';
29
29
 
30
30
  type GenericFunction = (...args: unknown[]) => unknown;
31
31
  export interface MockService {
@@ -63,7 +63,7 @@ let gateway: ApolloGateway | null = null;
63
63
  let cleanUp: (() => void) | null = null;
64
64
 
65
65
  beforeEach(() => {
66
- if (!nock.isActive()) nock.activate();
66
+ nockBeforeEach();
67
67
 
68
68
  const warn = jest.fn();
69
69
  const debug = jest.fn();
@@ -79,9 +79,8 @@ beforeEach(() => {
79
79
  });
80
80
 
81
81
  afterEach(async () => {
82
- expect(nock.isDone()).toBeTruthy();
83
- nock.cleanAll();
84
- nock.restore();
82
+ nockAfterEach();
83
+
85
84
  if (gateway) {
86
85
  await gateway.stop();
87
86
  gateway = null;
@@ -106,7 +105,7 @@ it('Fetches Supergraph SDL from remote storage', async () => {
106
105
 
107
106
  gateway = new ApolloGateway({
108
107
  logger,
109
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
108
+ uplinkEndpoints: [mockCloudConfigUrl1],
110
109
  });
111
110
 
112
111
  await gateway.load(mockApolloConfig);
@@ -116,7 +115,7 @@ it('Fetches Supergraph SDL from remote storage', async () => {
116
115
 
117
116
  it('Fetches Supergraph SDL from remote storage using a configured env variable', async () => {
118
117
  cleanUp = mockedEnv({
119
- APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT: mockCloudConfigUrl,
118
+ APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT: mockCloudConfigUrl1,
120
119
  });
121
120
  mockSupergraphSdlRequestSuccess();
122
121
 
@@ -150,7 +149,7 @@ it('Updates Supergraph SDL from remote storage', async () => {
150
149
 
151
150
  gateway = new ApolloGateway({
152
151
  logger,
153
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
152
+ uplinkEndpoints: [mockCloudConfigUrl1],
154
153
  });
155
154
  // eslint-disable-next-line
156
155
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
@@ -170,7 +169,8 @@ describe('Supergraph SDL update failures', () => {
170
169
 
171
170
  gateway = new ApolloGateway({
172
171
  logger,
173
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
172
+ uplinkEndpoints: [mockCloudConfigUrl1],
173
+ uplinkMaxRetries: 0
174
174
  });
175
175
 
176
176
  await expect(
@@ -198,7 +198,8 @@ describe('Supergraph SDL update failures', () => {
198
198
 
199
199
  gateway = new ApolloGateway({
200
200
  logger,
201
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
201
+ uplinkEndpoints: [mockCloudConfigUrl1],
202
+ uplinkMaxRetries: 0
202
203
  });
203
204
 
204
205
  // eslint-disable-next-line
@@ -232,7 +233,8 @@ describe('Supergraph SDL update failures', () => {
232
233
 
233
234
  gateway = new ApolloGateway({
234
235
  logger,
235
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
236
+ uplinkEndpoints: [mockCloudConfigUrl1],
237
+ uplinkMaxRetries: 0
236
238
  });
237
239
  // eslint-disable-next-line
238
240
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
@@ -270,7 +272,7 @@ describe('Supergraph SDL update failures', () => {
270
272
 
271
273
  gateway = new ApolloGateway({
272
274
  logger,
273
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
275
+ uplinkEndpoints: [mockCloudConfigUrl1],
274
276
  });
275
277
  // eslint-disable-next-line
276
278
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
@@ -301,7 +303,7 @@ describe('Supergraph SDL update failures', () => {
301
303
 
302
304
  gateway = new ApolloGateway({
303
305
  logger,
304
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
306
+ uplinkEndpoints: [mockCloudConfigUrl1],
305
307
  });
306
308
  // eslint-disable-next-line
307
309
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
@@ -346,7 +348,7 @@ it('Rollsback to a previous schema when triggered', async () => {
346
348
 
347
349
  gateway = new ApolloGateway({
348
350
  logger,
349
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
351
+ uplinkEndpoints: [mockCloudConfigUrl1],
350
352
  });
351
353
  // eslint-disable-next-line
352
354
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
@@ -432,7 +434,7 @@ describe('Downstream service health checks', () => {
432
434
  gateway = new ApolloGateway({
433
435
  serviceHealthCheck: true,
434
436
  logger,
435
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
437
+ uplinkEndpoints: [mockCloudConfigUrl1],
436
438
  });
437
439
  // eslint-disable-next-line
438
440
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
@@ -456,7 +458,7 @@ describe('Downstream service health checks', () => {
456
458
  gateway = new ApolloGateway({
457
459
  serviceHealthCheck: true,
458
460
  logger,
459
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
461
+ uplinkEndpoints: [mockCloudConfigUrl1],
460
462
  });
461
463
 
462
464
  // This is the ideal, but our version of Jest has a bug with printing error snapshots.
@@ -517,7 +519,7 @@ describe('Downstream service health checks', () => {
517
519
  gateway = new ApolloGateway({
518
520
  serviceHealthCheck: true,
519
521
  logger,
520
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
522
+ uplinkEndpoints: [mockCloudConfigUrl1],
521
523
  });
522
524
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
523
525
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
@@ -561,7 +563,7 @@ describe('Downstream service health checks', () => {
561
563
  gateway = new ApolloGateway({
562
564
  serviceHealthCheck: true,
563
565
  logger,
564
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
566
+ uplinkEndpoints: [mockCloudConfigUrl1],
565
567
  });
566
568
  // eslint-disable-next-line
567
569
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
@@ -64,14 +64,20 @@ function gatewayNock(url: Parameters<typeof nock>[0]): nock.Scope {
64
64
  });
65
65
  }
66
66
 
67
- export const mockCloudConfigUrl =
68
- 'https://example.cloud-config-url.com/cloudconfig/';
67
+ export const mockCloudConfigUrl1 =
68
+ 'https://example1.cloud-config-url.com/cloudconfig/';
69
+
70
+ export const mockCloudConfigUrl2 =
71
+ 'https://example2.cloud-config-url.com/cloudconfig/';
72
+
73
+ export const mockCloudConfigUrl3 =
74
+ 'https://example3.cloud-config-url.com/cloudconfig/';
69
75
 
70
76
  export const mockOutOfBandReporterUrl =
71
77
  'https://example.outofbandreporter.com/monitoring/';
72
78
 
73
- export function mockSupergraphSdlRequestIfAfter(ifAfter: string | null) {
74
- return gatewayNock(mockCloudConfigUrl).post('/', {
79
+ export function mockSupergraphSdlRequestIfAfter(ifAfter: string | null, url: string = mockCloudConfigUrl1) {
80
+ return gatewayNock(url).post('/', {
75
81
  query: SUPERGRAPH_SDL_QUERY,
76
82
  variables: {
77
83
  ref: graphRef,
@@ -81,8 +87,8 @@ export function mockSupergraphSdlRequestIfAfter(ifAfter: string | null) {
81
87
  });
82
88
  }
83
89
 
84
- export function mockSupergraphSdlRequest(ifAfter: string | null = null) {
85
- return mockSupergraphSdlRequestIfAfter(ifAfter);
90
+ export function mockSupergraphSdlRequest(ifAfter: string | null = null, url: string = mockCloudConfigUrl1) {
91
+ return mockSupergraphSdlRequestIfAfter(ifAfter, url);
86
92
  }
87
93
 
88
94
  export function mockSupergraphSdlRequestSuccessIfAfter(