Skip to content

Commit 1bddb63

Browse files
Gateway: minimize downstream requests (#3737)
* Minimize downstream requests Use graphql-js's `stripIgnoredCharacters` utility to minimize query body size over the wire from the gateway to downstream services. * Update changelog
1 parent 2562d09 commit 1bddb63

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

packages/apollo-gateway/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
* Reduce interface expansion for types contained to a single service [#3582](https://github.com/apollographql/apollo-server/pull/3582)
88
* Instantiate one `CachedFetcher` per gateway instance. This resolves a condition where multiple federated gateways would utilize the same cache store could result in an `Expected undefined to be a GraphQLSchema` error. [#3704](https://github.com/apollographql/apollo-server/pull/3704)
9+
* Gateway: minimize downstream request size [#3737](https://github.com/apollographql/apollo-server/pull/3737)
910

1011
# v0.11.6
1112

packages/apollo-gateway/src/__tests__/executeQueryPlan.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('executeQueryPlan', () => {
144144
);
145145
expect(response).toHaveProperty(
146146
'errors.0.extensions.query',
147-
'{\n me {\n name\n }\n}',
147+
'{me{name}}',
148148
);
149149
expect(response).toHaveProperty('errors.0.extensions.variables', {});
150150
});

packages/apollo-gateway/src/__tests__/gateway/buildService.test.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ it('correctly passes the context from ApolloServer to datasources', async () =>
8585
expect(fetch).toHaveFetched({
8686
url: 'https://api.example.com/foo',
8787
body: {
88-
query: `{
89-
me {
90-
username
91-
}
92-
}`,
88+
query: `{me{username}}`,
9389
variables: {},
9490
},
9591
headers: {

packages/apollo-gateway/src/executeQueryPlan.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
TypeNameMetaFieldDef,
1515
VariableDefinitionNode,
1616
GraphQLFieldResolver,
17+
stripIgnoredCharacters,
1718
} from 'graphql';
1819
import { Trace, google } from 'apollo-engine-reporting-protobuf';
1920
import { GraphQLDataSource } from './datasources/types';
@@ -289,7 +290,7 @@ async function executeFetch<TContext>(
289290
operation: OperationDefinitionNode,
290291
variables: Record<string, any>,
291292
): Promise<ResultMap | void | null> {
292-
const source = print(operation);
293+
const source = stripIgnoredCharacters(print(operation));
293294
// We declare this as 'any' because it is missing url and method, which
294295
// GraphQLRequest.http is supposed to have if it exists.
295296
let http: any;

0 commit comments

Comments
 (0)