@apollo/gateway 2.0.2-alpha.0 → 2.0.2
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 +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/datasources/RemoteGraphQLDataSource.d.ts +6 -5
- package/dist/datasources/RemoteGraphQLDataSource.d.ts.map +1 -1
- package/dist/datasources/RemoteGraphQLDataSource.js +16 -11
- package/dist/datasources/RemoteGraphQLDataSource.js.map +1 -1
- package/dist/executeQueryPlan.d.ts.map +1 -1
- package/dist/executeQueryPlan.js +2 -2
- package/dist/executeQueryPlan.js.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -22
- package/dist/index.js.map +1 -1
- package/dist/supergraphManagers/UplinkFetcher/index.d.ts +2 -2
- package/dist/supergraphManagers/UplinkFetcher/index.d.ts.map +1 -1
- package/dist/supergraphManagers/UplinkFetcher/index.js.map +1 -1
- package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.d.ts +3 -3
- package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.d.ts.map +1 -1
- package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.js +14 -13
- package/dist/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.js.map +1 -1
- package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.d.ts +6 -5
- package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.d.ts.map +1 -1
- package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.js +3 -3
- package/dist/supergraphManagers/UplinkFetcher/outOfBandReporter.js.map +1 -1
- package/package.json +7 -7
- package/src/__tests__/gateway/buildService.test.ts +81 -83
- package/src/__tests__/gateway/executor.test.ts +20 -17
- package/src/__tests__/gateway/opentelemetry.test.ts +3 -7
- package/src/__tests__/gateway/supergraphSdl.test.ts +6 -11
- package/src/config.ts +2 -2
- package/src/datasources/RemoteGraphQLDataSource.ts +32 -16
- package/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts +106 -140
- package/src/executeQueryPlan.ts +5 -1
- package/src/index.ts +3 -28
- package/src/supergraphManagers/IntrospectAndCompose/__tests__/IntrospectAndCompose.test.ts +0 -6
- package/src/supergraphManagers/UplinkFetcher/__tests__/loadSupergraphSdlFromStorage.test.ts +70 -74
- package/src/supergraphManagers/UplinkFetcher/index.ts +2 -2
- package/src/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.ts +23 -17
- package/src/supergraphManagers/UplinkFetcher/outOfBandReporter.ts +9 -7
- package/dist/cache.d.ts +0 -18
- package/dist/cache.d.ts.map +0 -1
- package/dist/cache.js +0 -46
- package/dist/cache.js.map +0 -1
- package/src/__mocks__/apollo-server-env.ts +0 -56
- package/src/__mocks__/make-fetch-happen-fetcher.ts +0 -57
- package/src/cache.ts +0 -66
- package/src/make-fetch-happen.d.ts +0 -59
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadSupergraphSdlFromStorage.js","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"loadSupergraphSdlFromStorage.js","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/loadSupergraphSdlFromStorage.ts"],"names":[],"mappings":";;;;;;AACA,8DAAgC;AAEhC,2DAAwE;AAS3D,QAAA,oBAAoB,GAAgB;;;;;;;;;;;;;;;CAehD,CAAC;AAgBF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAE3D,MAAM,aAAa,GAAG,4DAA4D,CAAC;AAEnF,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,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,IAAA,qDAAiC,EAAC;YACtC,KAAK,EAAE,IAAI,kBAAkB,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC;YACtF,eAAe,EAAE,QAAQ;YACzB,WAAW;YACX,QAAQ,EAAE,sBAAsB;YAChC,QAAQ,EAAE,MAAM;YAChB,SAAS,EAAE,SAAS;YACpB,OAAO,EAAE,OAAO;YAChB,OAAO;SACR,CAAC,CAAC;QACH,MAAM,IAAI,kBAAkB,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;KACvF;IAED,MAAM,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC;IACvC,IAAI,YAAY,CAAC,UAAU,KAAK,oBAAoB,EAAE;QACpD,MAAM,EACJ,EAAE,EACF,aAAa,EACb,eAAe,GAEhB,GAAG,YAAY,CAAC;QACjB,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,aAAc,EAAE,eAAe,EAAE,CAAC;KAC/D;SAAM,IAAI,YAAY,CAAC,UAAU,KAAK,YAAY,EAAE;QAEnD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC;QACvC,MAAM,IAAI,kBAAkB,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;KACrD;SAAM,IAAI,YAAY,CAAC,UAAU,KAAK,WAAW,EAAE;QAClD,OAAO,IAAI,CAAC;KACb;SAAM;QACL,MAAM,IAAI,kBAAkB,CAAC,+CAA+C,CAAC,CAAC;KAC/E;AACH,CAAC;AAzGD,oEAyGC"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fetcher, FetcherResponse } from '@apollo/utils.fetcher';
|
|
2
2
|
export declare const OUT_OF_BAND_REPORTER_QUERY = "#graphql\n mutation OOBReport($input: APIMonitoringReport) {\n reportError(report: $input)\n }\n";
|
|
3
|
-
export declare function submitOutOfBandReportIfConfigured({ error,
|
|
3
|
+
export declare function submitOutOfBandReportIfConfigured({ error, requestEndpoint, requestBody, endpoint, response, startedAt, endedAt, tags, fetcher, }: {
|
|
4
4
|
error: Error;
|
|
5
|
-
|
|
5
|
+
requestEndpoint: string;
|
|
6
|
+
requestBody: string;
|
|
6
7
|
endpoint: string | undefined;
|
|
7
|
-
response?:
|
|
8
|
+
response?: FetcherResponse;
|
|
8
9
|
startedAt: Date;
|
|
9
10
|
endedAt: Date;
|
|
10
11
|
tags?: string[];
|
|
11
|
-
fetcher:
|
|
12
|
+
fetcher: Fetcher;
|
|
12
13
|
}): Promise<void>;
|
|
13
14
|
//# sourceMappingURL=outOfBandReporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outOfBandReporter.d.ts","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/outOfBandReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"outOfBandReporter.d.ts","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/outOfBandReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AASjE,eAAO,MAAM,0BAA0B,0GAItC,CAAC;AAiBF,wBAAsB,iCAAiC,CAAC,EACtD,KAAK,EACL,eAAe,EACf,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAO,GACR,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,iBA6EA"}
|
|
@@ -8,7 +8,7 @@ exports.OUT_OF_BAND_REPORTER_QUERY = `#graphql
|
|
|
8
8
|
}
|
|
9
9
|
`;
|
|
10
10
|
const { name, version } = require('../../../package.json');
|
|
11
|
-
async function submitOutOfBandReportIfConfigured({ error,
|
|
11
|
+
async function submitOutOfBandReportIfConfigured({ error, requestEndpoint, requestBody, endpoint, response, startedAt, endedAt, tags, fetcher, }) {
|
|
12
12
|
var _a, _b;
|
|
13
13
|
if (!endpoint) {
|
|
14
14
|
return;
|
|
@@ -44,8 +44,8 @@ async function submitOutOfBandReportIfConfigured({ error, request, endpoint, res
|
|
|
44
44
|
message: error.message,
|
|
45
45
|
},
|
|
46
46
|
request: {
|
|
47
|
-
url:
|
|
48
|
-
body:
|
|
47
|
+
url: requestEndpoint,
|
|
48
|
+
body: requestBody,
|
|
49
49
|
},
|
|
50
50
|
response: response
|
|
51
51
|
? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outOfBandReporter.js","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/outOfBandReporter.ts"],"names":[],"mappings":";;;AAEA,mEAI0C;AAG7B,QAAA,0BAA0B,GAAgB;;;;CAItD,CAAC;AAEF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAepD,KAAK,UAAU,iCAAiC,CAAC,EACtD,KAAK,EACL,
|
|
1
|
+
{"version":3,"file":"outOfBandReporter.js","sourceRoot":"","sources":["../../../src/supergraphManagers/UplinkFetcher/outOfBandReporter.ts"],"names":[],"mappings":";;;AAEA,mEAI0C;AAG7B,QAAA,0BAA0B,GAAgB;;;;CAItD,CAAC;AAEF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAepD,KAAK,UAAU,iCAAiC,CAAC,EACtD,KAAK,E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AC;IAEF,IAAI;QACF,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE;YAC1C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,KAAK,EAAE,kCAA0B;gBACjC,SAAS;aACV,CAAC;YACF,OAAO,EAAE;gBACP,2BAA2B,EAAE,IAAI;gBACjC,8BAA8B,EAAE,OAAO;gBACvC,YAAY,EAAE,GAAG,IAAI,IAAI,OAAO,EAAE;gBAClC,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC,CAAC;QACH,MAAM,cAAc,GAA4B,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;QACzE,IAAI,CAAC,CAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,0CAAE,WAAW,CAAA,EAAE;YACtC,MAAM,IAAI,KAAK,CACb,uCAAuC,WAAW,CAAC,MAAM,IAAI,WAAW,CAAC,UAAU,EAAE,CACtF,CAAC;SACH;KACF;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,uCAAuC,MAAA,CAAC,CAAC,OAAO,mCAAI,CAAC,EAAE,CAAC,CAAC;KAC1E;AACH,CAAC;AAjGD,8EAiGC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apollo/gateway",
|
|
3
|
-
"version": "2.0.2
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Apollo Gateway",
|
|
5
5
|
"author": "Apollo <packages@apollographql.com>",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@apollo/composition": "^2.0.2
|
|
28
|
+
"@apollo/composition": "^2.0.2",
|
|
29
29
|
"@apollo/core-schema": "~0.3.0",
|
|
30
|
-
"@apollo/federation-internals": "^2.0.2
|
|
31
|
-
"@apollo/query-planner": "^2.0.2
|
|
30
|
+
"@apollo/federation-internals": "^2.0.2",
|
|
31
|
+
"@apollo/query-planner": "^2.0.2",
|
|
32
32
|
"@apollo/utils.createhash": "^1.0.0",
|
|
33
|
+
"@apollo/utils.fetcher": "^1.0.0",
|
|
33
34
|
"@apollo/utils.isnodelike": "^1.0.0",
|
|
34
35
|
"@apollo/utils.logger": "^1.0.0",
|
|
35
36
|
"@josephg/resolvable": "^1.0.1",
|
|
@@ -38,16 +39,15 @@
|
|
|
38
39
|
"apollo-reporting-protobuf": "^0.8.0 || ^3.0.0",
|
|
39
40
|
"apollo-server-caching": "^0.7.0 || ^3.0.0",
|
|
40
41
|
"apollo-server-core": "^2.23.0 || ^3.0.0",
|
|
41
|
-
"apollo-server-env": "^3.0.0 || ^4.0.0",
|
|
42
42
|
"apollo-server-errors": "^2.5.0 || ^3.0.0",
|
|
43
43
|
"apollo-server-types": "^0.9.0 || ^3.0.0",
|
|
44
44
|
"async-retry": "^1.3.3",
|
|
45
45
|
"loglevel": "^1.6.1",
|
|
46
|
-
"make-fetch-happen": "^
|
|
46
|
+
"make-fetch-happen": "^10.1.2",
|
|
47
47
|
"pretty-format": "^27.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"graphql": "^16.0.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "02bd93d0ed4f75f9cd59b84ddcb66a30babb1553"
|
|
53
53
|
}
|
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import nock from 'nock';
|
|
2
|
+
|
|
2
3
|
import { ApolloServerBase as ApolloServer } from 'apollo-server-core';
|
|
3
4
|
|
|
4
5
|
import { RemoteGraphQLDataSource } from '../../datasources/RemoteGraphQLDataSource';
|
|
5
6
|
import { ApolloGateway, SERVICE_DEFINITION_QUERY } from '../../';
|
|
6
7
|
import { fixtures } from 'apollo-federation-integration-testsuite';
|
|
7
8
|
import { GraphQLDataSourceRequestKind } from '../../datasources/types';
|
|
9
|
+
import { nockAfterEach, nockBeforeEach } from '../nockAssertions';
|
|
8
10
|
|
|
9
|
-
beforeEach(
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
beforeEach(nockBeforeEach);
|
|
12
|
+
afterEach(nockAfterEach);
|
|
13
|
+
|
|
14
|
+
const replyHeaders = {
|
|
15
|
+
'content-type': 'application/json',
|
|
16
|
+
};
|
|
12
17
|
|
|
13
18
|
it('calls buildService only once per service', async () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
nock('https://api.example.com')
|
|
20
|
+
.post('/foo')
|
|
21
|
+
.reply(
|
|
22
|
+
200,
|
|
23
|
+
{
|
|
24
|
+
data: { _service: { sdl: `extend type Query { thing: String }` } },
|
|
25
|
+
},
|
|
26
|
+
replyHeaders,
|
|
27
|
+
);
|
|
17
28
|
|
|
18
29
|
const buildServiceSpy = jest.fn(() => {
|
|
19
30
|
return new RemoteGraphQLDataSource({
|
|
@@ -23,7 +34,7 @@ it('calls buildService only once per service', async () => {
|
|
|
23
34
|
|
|
24
35
|
const gateway = new ApolloGateway({
|
|
25
36
|
serviceList: [{ name: 'foo', url: 'https://api.example.com/foo' }],
|
|
26
|
-
buildService: buildServiceSpy
|
|
37
|
+
buildService: buildServiceSpy,
|
|
27
38
|
});
|
|
28
39
|
|
|
29
40
|
await gateway.load();
|
|
@@ -34,11 +45,13 @@ it('calls buildService only once per service', async () => {
|
|
|
34
45
|
it('correctly passes the context from ApolloServer to datasources', async () => {
|
|
35
46
|
const gateway = new ApolloGateway({
|
|
36
47
|
localServiceList: fixtures,
|
|
37
|
-
buildService: _service => {
|
|
48
|
+
buildService: (_service) => {
|
|
38
49
|
return new RemoteGraphQLDataSource({
|
|
39
50
|
url: 'https://api.example.com/foo',
|
|
40
51
|
willSendRequest: (options) => {
|
|
41
|
-
if (
|
|
52
|
+
if (
|
|
53
|
+
options.kind === GraphQLDataSourceRequestKind.INCOMING_OPERATION
|
|
54
|
+
) {
|
|
42
55
|
options.request.http?.headers.set(
|
|
43
56
|
'x-user-id',
|
|
44
57
|
options.context.userId,
|
|
@@ -67,7 +80,22 @@ it('correctly passes the context from ApolloServer to datasources', async () =>
|
|
|
67
80
|
}
|
|
68
81
|
`;
|
|
69
82
|
|
|
70
|
-
|
|
83
|
+
nock('https://api.example.com', {
|
|
84
|
+
reqheaders: {
|
|
85
|
+
'x-user-id': '1234',
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
.post('/foo', {
|
|
89
|
+
query: `{me{username}}`,
|
|
90
|
+
variables: {},
|
|
91
|
+
})
|
|
92
|
+
.reply(
|
|
93
|
+
200,
|
|
94
|
+
{
|
|
95
|
+
data: { me: { username: '@jbaxleyiii' } },
|
|
96
|
+
},
|
|
97
|
+
replyHeaders,
|
|
98
|
+
);
|
|
71
99
|
|
|
72
100
|
const result = await server.executeOperation({
|
|
73
101
|
query,
|
|
@@ -77,33 +105,32 @@ it('correctly passes the context from ApolloServer to datasources', async () =>
|
|
|
77
105
|
expect(result.data).toEqual({
|
|
78
106
|
me: { username: '@jbaxleyiii' },
|
|
79
107
|
});
|
|
80
|
-
|
|
81
|
-
expect(fetch).toBeCalledTimes(1);
|
|
82
|
-
expect(fetch).toHaveFetched('https://api.example.com/foo', {
|
|
83
|
-
body: {
|
|
84
|
-
query: `{me{username}}`,
|
|
85
|
-
variables: {},
|
|
86
|
-
},
|
|
87
|
-
headers: {
|
|
88
|
-
'x-user-id': '1234',
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
108
|
});
|
|
92
109
|
|
|
93
|
-
function createSdlData(sdl: string):
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
function createSdlData(sdl: string): [number, any, Record<string, string>] {
|
|
111
|
+
return [
|
|
112
|
+
200,
|
|
113
|
+
{
|
|
114
|
+
data: {
|
|
115
|
+
_service: {
|
|
116
|
+
sdl: sdl,
|
|
117
|
+
},
|
|
98
118
|
},
|
|
99
119
|
},
|
|
100
|
-
|
|
120
|
+
replyHeaders,
|
|
121
|
+
];
|
|
101
122
|
}
|
|
102
123
|
|
|
103
124
|
it('makes enhanced introspection request using datasource', async () => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
125
|
+
nock('https://api.example.com', {
|
|
126
|
+
reqheaders: {
|
|
127
|
+
'custom-header': 'some-custom-value',
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
.post('/override', {
|
|
131
|
+
query: SERVICE_DEFINITION_QUERY,
|
|
132
|
+
})
|
|
133
|
+
.reply(...createSdlData('extend type Query { one: String }'));
|
|
107
134
|
|
|
108
135
|
const gateway = new ApolloGateway({
|
|
109
136
|
serviceList: [
|
|
@@ -112,7 +139,7 @@ it('makes enhanced introspection request using datasource', async () => {
|
|
|
112
139
|
url: 'https://api.example.com/one',
|
|
113
140
|
},
|
|
114
141
|
],
|
|
115
|
-
buildService: _service => {
|
|
142
|
+
buildService: (_service) => {
|
|
116
143
|
return new RemoteGraphQLDataSource({
|
|
117
144
|
url: 'https://api.example.com/override',
|
|
118
145
|
willSendRequest: ({ request }) => {
|
|
@@ -123,24 +150,20 @@ it('makes enhanced introspection request using datasource', async () => {
|
|
|
123
150
|
});
|
|
124
151
|
|
|
125
152
|
await gateway.load();
|
|
126
|
-
|
|
127
|
-
expect(fetch).toBeCalledTimes(1);
|
|
128
|
-
|
|
129
|
-
expect(fetch).toHaveFetched('https://api.example.com/override', {
|
|
130
|
-
body: {
|
|
131
|
-
query: SERVICE_DEFINITION_QUERY,
|
|
132
|
-
},
|
|
133
|
-
headers: {
|
|
134
|
-
'custom-header': 'some-custom-value',
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
153
|
});
|
|
138
154
|
|
|
139
155
|
it('customizes request on a per-service basis', async () => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
156
|
+
for (const subgraph of ['one', 'two', 'three']) {
|
|
157
|
+
nock('https://api.example.com', {
|
|
158
|
+
reqheaders: {
|
|
159
|
+
'service-name': subgraph,
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
.post(`/${subgraph}`, {
|
|
163
|
+
query: SERVICE_DEFINITION_QUERY,
|
|
164
|
+
})
|
|
165
|
+
.reply(...createSdlData(`extend type Query { ${subgraph}: String }`));
|
|
166
|
+
}
|
|
144
167
|
|
|
145
168
|
const gateway = new ApolloGateway({
|
|
146
169
|
serviceList: [
|
|
@@ -157,7 +180,7 @@ it('customizes request on a per-service basis', async () => {
|
|
|
157
180
|
url: 'https://api.example.com/three',
|
|
158
181
|
},
|
|
159
182
|
],
|
|
160
|
-
buildService: service => {
|
|
183
|
+
buildService: (service) => {
|
|
161
184
|
return new RemoteGraphQLDataSource({
|
|
162
185
|
url: service.url,
|
|
163
186
|
willSendRequest: ({ request }) => {
|
|
@@ -168,35 +191,6 @@ it('customizes request on a per-service basis', async () => {
|
|
|
168
191
|
});
|
|
169
192
|
|
|
170
193
|
await gateway.load();
|
|
171
|
-
|
|
172
|
-
expect(fetch).toBeCalledTimes(3);
|
|
173
|
-
|
|
174
|
-
expect(fetch).toHaveFetched('https://api.example.com/one', {
|
|
175
|
-
body: {
|
|
176
|
-
query: `query __ApolloGetServiceDefinition__ { _service { sdl } }`,
|
|
177
|
-
},
|
|
178
|
-
headers: {
|
|
179
|
-
'service-name': 'one',
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
expect(fetch).toHaveFetched('https://api.example.com/two', {
|
|
184
|
-
body: {
|
|
185
|
-
query: `query __ApolloGetServiceDefinition__ { _service { sdl } }`,
|
|
186
|
-
},
|
|
187
|
-
headers: {
|
|
188
|
-
'service-name': 'two',
|
|
189
|
-
},
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
expect(fetch).toHaveFetched('https://api.example.com/three', {
|
|
193
|
-
body: {
|
|
194
|
-
query: `query __ApolloGetServiceDefinition__ { _service { sdl } }`,
|
|
195
|
-
},
|
|
196
|
-
headers: {
|
|
197
|
-
'service-name': 'three',
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
194
|
});
|
|
201
195
|
|
|
202
196
|
it('does not share service definition cache between gateways', async () => {
|
|
@@ -205,11 +199,17 @@ it('does not share service definition cache between gateways', async () => {
|
|
|
205
199
|
updates += 1;
|
|
206
200
|
};
|
|
207
201
|
|
|
202
|
+
function nockSDLFetchOnce() {
|
|
203
|
+
nock('https://api.example.com')
|
|
204
|
+
.post('/repeat', {
|
|
205
|
+
query: SERVICE_DEFINITION_QUERY,
|
|
206
|
+
})
|
|
207
|
+
.reply(...createSdlData('extend type Query { repeat: String }'));
|
|
208
|
+
}
|
|
209
|
+
|
|
208
210
|
// Initialize first gateway
|
|
209
211
|
{
|
|
210
|
-
|
|
211
|
-
createSdlData('extend type Query { repeat: String }'),
|
|
212
|
-
);
|
|
212
|
+
nockSDLFetchOnce();
|
|
213
213
|
|
|
214
214
|
const gateway = new ApolloGateway({
|
|
215
215
|
serviceList: [
|
|
@@ -226,9 +226,7 @@ it('does not share service definition cache between gateways', async () => {
|
|
|
226
226
|
|
|
227
227
|
// Initialize second gateway
|
|
228
228
|
{
|
|
229
|
-
|
|
230
|
-
createSdlData('extend type Query { repeat: String }'),
|
|
231
|
-
);
|
|
229
|
+
nockSDLFetchOnce();
|
|
232
230
|
|
|
233
231
|
const gateway = new ApolloGateway({
|
|
234
232
|
serviceList: [
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import nock from 'nock';
|
|
2
2
|
import gql from 'graphql-tag';
|
|
3
3
|
import { ApolloGateway } from '../../';
|
|
4
|
-
import { fixtures } from 'apollo-federation-integration-testsuite';
|
|
4
|
+
import { accounts, fixtures } from 'apollo-federation-integration-testsuite';
|
|
5
5
|
import type { Logger } from '@apollo/utils.logger';
|
|
6
|
+
import { nockAfterEach, nockBeforeEach } from '../nockAssertions';
|
|
6
7
|
|
|
7
8
|
let logger: {
|
|
8
|
-
warn: jest.MockedFunction<Logger['warn']
|
|
9
|
-
debug: jest.MockedFunction<Logger['debug']
|
|
10
|
-
error: jest.MockedFunction<Logger['error']
|
|
11
|
-
info: jest.MockedFunction<Logger['info']
|
|
12
|
-
}
|
|
9
|
+
warn: jest.MockedFunction<Logger['warn']>;
|
|
10
|
+
debug: jest.MockedFunction<Logger['debug']>;
|
|
11
|
+
error: jest.MockedFunction<Logger['error']>;
|
|
12
|
+
info: jest.MockedFunction<Logger['info']>;
|
|
13
|
+
};
|
|
13
14
|
|
|
14
|
-
beforeEach(
|
|
15
|
-
|
|
15
|
+
beforeEach(nockBeforeEach);
|
|
16
|
+
afterEach(nockAfterEach);
|
|
16
17
|
|
|
18
|
+
beforeEach(() => {
|
|
17
19
|
logger = {
|
|
18
20
|
warn: jest.fn(),
|
|
19
21
|
debug: jest.fn(),
|
|
@@ -38,8 +40,8 @@ describe('ApolloGateway executor', () => {
|
|
|
38
40
|
}
|
|
39
41
|
`;
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
44
|
+
// @ts-ignore
|
|
43
45
|
const { errors } = await executor({
|
|
44
46
|
source,
|
|
45
47
|
document: gql(source),
|
|
@@ -58,8 +60,10 @@ describe('ApolloGateway executor', () => {
|
|
|
58
60
|
});
|
|
59
61
|
|
|
60
62
|
it('should not crash if variables are not provided', async () => {
|
|
61
|
-
const me = { birthDate: '1988-10-21'};
|
|
62
|
-
|
|
63
|
+
const me = { birthDate: '1988-10-21' };
|
|
64
|
+
|
|
65
|
+
nock(accounts.url).post('/').reply(200, { data: { me } });
|
|
66
|
+
|
|
63
67
|
const gateway = new ApolloGateway({
|
|
64
68
|
localServiceList: fixtures,
|
|
65
69
|
});
|
|
@@ -74,13 +78,12 @@ describe('ApolloGateway executor', () => {
|
|
|
74
78
|
}
|
|
75
79
|
`;
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
82
|
+
// @ts-ignore
|
|
79
83
|
const { errors, data } = await executor({
|
|
80
84
|
source,
|
|
81
85
|
document: gql(source),
|
|
82
|
-
request: {
|
|
83
|
-
},
|
|
86
|
+
request: {},
|
|
84
87
|
queryHash: 'hashed',
|
|
85
88
|
context: null,
|
|
86
89
|
cache: {} as any,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import gql from 'graphql-tag';
|
|
2
2
|
import {ApolloGateway, LocalGraphQLDataSource} from '../../';
|
|
3
3
|
import {fixtures, spanSerializer} from 'apollo-federation-integration-testsuite';
|
|
4
|
-
import {fetch} from '../../__mocks__/apollo-server-env';
|
|
5
4
|
import {InMemorySpanExporter, SimpleSpanProcessor} from '@opentelemetry/tracing'
|
|
6
5
|
import {NodeTracerProvider} from '@opentelemetry/node';
|
|
7
6
|
import { buildSubgraphSchema } from '@apollo/subgraph';
|
|
@@ -14,7 +13,6 @@ tracerProvider.addSpanProcessor(new SimpleSpanProcessor(inMemorySpans));
|
|
|
14
13
|
tracerProvider.register();
|
|
15
14
|
|
|
16
15
|
beforeEach(() => {
|
|
17
|
-
fetch.mockReset();
|
|
18
16
|
inMemorySpans.reset();
|
|
19
17
|
});
|
|
20
18
|
|
|
@@ -102,13 +100,11 @@ describe('opentelemetry', () => {
|
|
|
102
100
|
|
|
103
101
|
|
|
104
102
|
it('receives spans on fetch failure', async () => {
|
|
105
|
-
|
|
106
|
-
fetch.mockImplementationOnce(async () => {
|
|
107
|
-
throw Error("Nooo");
|
|
108
|
-
});
|
|
109
|
-
|
|
110
103
|
const gateway = new ApolloGateway({
|
|
111
104
|
localServiceList: fixtures,
|
|
105
|
+
fetcher: () => {
|
|
106
|
+
throw Error('Nooo');
|
|
107
|
+
},
|
|
112
108
|
});
|
|
113
109
|
|
|
114
110
|
const { executor } = await gateway.load();
|
|
@@ -4,15 +4,15 @@ import {
|
|
|
4
4
|
SubgraphHealthCheckFunction,
|
|
5
5
|
SupergraphSdlUpdateFunction,
|
|
6
6
|
} from '@apollo/gateway';
|
|
7
|
-
import { fixturesWithUpdate } from 'apollo-federation-integration-testsuite';
|
|
7
|
+
import { accounts, fixturesWithUpdate } from 'apollo-federation-integration-testsuite';
|
|
8
8
|
import { createHash } from '@apollo/utils.createhash';
|
|
9
9
|
import { ApolloServer } from 'apollo-server';
|
|
10
10
|
import type { Logger } from '@apollo/utils.logger';
|
|
11
|
-
import { fetch } from '../../__mocks__/make-fetch-happen-fetcher';
|
|
12
11
|
import { getTestingSupergraphSdl } from '../execution-utils';
|
|
13
12
|
import { mockAllServicesHealthCheckSuccess } from '../integration/nockMocks';
|
|
14
13
|
import resolvable from '@josephg/resolvable';
|
|
15
14
|
import { nockAfterEach, nockBeforeEach } from '../nockAssertions';
|
|
15
|
+
import nock from 'nock';
|
|
16
16
|
|
|
17
17
|
async function getSupergraphSdlGatewayServer() {
|
|
18
18
|
const server = new ApolloServer({
|
|
@@ -21,7 +21,6 @@ async function getSupergraphSdlGatewayServer() {
|
|
|
21
21
|
buildService({ url }) {
|
|
22
22
|
return new RemoteGraphQLDataSource({
|
|
23
23
|
url,
|
|
24
|
-
fetcher: fetch,
|
|
25
24
|
});
|
|
26
25
|
},
|
|
27
26
|
}),
|
|
@@ -59,9 +58,10 @@ describe('Using supergraphSdl static configuration', () => {
|
|
|
59
58
|
it('successfully starts and serves requests to the proper services', async () => {
|
|
60
59
|
const server = await getSupergraphSdlGatewayServer();
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
nock(accounts.url)
|
|
62
|
+
.post('/', { query: '{me{username}}', variables: {} })
|
|
63
|
+
.reply(200, { data: { me: { username: '@jbaxleyiii' } } });
|
|
64
|
+
|
|
65
65
|
|
|
66
66
|
const result = await server.executeOperation({
|
|
67
67
|
query: '{ me { username } }',
|
|
@@ -75,11 +75,6 @@ describe('Using supergraphSdl static configuration', () => {
|
|
|
75
75
|
}
|
|
76
76
|
`);
|
|
77
77
|
|
|
78
|
-
const [url, request] = fetch.mock.calls[0];
|
|
79
|
-
expect(url).toEqual('https://accounts.api.com.invalid');
|
|
80
|
-
expect(request?.body).toEqual(
|
|
81
|
-
JSON.stringify({ query: '{me{username}}', variables: {} }),
|
|
82
|
-
);
|
|
83
78
|
await server.stop();
|
|
84
79
|
});
|
|
85
80
|
});
|
package/src/config.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GraphQLError, GraphQLSchema } from 'graphql';
|
|
2
2
|
import { HeadersInit } from 'node-fetch';
|
|
3
|
-
import { fetch } from 'apollo-server-env';
|
|
4
3
|
import { GraphQLRequestContextExecutionDidStart } from 'apollo-server-types';
|
|
5
4
|
import type { Logger } from '@apollo/utils.logger';
|
|
6
5
|
import { GraphQLDataSource } from './datasources/types';
|
|
@@ -8,6 +7,7 @@ import { QueryPlan } from '@apollo/query-planner';
|
|
|
8
7
|
import { OperationContext } from './operationContext';
|
|
9
8
|
import { ServiceMap } from './executeQueryPlan';
|
|
10
9
|
import { ServiceDefinition } from "@apollo/federation-internals";
|
|
10
|
+
import { Fetcher } from '@apollo/utils.fetcher';
|
|
11
11
|
|
|
12
12
|
export type ServiceEndpointDefinition = Pick<ServiceDefinition, 'name' | 'url'>;
|
|
13
13
|
|
|
@@ -126,7 +126,7 @@ interface GatewayConfigBase {
|
|
|
126
126
|
experimental_didUpdateSupergraph?: Experimental_DidUpdateSupergraphCallback;
|
|
127
127
|
experimental_approximateQueryPlanStoreMiB?: number;
|
|
128
128
|
experimental_autoFragmentization?: boolean;
|
|
129
|
-
fetcher?:
|
|
129
|
+
fetcher?: Fetcher;
|
|
130
130
|
serviceHealthCheck?: boolean;
|
|
131
131
|
}
|
|
132
132
|
|