Skip to content

Commit

Permalink
Enable progressive override in router-bridge (#437)
Browse files Browse the repository at this point in the history
`buildQueryPlan` now accepts an options object currently consisting of
an optional Map of overridden labels to enable progressive override.
This set of changes will enable the router to propagate these options
through to the query planner.

TODO:
- [x] Release v2.7 fed components and update package file to use npm
published versions
  • Loading branch information
trevor-scheer authored Jan 24, 2024
1 parent a0d7b4a commit 170bc39
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 29 deletions.
3 changes: 2 additions & 1 deletion federation-2/router-bridge/benches/query_planning.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;
use router_bridge::planner::PlanOptions;
use router_bridge::planner::Planner;
use router_bridge::planner::QueryPlannerConfig;

Expand All @@ -19,7 +20,7 @@ fn from_elem(c: &mut Criterion) {

b.to_async(runtime).iter(|| async {
planner
.plan(QUERY.to_string(), None)
.plan(QUERY.to_string(), None, PlanOptions::default())
.await
.unwrap()
.into_result()
Expand Down
23 changes: 20 additions & 3 deletions federation-2/router-bridge/js-src/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export interface QueryPlanResult {
queryPlan: QueryPlan;
}

export interface PlanOptions {
// We receive these across the bridge as an array of strings,
// but ultimately build a Map object out of it for use in the planner.
overrideConditions?: string[];
}

export class BridgeQueryPlanner {
private readonly supergraph: Supergraph;
private readonly apiSchema: GraphQLSchema;
Expand All @@ -72,7 +78,8 @@ export class BridgeQueryPlanner {

plan(
operationString: string,
providedOperationName?: string
providedOperationName?: string,
options?: PlanOptions
): ExecutionResultWithUsageReporting<QueryPlanResult> {
let operationResult = this.operation(
operationString,
Expand All @@ -87,8 +94,18 @@ export class BridgeQueryPlanner {
let usageReporting = operationResult.usageReporting;
let operation = operationResult.data;
const operationName = operation?.name;

const queryPlan = this.planner.buildQueryPlan(operation);
const buildQueryPlanOptions = options
? {
overrideConditions: new Map(
options.overrideConditions.map((override) => [override, true])
),
}
: undefined;

const queryPlan = this.planner.buildQueryPlan(
operation,
buildQueryPlanOptions
);
let formattedQueryPlan: string | null;
try {
formattedQueryPlan = prettyFormatQueryPlan(queryPlan);
Expand Down
4 changes: 3 additions & 1 deletion federation-2/router-bridge/js-src/plan_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ASTNode, Source, SourceLocation, ExecutionResult } from "graphql";
import {
BridgeQueryPlanner,
ExecutionResultWithUsageReporting,
PlanOptions,
QueryPlanResult,
} from "./plan";
import { QueryPlannerConfigExt } from "./types";
Expand Down Expand Up @@ -45,6 +46,7 @@ interface PlanEvent {
query: string;
operationName?: string;
schemaId: number;
options?: PlanOptions;
}
interface ApiSchemaEvent {
kind: PlannerEventKind.ApiSchema;
Expand Down Expand Up @@ -258,7 +260,7 @@ async function run() {
case PlannerEventKind.Plan:
const planResult = planners
.get(event.schemaId)
.plan(event.query, event.operationName);
.plan(event.query, event.operationName, event.options);
await send({ id, payload: planResult });
break;
case PlannerEventKind.ApiSchema:
Expand Down
Loading

0 comments on commit 170bc39

Please sign in to comment.