Skip to content

Commit

Permalink
Type conditioned fetching (#2949)
Browse files Browse the repository at this point in the history
Type conditioned fetching

Fixes #2938
When querying a field that is in a path of 2 or more unions, the query
planner was not able to handle different selections and would
aggressively collapse selections in fetches yielding an incorrect plan.

This change introduces new syntax to express type conditions in (key and
flatten) paths. Type conditioned fetching can be enabled through a flag,
and execution is supported in the router only.
  • Loading branch information
o0Ignition0o authored Apr 12, 2024
1 parent 4e5f79d commit 3e2c845
Show file tree
Hide file tree
Showing 5 changed files with 898 additions and 26 deletions.
9 changes: 9 additions & 0 deletions .changeset/olive-papayas-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@apollo/query-planner": patch
---

Type conditioned fetching

When querying a field that is in a path of 2 or more unions, the query planner was not able to handle different selections and would aggressively collapse selections in fetches yielding an incorrect plan.

This change introduces new syntax to express type conditions in (key and flatten) paths. Type conditioned fetching can be enabled through a flag, and execution is supported in the router only. (#2938)
8 changes: 6 additions & 2 deletions gateway-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
LocalCompose,
} from './supergraphManagers';
import {
assert,
operationFromDocument,
Schema,
ServiceDefinition,
Expand Down Expand Up @@ -186,7 +187,7 @@ export class ApolloGateway implements GatewayInterface {
this.pollIntervalInMs = this.config?.pollIntervalInMs;
}

this.issueConfigurationWarningsIfApplicable();
this.validateConfigAndEmitWarnings();

this.logger.debug('Gateway successfully initialized (but not yet loaded)');
this.state = { phase: 'initialized' };
Expand All @@ -213,7 +214,9 @@ export class ApolloGateway implements GatewayInterface {
});
}

private issueConfigurationWarningsIfApplicable() {
private validateConfigAndEmitWarnings() {
assert(!this.config.queryPlannerConfig?.typeConditionedFetching, "Type conditions are not supported in the gateway");

// Warn against using the pollInterval and a serviceList simultaneously
// TODO(trevor:removeServiceList)
if (this.pollIntervalInMs && isServiceListConfig(this.config)) {
Expand Down Expand Up @@ -568,6 +571,7 @@ export class ApolloGateway implements GatewayInterface {
this.queryPlanStore.clear();
this.apiSchema = supergraph.apiSchema();
this.schema = addExtensions(this.apiSchema.toGraphQLJSSchema());

this.queryPlanner = new QueryPlanner(supergraph, this.config.queryPlannerConfig);

// Notify onSchemaChange listeners of the updated schema
Expand Down
Loading

0 comments on commit 3e2c845

Please sign in to comment.