@apollo/gateway 0.44.1 → 0.45.0-alpha.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +10 -3
  2. package/dist/__generated__/graphqlTypes.d.ts +13 -12
  3. package/dist/__generated__/graphqlTypes.d.ts.map +1 -1
  4. package/dist/__generated__/graphqlTypes.js.map +1 -1
  5. package/dist/config.d.ts +3 -8
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js +6 -17
  8. package/dist/config.js.map +1 -1
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +30 -37
  12. package/dist/index.js.map +1 -1
  13. package/dist/loadSupergraphSdlFromStorage.d.ts +13 -5
  14. package/dist/loadSupergraphSdlFromStorage.d.ts.map +1 -1
  15. package/dist/loadSupergraphSdlFromStorage.js +34 -7
  16. package/dist/loadSupergraphSdlFromStorage.js.map +1 -1
  17. package/dist/outOfBandReporter.d.ts +10 -12
  18. package/dist/outOfBandReporter.d.ts.map +1 -1
  19. package/dist/outOfBandReporter.js +70 -73
  20. package/dist/outOfBandReporter.js.map +1 -1
  21. package/package.json +4 -4
  22. package/src/__generated__/graphqlTypes.ts +13 -12
  23. package/src/__tests__/gateway/reporting.test.ts +5 -3
  24. package/src/__tests__/integration/configuration.test.ts +32 -11
  25. package/src/__tests__/integration/networkRequests.test.ts +22 -22
  26. package/src/__tests__/integration/nockMocks.ts +12 -6
  27. package/src/__tests__/loadSupergraphSdlFromStorage.test.ts +101 -377
  28. package/src/__tests__/nockAssertions.ts +20 -0
  29. package/src/config.ts +10 -43
  30. package/src/index.ts +36 -56
  31. package/src/loadSupergraphSdlFromStorage.ts +54 -8
  32. package/src/outOfBandReporter.ts +87 -89
  33. package/dist/legacyLoadServicesFromStorage.d.ts +0 -20
  34. package/dist/legacyLoadServicesFromStorage.d.ts.map +0 -1
  35. package/dist/legacyLoadServicesFromStorage.js +0 -62
  36. package/dist/legacyLoadServicesFromStorage.js.map +0 -1
  37. package/src/__tests__/integration/legacyNetworkRequests.test.ts +0 -279
  38. package/src/__tests__/integration/legacyNockMocks.ts +0 -113
  39. package/src/legacyLoadServicesFromStorage.ts +0 -170
