Skip to content
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

feat(federation): sketch a query completeness correctness check #6231

Closed
wants to merge 11 commits into from
43 changes: 43 additions & 0 deletions apollo-federation/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ enum Command {
#[command(flatten)]
planner: QueryPlannerArgs,
},
/// Plan and test a query.
PlanCheck {
query: PathBuf,
/// Path(s) to one supergraph schema file, `-` for stdin or multiple subgraph schemas.
schemas: Vec<PathBuf>,
#[command(flatten)]
planner: QueryPlannerArgs,
},
}

impl QueryPlannerArgs {
Expand Down Expand Up @@ -154,6 +162,11 @@ fn main() -> ExitCode {
operations_dir,
planner,
} => cmd_bench(&supergraph_schema, &operations_dir, planner),
Command::PlanCheck {
query,
schemas,
planner,
} => cmd_plan_correctness(&query, &schemas, planner),
};
match result {
Err(error) => {
Expand Down Expand Up @@ -321,6 +334,36 @@ fn cmd_bench(
Ok(())
}

fn cmd_plan_correctness(
query_path: &Path,
schema_paths: &[PathBuf],
planner: QueryPlannerArgs,
) -> Result<(), FederationError> {
let query = read_input(query_path);
let supergraph = load_supergraph(schema_paths)?;
let query_doc =
ExecutableDocument::parse_and_validate(supergraph.schema.schema(), query, query_path)?;
let config = QueryPlannerConfig::from(planner);

println!("supergraph paths");
println!("================");
let supergraph_paths = apollo_federation::correctness::supergraph_query_paths(
&supergraph.schema,
&query_doc,
None,
)?;

let planner = QueryPlanner::new(&supergraph, config)?;
let plan = planner.build_query_plan(&query_doc, None)?;

println!("plan paths");
println!("==========");
let plan_paths = apollo_federation::correctness::query_plan_paths(&supergraph.schema, &plan)?;
apollo_federation::correctness::compare_paths(&supergraph_paths, &plan_paths)?;

Ok(())
}

#[test]
fn test_bench() {
insta::assert_json_snapshot!(
Expand Down
Loading
Loading