@apollo/gateway 2.0.1 → 2.0.2-alpha.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 +18 -13
- 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 +7 -25
- package/dist/index.js.map +1 -1
- package/dist/schema-helper/addExtensions.d.ts +3 -0
- package/dist/schema-helper/addExtensions.d.ts.map +1 -0
- package/dist/schema-helper/addExtensions.js +20 -0
- package/dist/schema-helper/addExtensions.js.map +1 -0
- 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/dist/typings/graphql.d.ts +34 -0
- package/dist/typings/graphql.d.ts.map +1 -0
- package/dist/{schema-helper/resolverMap.js → typings/graphql.js} +1 -1
- package/dist/typings/graphql.js.map +1 -0
- package/package.json +10 -8
- package/src/__tests__/executeQueryPlan.test.ts +4 -1
- package/src/__tests__/execution-utils.ts +2 -2
- package/src/__tests__/gateway/buildService.test.ts +81 -83
- package/src/__tests__/gateway/endToEnd.test.ts +1 -1
- package/src/__tests__/gateway/executor.test.ts +20 -17
- package/src/__tests__/gateway/extensions.test.ts +37 -0
- package/src/__tests__/gateway/lifecycle-hooks.test.ts +1 -1
- package/src/__tests__/gateway/opentelemetry.test.ts +3 -7
- package/src/__tests__/gateway/reporting.test.ts +1 -1
- package/src/__tests__/gateway/supergraphSdl.test.ts +7 -12
- package/src/config.ts +2 -2
- package/src/datasources/RemoteGraphQLDataSource.ts +34 -18
- package/src/datasources/__tests__/LocalGraphQLDataSource.test.ts +1 -1
- package/src/datasources/__tests__/RemoteGraphQLDataSource.test.ts +106 -140
- package/src/executeQueryPlan.ts +5 -1
- package/src/index.ts +15 -32
- package/src/schema-helper/__tests__/addExtensions.test.ts +11 -0
- package/src/schema-helper/addExtensions.ts +17 -0
- 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/src/typings/graphql.ts +43 -0
- 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/dist/schema-helper/addResolversToSchema.d.ts +0 -4
- package/dist/schema-helper/addResolversToSchema.d.ts.map +0 -1
- package/dist/schema-helper/addResolversToSchema.js +0 -62
- package/dist/schema-helper/addResolversToSchema.js.map +0 -1
- package/dist/schema-helper/error.d.ts +0 -6
- package/dist/schema-helper/error.d.ts.map +0 -1
- package/dist/schema-helper/error.js +0 -14
- package/dist/schema-helper/error.js.map +0 -1
- package/dist/schema-helper/index.d.ts +0 -4
- package/dist/schema-helper/index.d.ts.map +0 -1
- package/dist/schema-helper/index.js +0 -20
- package/dist/schema-helper/index.js.map +0 -1
- package/dist/schema-helper/resolverMap.d.ts +0 -16
- package/dist/schema-helper/resolverMap.d.ts.map +0 -1
- package/dist/schema-helper/resolverMap.js.map +0 -1
- package/dist/utilities/createHash.d.ts +0 -2
- package/dist/utilities/createHash.d.ts.map +0 -1
- package/dist/utilities/createHash.js +0 -15
- package/dist/utilities/createHash.js.map +0 -1
- package/dist/utilities/isNodeLike.d.ts +0 -3
- package/dist/utilities/isNodeLike.d.ts.map +0 -1
- package/dist/utilities/isNodeLike.js +0 -8
- package/dist/utilities/isNodeLike.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
- package/src/schema-helper/addResolversToSchema.ts +0 -83
- package/src/schema-helper/error.ts +0 -11
- package/src/schema-helper/index.ts +0 -3
- package/src/schema-helper/resolverMap.ts +0 -23
- package/src/utilities/createHash.ts +0 -10
- package/src/utilities/isNodeLike.ts +0 -11
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.loadSupergraphSdlFromStorage = exports.loadSupergraphSdlFromUplinks = exports.UplinkFetcherError = exports.SUPERGRAPH_SDL_QUERY = void 0;
|
|
7
|
-
const apollo_server_env_1 = require("apollo-server-env");
|
|
8
7
|
const async_retry_1 = __importDefault(require("async-retry"));
|
|
9
8
|
const outOfBandReporter_1 = require("./outOfBandReporter");
|
|
10
9
|
exports.SUPERGRAPH_SDL_QUERY = `#graphql
|
|
@@ -52,17 +51,17 @@ async function loadSupergraphSdlFromUplinks({ graphRef, apiKey, endpoints, error
|
|
|
52
51
|
exports.loadSupergraphSdlFromUplinks = loadSupergraphSdlFromUplinks;
|
|
53
52
|
async function loadSupergraphSdlFromStorage({ graphRef, apiKey, endpoint, errorReportingEndpoint, fetcher, compositionId, }) {
|
|
54
53
|
var _a, _b;
|
|
55
|
-
|
|
54
|
+
const requestBody = JSON.stringify({
|
|
55
|
+
query: exports.SUPERGRAPH_SDL_QUERY,
|
|
56
|
+
variables: {
|
|
57
|
+
ref: graphRef,
|
|
58
|
+
apiKey,
|
|
59
|
+
ifAfterId: compositionId,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
56
62
|
const requestDetails = {
|
|
57
63
|
method: 'POST',
|
|
58
|
-
body:
|
|
59
|
-
query: exports.SUPERGRAPH_SDL_QUERY,
|
|
60
|
-
variables: {
|
|
61
|
-
ref: graphRef,
|
|
62
|
-
apiKey,
|
|
63
|
-
ifAfterId: compositionId,
|
|
64
|
-
},
|
|
65
|
-
}),
|
|
64
|
+
body: requestBody,
|
|
66
65
|
headers: {
|
|
67
66
|
'apollographql-client-name': name,
|
|
68
67
|
'apollographql-client-version': version,
|
|
@@ -70,8 +69,8 @@ async function loadSupergraphSdlFromStorage({ graphRef, apiKey, endpoint, errorR
|
|
|
70
69
|
'content-type': 'application/json',
|
|
71
70
|
},
|
|
72
71
|
};
|
|
73
|
-
const request = new apollo_server_env_1.Request(endpoint, requestDetails);
|
|
74
72
|
const startTime = new Date();
|
|
73
|
+
let result;
|
|
75
74
|
try {
|
|
76
75
|
result = await fetcher(endpoint, requestDetails);
|
|
77
76
|
}
|
|
@@ -79,7 +78,8 @@ async function loadSupergraphSdlFromStorage({ graphRef, apiKey, endpoint, errorR
|
|
|
79
78
|
const endTime = new Date();
|
|
80
79
|
await (0, outOfBandReporter_1.submitOutOfBandReportIfConfigured)({
|
|
81
80
|
error: e,
|
|
82
|
-
|
|
81
|
+
requestEndpoint: endpoint,
|
|
82
|
+
requestBody,
|
|
83
83
|
endpoint: errorReportingEndpoint,
|
|
84
84
|
startedAt: startTime,
|
|
85
85
|
endedAt: endTime,
|
|
@@ -103,7 +103,8 @@ async function loadSupergraphSdlFromStorage({ graphRef, apiKey, endpoint, errorR
|
|
|
103
103
|
else {
|
|
104
104
|
await (0, outOfBandReporter_1.submitOutOfBandReportIfConfigured)({
|
|
105
105
|
error: new UplinkFetcherError(fetchErrorMsg + result.status + ' ' + result.statusText),
|
|
106
|
-
|
|
106
|
+
requestEndpoint: endpoint,
|
|
107
|
+
requestBody,
|
|
107
108
|
endpoint: errorReportingEndpoint,
|
|
108
109
|
response: result,
|
|
109
110
|
startedAt: startTime,
|
|
@@ -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;CACF;AALD,gDAKC;AAEM,KAAK,UAAU,4BAA4B,CAAC,EACjD,QAAQ,EACR,MAAM,EACN,SAAS,EACT,sBAAsB,EACtB,OAAO,EACP,aAAa,EACb,UAAU,EACV,c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,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,eAAe,EACf,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAO,GAWR;;IAEC,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO;KACR;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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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { GraphQLResolveInfo } from 'graphql';
|
|
2
|
+
declare type GraphQLReferenceResolver<TContext> = (reference: object, context: TContext, info: GraphQLResolveInfo) => any;
|
|
3
|
+
interface ApolloSubgraphExtensions<TContext> {
|
|
4
|
+
resolveReference?: GraphQLReferenceResolver<TContext>;
|
|
5
|
+
}
|
|
6
|
+
interface ApolloGatewayExtensions {
|
|
7
|
+
version?: String;
|
|
8
|
+
}
|
|
9
|
+
declare module 'graphql/type/definition' {
|
|
10
|
+
interface GraphQLObjectTypeExtensions<_TSource = any, _TContext = any> {
|
|
11
|
+
apollo?: {
|
|
12
|
+
subgraph?: ApolloSubgraphExtensions<_TContext>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
interface GraphQLInterfaceTypeExtensions<_TSource = any, _TContext = any> {
|
|
16
|
+
apollo?: {
|
|
17
|
+
subgraph?: ApolloSubgraphExtensions<_TContext>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
interface GraphQLUnionTypeExtensions<_TSource = any, _TContext = any> {
|
|
21
|
+
apollo?: {
|
|
22
|
+
subgraph?: ApolloSubgraphExtensions<_TContext>;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
declare module 'graphql/type/schema' {
|
|
27
|
+
interface GraphQLSchemaExtensions {
|
|
28
|
+
apollo?: {
|
|
29
|
+
gateway?: ApolloGatewayExtensions;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=graphql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/typings/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,aAAK,wBAAwB,CAAC,QAAQ,IAAI,CACxC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,kBAAkB,KACrB,GAAG,CAAC;AAET,UAAU,wBAAwB,CAAC,QAAQ;IACzC,gBAAgB,CAAC,EAAE,wBAAwB,CAAC,QAAQ,CAAC,CAAC;CACvD;AAED,UAAU,uBAAuB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,OAAO,QAAQ,yBAAyB,CAAC;IACvC,UAAU,2BAA2B,CAAC,QAAQ,GAAG,GAAG,EAAE,SAAS,GAAG,GAAG;QACnE,MAAM,CAAC,EAAE;YACP,QAAQ,CAAC,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAC;SAChD,CAAA;KACF;IAED,UAAU,8BAA8B,CAAC,QAAQ,GAAG,GAAG,EAAE,SAAS,GAAG,GAAG;QACtE,MAAM,CAAC,EAAE;YACP,QAAQ,CAAC,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAC;SAChD,CAAA;KACF;IAED,UAAU,0BAA0B,CAAC,QAAQ,GAAG,GAAG,EAAE,SAAS,GAAG,GAAG;QAClE,MAAM,CAAC,EAAE;YACP,QAAQ,CAAC,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAC;SAChD,CAAA;KACF;CACF;AAED,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,uBAAuB;QAC/B,MAAM,CAAC,EAAE;YACP,OAAO,CAAC,EAAE,uBAAuB,CAAC;SACnC,CAAA;KACF;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../src/typings/graphql.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apollo/gateway",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-alpha.2",
|
|
4
4
|
"description": "Apollo Gateway",
|
|
5
5
|
"author": "Apollo <packages@apollographql.com>",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,9 +25,13 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@apollo/composition": "^2.0.
|
|
28
|
+
"@apollo/composition": "^2.0.2-alpha.2",
|
|
29
29
|
"@apollo/core-schema": "~0.3.0",
|
|
30
|
-
"@apollo/
|
|
30
|
+
"@apollo/federation-internals": "^2.0.2-alpha.2",
|
|
31
|
+
"@apollo/query-planner": "^2.0.2-alpha.2",
|
|
32
|
+
"@apollo/utils.createhash": "^1.0.0",
|
|
33
|
+
"@apollo/utils.fetcher": "^1.0.0",
|
|
34
|
+
"@apollo/utils.isnodelike": "^1.0.0",
|
|
31
35
|
"@apollo/utils.logger": "^1.0.0",
|
|
32
36
|
"@josephg/resolvable": "^1.0.1",
|
|
33
37
|
"@opentelemetry/api": "^1.0.1",
|
|
@@ -35,17 +39,15 @@
|
|
|
35
39
|
"apollo-reporting-protobuf": "^0.8.0 || ^3.0.0",
|
|
36
40
|
"apollo-server-caching": "^0.7.0 || ^3.0.0",
|
|
37
41
|
"apollo-server-core": "^2.23.0 || ^3.0.0",
|
|
38
|
-
"apollo-server-env": "^3.0.0 || ^4.0.0",
|
|
39
42
|
"apollo-server-errors": "^2.5.0 || ^3.0.0",
|
|
40
43
|
"apollo-server-types": "^0.9.0 || ^3.0.0",
|
|
41
44
|
"async-retry": "^1.3.3",
|
|
42
45
|
"loglevel": "^1.6.1",
|
|
43
|
-
"make-fetch-happen": "^
|
|
44
|
-
"pretty-format": "^27.0.0"
|
|
45
|
-
"sha.js": "^2.4.11"
|
|
46
|
+
"make-fetch-happen": "^10.1.2",
|
|
47
|
+
"pretty-format": "^27.0.0"
|
|
46
48
|
},
|
|
47
49
|
"peerDependencies": {
|
|
48
50
|
"graphql": "^16.0.0"
|
|
49
51
|
},
|
|
50
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "906611360a43172c938b7a0571cc354111b5913f"
|
|
51
53
|
}
|
|
@@ -20,7 +20,10 @@ import { ApolloGateway } from '..';
|
|
|
20
20
|
import { ApolloServerBase as ApolloServer } from 'apollo-server-core';
|
|
21
21
|
import { getFederatedTestingSchema } from './execution-utils';
|
|
22
22
|
import { Schema, Operation, parseOperation, buildSchemaFromAST, arrayEquals } from '@apollo/federation-internals';
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
addResolversToSchema,
|
|
25
|
+
GraphQLResolverMap,
|
|
26
|
+
} from '@apollo/subgraph/src/schema-helper';
|
|
24
27
|
|
|
25
28
|
expect.addSnapshotSerializer(astSerializer);
|
|
26
29
|
expect.addSnapshotSerializer(queryPlanSerializer);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
GraphQLSchemaValidationError,
|
|
3
2
|
GraphQLSchemaModule,
|
|
4
3
|
GraphQLResolverMap,
|
|
5
|
-
|
|
4
|
+
GraphQLSchemaValidationError,
|
|
5
|
+
} from '@apollo/subgraph/src/schema-helper';
|
|
6
6
|
import { GraphQLRequest, GraphQLExecutionResult } from 'apollo-server-types';
|
|
7
7
|
import type { Logger } from '@apollo/utils.logger';
|
|
8
8
|
import { buildSubgraphSchema } from '@apollo/subgraph';
|
|
@@ -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: [
|
|
@@ -4,7 +4,7 @@ import fetch, { Response } from 'node-fetch';
|
|
|
4
4
|
import { ApolloGateway } from '../..';
|
|
5
5
|
import { fixtures } from 'apollo-federation-integration-testsuite';
|
|
6
6
|
import { ApolloServerPluginInlineTrace } from 'apollo-server-core';
|
|
7
|
-
import { GraphQLSchemaModule } from '
|
|
7
|
+
import { GraphQLSchemaModule } from '@apollo/subgraph/src/schema-helper';
|
|
8
8
|
import { buildSchema, ObjectType, ServiceDefinition } from '@apollo/federation-internals';
|
|
9
9
|
import gql from 'graphql-tag';
|
|
10
10
|
import { printSchema } from 'graphql';
|
|
@@ -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,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ApolloGateway } from '@apollo/gateway';
|
|
2
|
+
import resolvable from '@josephg/resolvable';
|
|
3
|
+
import { GraphQLSchema } from 'graphql';
|
|
4
|
+
import { getTestingSupergraphSdl } from '../execution-utils';
|
|
5
|
+
const { version } = require('../../../package.json');
|
|
6
|
+
|
|
7
|
+
describe('addExtensions', () => {
|
|
8
|
+
let gateway: ApolloGateway;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
gateway = new ApolloGateway({
|
|
12
|
+
supergraphSdl: getTestingSupergraphSdl(),
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(async () => {
|
|
17
|
+
await gateway.stop();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('has extensions on loaded schemas', async () => {
|
|
21
|
+
const { schema } = await gateway.load();
|
|
22
|
+
expect(schema.extensions).toEqual({ apollo: { gateway: { version: version } } });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('has extensions on schema updates', async () => {
|
|
26
|
+
const schemaChangeBlocker = resolvable<{
|
|
27
|
+
apiSchema: GraphQLSchema;
|
|
28
|
+
coreSupergraphSdl: string;
|
|
29
|
+
}>();
|
|
30
|
+
|
|
31
|
+
gateway.onSchemaLoadOrUpdate(schemaChangeBlocker.resolve);
|
|
32
|
+
gateway.load();
|
|
33
|
+
|
|
34
|
+
const { apiSchema } = await schemaChangeBlocker;
|
|
35
|
+
expect(apiSchema.extensions).toEqual({ apollo: { gateway: { version: version } } });
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -16,9 +16,9 @@ import {
|
|
|
16
16
|
fixtures,
|
|
17
17
|
fixturesWithUpdate,
|
|
18
18
|
} from 'apollo-federation-integration-testsuite';
|
|
19
|
+
import { createHash } from '@apollo/utils.createhash';
|
|
19
20
|
import type { Logger } from '@apollo/utils.logger';
|
|
20
21
|
import resolvable from '@josephg/resolvable';
|
|
21
|
-
import { createHash } from '../../utilities/createHash';
|
|
22
22
|
import { getTestingSupergraphSdl } from '../execution-utils';
|
|
23
23
|
|
|
24
24
|
// The order of this was specified to preserve existing test coverage. Typically
|