Skip to content

Commit

Permalink
Gateway: minimize downstream requests (apollographql/apollo-server#3737)
Browse files Browse the repository at this point in the history
* 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

Apollo-Orig-Commit-AS: apollographql/apollo-server@1bddb63
  • Loading branch information
trevor-scheer committed Jan 31, 2020
1 parent 9bee37b commit 24632ef
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions gateway-js/CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
* Reduce interface expansion for types contained to a single service [#3582](https://github.com/apollographql/apollo-server/pull/3582)
* 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)
* Gateway: minimize downstream request size [#3737](https://github.com/apollographql/apollo-server/pull/3737)

# v0.11.6

Expand Down
2 changes: 1 addition & 1 deletion gateway-js/src/__tests__/executeQueryPlan.test.ts
Expand Up @@ -144,7 +144,7 @@ describe('executeQueryPlan', () => {
);
expect(response).toHaveProperty(
'errors.0.extensions.query',
'{\n me {\n name\n }\n}',
'{me{name}}',
);
expect(response).toHaveProperty('errors.0.extensions.variables', {});
});
Expand Down
6 changes: 1 addition & 5 deletions gateway-js/src/__tests__/gateway/buildService.test.ts
Expand Up @@ -85,11 +85,7 @@ it('correctly passes the context from ApolloServer to datasources', async () =>
expect(fetch).toHaveFetched({
url: 'https://api.example.com/foo',
body: {
query: `{
me {
username
}
}`,
query: `{me{username}}`,
variables: {},
},
headers: {
Expand Down
3 changes: 2 additions & 1 deletion gateway-js/src/executeQueryPlan.ts
Expand Up @@ -14,6 +14,7 @@ import {
TypeNameMetaFieldDef,
VariableDefinitionNode,
GraphQLFieldResolver,
stripIgnoredCharacters,
} from 'graphql';
import { Trace, google } from 'apollo-engine-reporting-protobuf';
import { GraphQLDataSource } from './datasources/types';
Expand Down Expand Up @@ -289,7 +290,7 @@ async function executeFetch<TContext>(
operation: OperationDefinitionNode,
variables: Record<string, any>,
): Promise<ResultMap | void | null> {
const source = print(operation);
const source = stripIgnoredCharacters(print(operation));
// We declare this as 'any' because it is missing url and method, which
// GraphQLRequest.http is supposed to have if it exists.
let http: any;
Expand Down

0 comments on commit 24632ef

Please sign in to comment.