@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,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fetch,
|
|
3
|
-
Request,
|
|
4
|
-
Response,
|
|
5
|
-
Body,
|
|
6
|
-
BodyInit,
|
|
7
|
-
Headers,
|
|
8
|
-
HeadersInit,
|
|
9
|
-
URL,
|
|
10
|
-
URLSearchParams,
|
|
11
|
-
} from 'apollo-server-env';
|
|
12
|
-
interface FetchMock extends jest.MockedFunction<typeof fetch> {
|
|
13
|
-
mockResponseOnce(data?: any, headers?: HeadersInit, status?: number): this;
|
|
14
|
-
mockJSONResponseOnce(data?: object, headers?: HeadersInit): this;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const mockFetch = jest.fn(fetch) as unknown as FetchMock;
|
|
18
|
-
|
|
19
|
-
mockFetch.mockResponseOnce = (
|
|
20
|
-
data?: BodyInit,
|
|
21
|
-
headers?: Headers,
|
|
22
|
-
status: number = 200,
|
|
23
|
-
) => {
|
|
24
|
-
return mockFetch.mockImplementationOnce(async () => {
|
|
25
|
-
return new Response(data, {
|
|
26
|
-
status,
|
|
27
|
-
headers,
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
mockFetch.mockJSONResponseOnce = (
|
|
33
|
-
data = {},
|
|
34
|
-
headers?: Headers,
|
|
35
|
-
status?: number,
|
|
36
|
-
) => {
|
|
37
|
-
return mockFetch.mockResponseOnce(
|
|
38
|
-
JSON.stringify(data),
|
|
39
|
-
Object.assign({ 'Content-Type': 'application/json' }, headers),
|
|
40
|
-
status,
|
|
41
|
-
);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const env = {
|
|
45
|
-
fetch: mockFetch,
|
|
46
|
-
Request,
|
|
47
|
-
Response,
|
|
48
|
-
Body,
|
|
49
|
-
Headers,
|
|
50
|
-
URL,
|
|
51
|
-
URLSearchParams,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
jest.doMock('apollo-server-env', () => env);
|
|
55
|
-
|
|
56
|
-
export = env;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/// <reference path="../make-fetch-happen.d.ts" />
|
|
2
|
-
// This explicit reference shouldn't be needed because the project references
|
|
3
|
-
// the main project, which includes these type declarations. For some reason,
|
|
4
|
-
// VS Code doesn't pick that up though.
|
|
5
|
-
// (This may be related to https://github.com/microsoft/TypeScript/issues/36708.)
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
fetch,
|
|
9
|
-
Response,
|
|
10
|
-
BodyInit,
|
|
11
|
-
Headers,
|
|
12
|
-
HeadersInit
|
|
13
|
-
} from 'apollo-server-env';
|
|
14
|
-
|
|
15
|
-
import fetcher from 'make-fetch-happen';
|
|
16
|
-
|
|
17
|
-
interface MakeFetchHappenMock extends jest.MockedFunction<typeof fetch> {
|
|
18
|
-
mockResponseOnce(data?: any, headers?: HeadersInit, status?: number): this;
|
|
19
|
-
mockJSONResponseOnce(data?: object, headers?: HeadersInit): this;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const mockMakeFetchHappen = jest.fn(fetcher) as unknown as MakeFetchHappenMock;
|
|
23
|
-
const defaults = () => mockMakeFetchHappen;
|
|
24
|
-
|
|
25
|
-
mockMakeFetchHappen.mockResponseOnce = (
|
|
26
|
-
data?: BodyInit,
|
|
27
|
-
headers?: Headers,
|
|
28
|
-
status: number = 200,
|
|
29
|
-
) => {
|
|
30
|
-
return mockMakeFetchHappen.mockImplementationOnce(async () => {
|
|
31
|
-
return new Response(data, {
|
|
32
|
-
status,
|
|
33
|
-
headers,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
mockMakeFetchHappen.mockJSONResponseOnce = (
|
|
39
|
-
data = {},
|
|
40
|
-
headers?: Headers,
|
|
41
|
-
status?: number,
|
|
42
|
-
) => {
|
|
43
|
-
return mockMakeFetchHappen.mockResponseOnce(
|
|
44
|
-
JSON.stringify(data),
|
|
45
|
-
Object.assign({ 'Content-Type': 'application/json' }, headers),
|
|
46
|
-
status,
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const makeFetchMock = {
|
|
51
|
-
fetch: mockMakeFetchHappen,
|
|
52
|
-
defaults,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
jest.doMock('make-fetch-happen', () => makeFetchMock);
|
|
56
|
-
|
|
57
|
-
export = makeFetchMock;
|
package/src/cache.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { CacheManager } from 'make-fetch-happen';
|
|
2
|
-
import { Request, Response, Headers } from 'apollo-server-env';
|
|
3
|
-
import { InMemoryLRUCache } from 'apollo-server-caching';
|
|
4
|
-
|
|
5
|
-
const MAX_SIZE = 5 * 1024 * 1024; // 5MB
|
|
6
|
-
|
|
7
|
-
function cacheKey(request: Request) {
|
|
8
|
-
return `gateway:request-cache:${request.method}:${request.url}`;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface CachedRequest {
|
|
12
|
-
body: string;
|
|
13
|
-
status: number;
|
|
14
|
-
statusText: string;
|
|
15
|
-
headers: Headers;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class HttpRequestCache implements CacheManager {
|
|
19
|
-
constructor(
|
|
20
|
-
public cache: InMemoryLRUCache<CachedRequest> = new InMemoryLRUCache({
|
|
21
|
-
maxSize: MAX_SIZE,
|
|
22
|
-
}),
|
|
23
|
-
) {}
|
|
24
|
-
|
|
25
|
-
// Return true if entry exists, else false
|
|
26
|
-
async delete(request: Request) {
|
|
27
|
-
const key = cacheKey(request);
|
|
28
|
-
const entry = await this.cache.get(key);
|
|
29
|
-
await this.cache.delete(key);
|
|
30
|
-
return Boolean(entry);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async put(request: Request, response: Response) {
|
|
34
|
-
// A `HEAD` request has no body to cache and a 304 response could have
|
|
35
|
-
// only been negotiated by using a cached body that was still valid.
|
|
36
|
-
// Therefore, we do NOT write to the cache in either of these cases.
|
|
37
|
-
// Without avoiding this, we will invalidate the cache, thus causing
|
|
38
|
-
// subsequent conditional requests (e.g., `If-None-Match: "MD%") to be
|
|
39
|
-
// lacking content to conditionally request against and necessitating
|
|
40
|
-
// a full request/response.
|
|
41
|
-
if (request.method === "HEAD" || response.status === 304) {
|
|
42
|
-
return response;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const body = await response.text();
|
|
46
|
-
|
|
47
|
-
this.cache.set(cacheKey(request), {
|
|
48
|
-
body,
|
|
49
|
-
status: response.status,
|
|
50
|
-
statusText: response.statusText,
|
|
51
|
-
headers: response.headers,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return new Response(body, response);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async match(request: Request) {
|
|
58
|
-
return this.cache.get(cacheKey(request)).then(response => {
|
|
59
|
-
if (response) {
|
|
60
|
-
const { body, ...requestInit } = response;
|
|
61
|
-
return new Response(body, requestInit);
|
|
62
|
-
}
|
|
63
|
-
return;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* We are attempting to get types included natively in this package, but it
|
|
3
|
-
* has not happened, yet!
|
|
4
|
-
*
|
|
5
|
-
* See https://github.com/npm/make-fetch-happen/issues/20
|
|
6
|
-
*/
|
|
7
|
-
declare module 'make-fetch-happen' {
|
|
8
|
-
import {
|
|
9
|
-
Response,
|
|
10
|
-
Request,
|
|
11
|
-
RequestInfo,
|
|
12
|
-
RequestInit,
|
|
13
|
-
} from 'apollo-server-env';
|
|
14
|
-
|
|
15
|
-
// If adding to these options, they should mirror those from `make-fetch-happen`
|
|
16
|
-
// @see: https://github.com/npm/make-fetch-happen/#extra-options
|
|
17
|
-
export interface FetcherOptions {
|
|
18
|
-
cacheManager?: string | CacheManager;
|
|
19
|
-
// @see: https://www.npmjs.com/package/retry#retrytimeoutsoptions
|
|
20
|
-
retry?:
|
|
21
|
-
| boolean
|
|
22
|
-
| number
|
|
23
|
-
| {
|
|
24
|
-
// The maximum amount of times to retry the operation. Default is 10. Seting this to 1 means do it once, then retry it once
|
|
25
|
-
retries?: number;
|
|
26
|
-
// The exponential factor to use. Default is 2.
|
|
27
|
-
factor?: number;
|
|
28
|
-
// The number of milliseconds before starting the first retry. Default is 1000.
|
|
29
|
-
minTimeout?: number;
|
|
30
|
-
// The maximum number of milliseconds between two retries. Default is Infinity.
|
|
31
|
-
maxTimeout?: number;
|
|
32
|
-
// Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.
|
|
33
|
-
randomize?: boolean;
|
|
34
|
-
};
|
|
35
|
-
onRetry?(): void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface CacheManager {
|
|
39
|
-
delete(req: Request): Promise<Boolean>;
|
|
40
|
-
put(req: Request, res: Response): Promise<Response>;
|
|
41
|
-
match(req: Request): Promise<Response | undefined>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* This is an augmentation of the fetch function types provided by `apollo-server-env`
|
|
46
|
-
* @see: https://git.io/JvBwX
|
|
47
|
-
*/
|
|
48
|
-
export interface Fetcher {
|
|
49
|
-
(input?: RequestInfo, init?: RequestInit & FetcherOptions): Promise<
|
|
50
|
-
Response
|
|
51
|
-
>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
let fetch: Fetcher & {
|
|
55
|
-
defaults(opts?: RequestInit & FetcherOptions): typeof fetch;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export default fetch;
|
|
59
|
-
}
|