@apollo/gateway 0.50.2 → 0.51.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 +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 +4 -4
- package/src/__tests__/gateway/buildService.test.ts +81 -83
- package/src/__tests__/gateway/executor.test.ts +18 -15
- package/src/__tests__/gateway/opentelemetry.test.ts +3 -7
- package/src/__tests__/gateway/supergraphSdl.test.ts +10 -12
- 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,CAAC;C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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,EACL,eAA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F,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": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Apollo Gateway",
|
|
5
5
|
"author": "Apollo <packages@apollographql.com>",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@apollo/federation": "^0.36.2",
|
|
30
30
|
"@apollo/query-planner": "^0.10.2",
|
|
31
31
|
"@apollo/utils.createhash": "^1.0.0",
|
|
32
|
+
"@apollo/utils.fetcher": "^1.0.0",
|
|
32
33
|
"@apollo/utils.logger": "^1.0.0",
|
|
33
34
|
"@josephg/resolvable": "^1.0.1",
|
|
34
35
|
"@opentelemetry/api": "^1.0.1",
|
|
@@ -36,16 +37,15 @@
|
|
|
36
37
|
"apollo-reporting-protobuf": "^0.8.0 || ^3.0.0",
|
|
37
38
|
"apollo-server-caching": "^0.7.0 || ^3.0.0",
|
|
38
39
|
"apollo-server-core": "^2.23.0 || ^3.0.0",
|
|
39
|
-
"apollo-server-env": "^3.0.0 || ^4.0.0",
|
|
40
40
|
"apollo-server-errors": "^2.5.0 || ^3.0.0",
|
|
41
41
|
"apollo-server-types": "^0.9.0 || ^3.0.0",
|
|
42
42
|
"async-retry": "^1.3.3",
|
|
43
43
|
"loglevel": "^1.6.1",
|
|
44
|
-
"make-fetch-happen": "^
|
|
44
|
+
"make-fetch-happen": "^10.1.2",
|
|
45
45
|
"pretty-format": "^27.4.6"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"graphql": "^15.8.0 || ^16.0.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "bf11c7dbd65049d1cb0d91b148f181b89e51e157"
|
|
51
51
|
}
|
|
@@ -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,7 +40,7 @@ describe('ApolloGateway executor', () => {
|
|
|
38
40
|
}
|
|
39
41
|
`;
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
// @ts-ignore
|
|
42
44
|
const { errors } = await executor({
|
|
43
45
|
source,
|
|
44
46
|
document: gql(source),
|
|
@@ -57,8 +59,10 @@ describe('ApolloGateway executor', () => {
|
|
|
57
59
|
});
|
|
58
60
|
|
|
59
61
|
it('should not crash if variables are not provided', async () => {
|
|
60
|
-
const me = { birthDate: '1988-10-21'};
|
|
61
|
-
|
|
62
|
+
const me = { birthDate: '1988-10-21' };
|
|
63
|
+
|
|
64
|
+
nock(accounts.url).post('/').reply(200, { data: { me } });
|
|
65
|
+
|
|
62
66
|
const gateway = new ApolloGateway({
|
|
63
67
|
localServiceList: fixtures,
|
|
64
68
|
});
|
|
@@ -73,12 +77,11 @@ describe('ApolloGateway executor', () => {
|
|
|
73
77
|
}
|
|
74
78
|
`;
|
|
75
79
|
|
|
76
|
-
|
|
80
|
+
// @ts-ignore
|
|
77
81
|
const { errors, data } = await executor({
|
|
78
82
|
source,
|
|
79
83
|
document: gql(source),
|
|
80
|
-
request: {
|
|
81
|
-
},
|
|
84
|
+
request: {},
|
|
82
85
|
queryHash: 'hashed',
|
|
83
86
|
context: null,
|
|
84
87
|
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,23 +4,25 @@ 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({
|
|
19
19
|
gateway: new ApolloGateway({
|
|
20
20
|
supergraphSdl: getTestingSupergraphSdl(),
|
|
21
21
|
buildService({ url }) {
|
|
22
|
-
return new RemoteGraphQLDataSource({
|
|
23
|
-
|
|
22
|
+
return new RemoteGraphQLDataSource({
|
|
23
|
+
url,
|
|
24
|
+
});
|
|
25
|
+
},
|
|
24
26
|
}),
|
|
25
27
|
});
|
|
26
28
|
|
|
@@ -54,9 +56,10 @@ describe('Using supergraphSdl static configuration', () => {
|
|
|
54
56
|
it('successfully starts and serves requests to the proper services', async () => {
|
|
55
57
|
const server = await getSupergraphSdlGatewayServer();
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
nock(accounts.url)
|
|
60
|
+
.post('/', { query: '{me{username}}', variables: {} })
|
|
61
|
+
.reply(200, { data: { me: { username: '@jbaxleyiii' } } });
|
|
62
|
+
|
|
60
63
|
|
|
61
64
|
const result = await server.executeOperation({
|
|
62
65
|
query: '{ me { username } }',
|
|
@@ -70,11 +73,6 @@ describe('Using supergraphSdl static configuration', () => {
|
|
|
70
73
|
}
|
|
71
74
|
`);
|
|
72
75
|
|
|
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
76
|
await server.stop();
|
|
79
77
|
});
|
|
80
78
|
});
|
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 { ServiceDefinition } from '@apollo/federation';
|
|
@@ -8,6 +7,7 @@ import { GraphQLDataSource } from './datasources/types';
|
|
|
8
7
|
import { QueryPlan } from '@apollo/query-planner';
|
|
9
8
|
import { OperationContext } from './operationContext';
|
|
10
9
|
import { ServiceMap } from './executeQueryPlan';
|
|
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
|
|
|
@@ -12,17 +12,19 @@ import {
|
|
|
12
12
|
AuthenticationError,
|
|
13
13
|
ForbiddenError,
|
|
14
14
|
} from 'apollo-server-errors';
|
|
15
|
-
import { fetch, Request, Headers, Response } from 'apollo-server-env';
|
|
16
15
|
import { isObject } from '../utilities/predicates';
|
|
17
16
|
import { GraphQLDataSource, GraphQLDataSourceProcessOptions, GraphQLDataSourceRequestKind } from './types';
|
|
18
17
|
import { createHash } from '@apollo/utils.createhash';
|
|
19
18
|
import { parseCacheControlHeader } from './parseCacheControlHeader';
|
|
20
19
|
import fetcher from 'make-fetch-happen';
|
|
20
|
+
import { Headers as NodeFetchHeaders, Request as NodeFetchRequest } from 'node-fetch';
|
|
21
|
+
import { Fetcher, FetcherRequestInit, FetcherResponse } from '@apollo/utils.fetcher';
|
|
22
|
+
|
|
21
23
|
export class RemoteGraphQLDataSource<
|
|
22
24
|
TContext extends Record<string, any> = Record<string, any>,
|
|
23
25
|
> implements GraphQLDataSource<TContext>
|
|
24
26
|
{
|
|
25
|
-
fetcher:
|
|
27
|
+
fetcher: Fetcher;
|
|
26
28
|
|
|
27
29
|
constructor(
|
|
28
30
|
config?: Partial<RemoteGraphQLDataSource<TContext>> &
|
|
@@ -30,6 +32,11 @@ export class RemoteGraphQLDataSource<
|
|
|
30
32
|
ThisType<RemoteGraphQLDataSource<TContext>>,
|
|
31
33
|
) {
|
|
32
34
|
this.fetcher = fetcher.defaults({
|
|
35
|
+
// Allow an arbitrary number of sockets per subgraph. This is the default
|
|
36
|
+
// behavior of Node's http.Agent as well as the npm package agentkeepalive
|
|
37
|
+
// which wraps it, but is not the default behavior of make-fetch-happen
|
|
38
|
+
// which wraps agentkeepalive (that package sets this to 15 by default).
|
|
39
|
+
maxSockets: Infinity,
|
|
33
40
|
// although this is the default, we want to take extra care and be very
|
|
34
41
|
// explicity to ensure that mutations cannot be retried. please leave this
|
|
35
42
|
// intact.
|
|
@@ -82,7 +89,12 @@ export class RemoteGraphQLDataSource<
|
|
|
82
89
|
const context = originalContext as TContext;
|
|
83
90
|
|
|
84
91
|
// Respect incoming http headers (eg, apollo-federation-include-trace).
|
|
85
|
-
const headers =
|
|
92
|
+
const headers = new NodeFetchHeaders();
|
|
93
|
+
if (request.http?.headers) {
|
|
94
|
+
for (const [name, value] of request.http.headers) {
|
|
95
|
+
headers.append(name, value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
86
98
|
headers.set('Content-Type', 'application/json');
|
|
87
99
|
|
|
88
100
|
request.http = {
|
|
@@ -177,20 +189,24 @@ export class RemoteGraphQLDataSource<
|
|
|
177
189
|
// we're accessing (e.g. url) and what we access it with (e.g. headers).
|
|
178
190
|
const { http, ...requestWithoutHttp } = request;
|
|
179
191
|
const stringifiedRequestWithoutHttp = JSON.stringify(requestWithoutHttp);
|
|
180
|
-
const
|
|
181
|
-
|
|
192
|
+
const requestInit: FetcherRequestInit = {
|
|
193
|
+
method: http.method,
|
|
194
|
+
headers: Object.fromEntries(http.headers),
|
|
182
195
|
body: stringifiedRequestWithoutHttp,
|
|
183
|
-
}
|
|
196
|
+
};
|
|
197
|
+
// Note that we don't actually send this Request object to the fetcher; it
|
|
198
|
+
// is merely sent to methods on this object that might be overridden by users.
|
|
199
|
+
// We are careful to only send data to the overridable fetcher function that uses
|
|
200
|
+
// plain JS objects --- some fetch implementations don't know how to handle
|
|
201
|
+
// Request or Headers objects created by other fetch implementations.
|
|
202
|
+
const fetchRequest = new NodeFetchRequest(http.url, requestInit);
|
|
184
203
|
|
|
185
|
-
let fetchResponse:
|
|
204
|
+
let fetchResponse: FetcherResponse | undefined;
|
|
186
205
|
|
|
187
206
|
try {
|
|
188
207
|
// Use our local `fetcher` to allow for fetch injection
|
|
189
208
|
// Use the fetcher's `Request` implementation for compatibility
|
|
190
|
-
fetchResponse = await this.fetcher(http.url,
|
|
191
|
-
...http,
|
|
192
|
-
body: stringifiedRequestWithoutHttp,
|
|
193
|
-
});
|
|
209
|
+
fetchResponse = await this.fetcher(http.url, requestInit);
|
|
194
210
|
|
|
195
211
|
if (!fetchResponse.ok) {
|
|
196
212
|
throw await this.errorFromResponse(fetchResponse);
|
|
@@ -266,16 +282,16 @@ export class RemoteGraphQLDataSource<
|
|
|
266
282
|
|
|
267
283
|
public didEncounterError(
|
|
268
284
|
error: Error,
|
|
269
|
-
_fetchRequest:
|
|
270
|
-
_fetchResponse?:
|
|
285
|
+
_fetchRequest: NodeFetchRequest,
|
|
286
|
+
_fetchResponse?: FetcherResponse,
|
|
271
287
|
_context?: TContext,
|
|
272
288
|
) {
|
|
273
289
|
throw error;
|
|
274
290
|
}
|
|
275
291
|
|
|
276
292
|
public parseBody(
|
|
277
|
-
fetchResponse:
|
|
278
|
-
_fetchRequest?:
|
|
293
|
+
fetchResponse: FetcherResponse,
|
|
294
|
+
_fetchRequest?: NodeFetchRequest,
|
|
279
295
|
_context?: TContext,
|
|
280
296
|
): Promise<object | string> {
|
|
281
297
|
const contentType = fetchResponse.headers.get('Content-Type');
|
|
@@ -286,7 +302,7 @@ export class RemoteGraphQLDataSource<
|
|
|
286
302
|
}
|
|
287
303
|
}
|
|
288
304
|
|
|
289
|
-
public async errorFromResponse(response:
|
|
305
|
+
public async errorFromResponse(response: FetcherResponse) {
|
|
290
306
|
const message = `${response.status}: ${response.statusText}`;
|
|
291
307
|
|
|
292
308
|
let error: ApolloError;
|