Skip to content

feat: Query planner skips fetches when possible (based on @skip and @include usages #1113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 2, 2021
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { QueryPlan, PlanNode } from '@apollo/query-planner';
import { shouldSkipFetchNode } from '@apollo/gateway/src/executeQueryPlan';
import { astSerializer, queryPlanSerializer } from '../snapshotSerializers';
const prettyFormat = require('pretty-format');

Expand All @@ -10,15 +11,6 @@ declare global {
}
}

// function printNode(node: ExecutionNode) {
// return prettyFormat(
// { nodes: [node], kind: 'QueryPlan' },
// {
// plugins: [queryPlanSerializer, astSerializer],
// },
// );
// }

const lineEndRegex = /^/gm;
function indentString(string: string, count = 2) {
if (!string) return string;
Expand All @@ -27,11 +19,11 @@ function indentString(string: string, count = 2) {

function toCallService(
this: jest.MatcherUtils,
queryPlan: QueryPlan,
input: QueryPlan | { queryPlan: QueryPlan, variables: Record<string, any> },
service: string,
): { message(): string; pass: boolean } {
// const receivedString = print(received);
// const expectedString = print(expected);
const { queryPlan, variables } =
'kind' in input ? { queryPlan: input, variables: {} } : input;

const printReceived = (string: string) =>
this.utils.RECEIVED_COLOR(indentString(string));
Expand All @@ -44,7 +36,7 @@ function toCallService(
function walkExecutionNode(node?: PlanNode) {
if (!node) return;
if (node.kind === 'Fetch' && node.serviceName === service) {
pass = true;
pass = !shouldSkipFetchNode(node, variables);
// initialServiceCall = node;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,11 +932,9 @@ it('composition of full-SDL schemas without any errors', () => {
) on FIELD_DEFINITION | ENUM_VALUE
directive @specifiedBy(url: String!) on SCALAR
directive @include(
if: String = "Included when true."
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
directive @skip(
if: String = "Skipped when true."
if: Boolean
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
directive @skip(if: Boolean) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

# Federation directives
directive @key(fields: _FieldSet!) repeatable on OBJECT | INTERFACE
Expand Down
2 changes: 1 addition & 1 deletion gateway-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.

- _Nothing yet. Stay tuned._
- Skip fetches when possible (based on @skip and @include usages). The query planner now aggregates top-level skip and include usages, which allows the gateway to skip `FetchNode`s altogether when possible during execution. [PR #1113](https://github.com/apollographql/federation/pull/1113)

## v0.42.1

Expand Down
Loading