Skip to content

Commit 3e2c845

Browse files
authored
Type conditioned fetching (#2949)
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.
1 parent 4e5f79d commit 3e2c845

File tree

5 files changed

+898
-26
lines changed

5 files changed

+898
-26
lines changed

.changeset/olive-papayas-act.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@apollo/query-planner": patch
3+
---
4+
5+
Type conditioned fetching
6+
7+
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.
8+
9+
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)

gateway-js/src/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
LocalCompose,
5858
} from './supergraphManagers';
5959
import {
60+
assert,
6061
operationFromDocument,
6162
Schema,
6263
ServiceDefinition,
@@ -186,7 +187,7 @@ export class ApolloGateway implements GatewayInterface {
186187
this.pollIntervalInMs = this.config?.pollIntervalInMs;
187188
}
188189

189-
this.issueConfigurationWarningsIfApplicable();
190+
this.validateConfigAndEmitWarnings();
190191

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

216-
private issueConfigurationWarningsIfApplicable() {
217+
private validateConfigAndEmitWarnings() {
218+
assert(!this.config.queryPlannerConfig?.typeConditionedFetching, "Type conditions are not supported in the gateway");
219+
217220
// Warn against using the pollInterval and a serviceList simultaneously
218221
// TODO(trevor:removeServiceList)
219222
if (this.pollIntervalInMs && isServiceListConfig(this.config)) {
@@ -568,6 +571,7 @@ export class ApolloGateway implements GatewayInterface {
568571
this.queryPlanStore.clear();
569572
this.apiSchema = supergraph.apiSchema();
570573
this.schema = addExtensions(this.apiSchema.toGraphQLJSSchema());
574+
571575
this.queryPlanner = new QueryPlanner(supergraph, this.config.queryPlannerConfig);
572576

573577
// Notify onSchemaChange listeners of the updated schema

0 commit comments

Comments
 (0)