@@ -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
  export interface MockService {
31
31
  name: string;
@@ -62,7 +62,7 @@ let gateway: ApolloGateway | null = null;
62
62
  let cleanUp: (() => void) | null = null;
63
63
 
64
64
  beforeEach(() => {
65
- if (!nock.isActive()) nock.activate();
65
+ nockBeforeEach();
66
66
 
67
67
  const warn = jest.fn();
68
68
  const debug = jest.fn();
@@ -78,9 +78,8 @@ beforeEach(() => {
78
78
  });
79
79
 
80
80
  afterEach(async () => {
81
- expect(nock.isDone()).toBeTruthy();
82
- nock.cleanAll();
83
- nock.restore();
81
+ nockAfterEach();
82
+
84
83
  if (gateway) {
85
84
  await gateway.stop();
86
85
  gateway = null;
@@ -100,13 +99,12 @@ it('Queries remote endpoints for their SDLs', async () => {
100
99
  expect(gateway.schema!.getType('User')!.description).toBe('This is my User');
101
100
  });
102
101
 
103
- // TODO(trevor:cloudconfig): Remove all usages of the experimental config option
104
102
  it('Fetches Supergraph SDL from remote storage', async () => {
105
103
  mockSupergraphSdlRequestSuccess();
106
104
 
107
105
  gateway = new ApolloGateway({
108
106
  logger,
109
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
107
+ uplinkEndpoints: [mockCloudConfigUrl1],
110
108
  });
111
109
 
112
110
  await gateway.load(mockApolloConfig);
@@ -114,10 +112,9 @@ it('Fetches Supergraph SDL from remote storage', async () => {
114
112
  expect(gateway.schema?.getType('User')).toBeTruthy();
115
113
  });
116
114
 
117
- // TODO(trevor:cloudconfig): This test should evolve to demonstrate overriding the default in the future
118
115
  it('Fetches Supergraph SDL from remote storage using a configured env variable', async () => {
119
116
  cleanUp = mockedEnv({
120
- APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT: mockCloudConfigUrl,
117
+ APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT: mockCloudConfigUrl1,
121
118
  });
122
119
  mockSupergraphSdlRequestSuccess();
123
120
 
@@ -151,11 +148,11 @@ it('Updates Supergraph SDL from remote storage', async () => {
151
148
 
152
149
  gateway = new ApolloGateway({
153
150
  logger,
154
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
151
+ uplinkEndpoints: [mockCloudConfigUrl1],
155
152
  });
156
153
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
157
154
  gateway.experimental_pollInterval = 100;
158
- gateway.onSchemaChange(schemaChangeCallback);
155
+ gateway.onSchemaLoadOrUpdate(schemaChangeCallback);
159
156
 
160
157
  await gateway.load(mockApolloConfig);
161
158
  expect(gateway['compositionId']).toMatchInlineSnapshot(`"originalId-1234"`);
@@ -170,7 +167,8 @@ describe('Supergraph SDL update failures', () => {
170
167
 
171
168
  gateway = new ApolloGateway({
172
169
  logger,
173
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
170
+ uplinkEndpoints: [mockCloudConfigUrl1],
171
+ uplinkMaxRetries: 0
174
172
  });
175
173
 
176
174
  await expect(
@@ -198,7 +196,8 @@ describe('Supergraph SDL update failures', () => {
198
196
 
199
197
  gateway = new ApolloGateway({
200
198
  logger,
201
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
199
+ uplinkEndpoints: [mockCloudConfigUrl1],
200
+ uplinkMaxRetries: 0
202
201
  });
203
202
 
204
203
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
@@ -231,7 +230,8 @@ describe('Supergraph SDL update failures', () => {
231
230
 
232
231
  gateway = new ApolloGateway({
233
232
  logger,
234
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
233
+ uplinkEndpoints: [mockCloudConfigUrl1],
234
+ uplinkMaxRetries: 0
235
235
  });
236
236
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
237
237
  gateway.experimental_pollInterval = 100;
@@ -268,7 +268,7 @@ describe('Supergraph SDL update failures', () => {
268
268
 
269
269
  gateway = new ApolloGateway({
270
270
  logger,
271
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
271
+ uplinkEndpoints: [mockCloudConfigUrl1],
272
272
  });
273
273
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
274
274
  gateway.experimental_pollInterval = 100;
@@ -298,7 +298,7 @@ describe('Supergraph SDL update failures', () => {
298
298
 
299
299
  gateway = new ApolloGateway({
300
300
  logger,
301
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
301
+ uplinkEndpoints: [mockCloudConfigUrl1],
302
302
  });
303
303
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
304
304
  gateway.experimental_pollInterval = 100;
@@ -342,7 +342,7 @@ it('Rollsback to a previous schema when triggered', async () => {
342
342
 
343
343
  gateway = new ApolloGateway({
344
344
  logger,
345
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
345
+ uplinkEndpoints: [mockCloudConfigUrl1],
346
346
  });
347
347
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
348
348
  gateway.experimental_pollInterval = 100;
@@ -426,7 +426,7 @@ describe('Downstream service health checks', () => {
426
426
  gateway = new ApolloGateway({
427
427
  serviceHealthCheck: true,
428
428
  logger,
429
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
429
+ uplinkEndpoints: [mockCloudConfigUrl1],
430
430
  });
431
431
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
432
432
  gateway.experimental_pollInterval = 100;
@@ -449,7 +449,7 @@ describe('Downstream service health checks', () => {
449
449
  gateway = new ApolloGateway({
450
450
  serviceHealthCheck: true,
451
451
  logger,
452
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
452
+ uplinkEndpoints: [mockCloudConfigUrl1],
453
453
  });
454
454
 
455
455
  // This is the ideal, but our version of Jest has a bug with printing error snapshots.
@@ -509,7 +509,7 @@ describe('Downstream service health checks', () => {
509
509
  gateway = new ApolloGateway({
510
510
  serviceHealthCheck: true,
511
511
  logger,
512
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
512
+ uplinkEndpoints: [mockCloudConfigUrl1],
513
513
  });
514
514
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
515
515
  gateway.experimental_pollInterval = 100;
@@ -552,7 +552,7 @@ describe('Downstream service health checks', () => {
552
552
  gateway = new ApolloGateway({
553
553
  serviceHealthCheck: true,
554
554
  logger,
555
- schemaConfigDeliveryEndpoint: mockCloudConfigUrl,
555
+ uplinkEndpoints: [mockCloudConfigUrl1],
556
556
  });
557
557
  // @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
558
558
  gateway.experimental_pollInterval = 100;
@@ -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(