Skip to content

Commit

Permalink
Resolve basic select one queries in OpenDD pipeline (#1481)
Browse files Browse the repository at this point in the history
<!-- The PR description should answer 2 important questions: -->

### What

Stacks on top of #1480 and implements the same, but for "select one"
queries. Behind a feature flag, so this is a functional no-op.

V3_GIT_ORIGIN_REV_ID: 575a149755059a8ad77a986b477452bd32b90a5f
  • Loading branch information
danieljharvey authored and hasura-bot committed Jan 6, 2025
1 parent 9670d5a commit 11f9890
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 104 deletions.
4 changes: 2 additions & 2 deletions v3/crates/engine/tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn test_model_select_one_filter() -> anyhow::Result<()> {
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::YesPlease,
common::TestOpenDDPipeline::Skip,
)
}

Expand Down Expand Up @@ -1111,7 +1111,7 @@ fn test_typename() -> anyhow::Result<()> {
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand Down
132 changes: 67 additions & 65 deletions v3/crates/graphql/frontend/tests/generate_ir/get_by_id/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,80 +100,82 @@
"ir": {
"field_name": "ArticleByID",
"model_selection": {
"data_connector": {
"name": {
"name": "db"
},
"url": {
"singleUrl": "http://localhost:8080/"
},
"headers": {
"hasura-m-auth-token": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~!#$&'()*+,/:;=?@[]\""
},
"capabilities": {
"supported_ndc_version": "V01",
"supports_explaining_queries": true,
"supports_nested_object_filtering": true,
"supports_nested_object_ordering": true,
"supports_aggregates": {},
"supports_query_variables": true,
"supports_relationships": {
"supports_relation_comparisons": true,
"supports_nested_relationships": {
"supports_nested_array_selection": true
"Ir": {
"data_connector": {
"name": {
"name": "db"
},
"url": {
"singleUrl": "http://localhost:8080/"
},
"headers": {
"hasura-m-auth-token": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~!#$&'()*+,/:;=?@[]\""
},
"capabilities": {
"supported_ndc_version": "V01",
"supports_explaining_queries": true,
"supports_nested_object_filtering": true,
"supports_nested_object_ordering": true,
"supports_aggregates": {},
"supports_query_variables": true,
"supports_relationships": {
"supports_relation_comparisons": true,
"supports_nested_relationships": {
"supports_nested_array_selection": true
}
}
}
}
},
"collection": "article",
"arguments": {},
"filter_clause": {
"query_filter": {
"where_clause": null,
"additional_filter": {
"LocalField": {
"BinaryComparison": {
"column": {
"Column": {
"name": "id",
"field_path": []
}
},
"operator": "_eq",
"value": {
"Scalar": {
"value": 1
},
"collection": "article",
"arguments": {},
"filter_clause": {
"query_filter": {
"where_clause": null,
"additional_filter": {
"LocalField": {
"BinaryComparison": {
"column": {
"Column": {
"name": "id",
"field_path": []
}
},
"operator": "_eq",
"value": {
"Scalar": {
"value": 1
}
}
}
}
}
}
},
"permission_filter": null,
"relationship_join_filter": null
},
"limit": null,
"offset": null,
"order_by": null,
"selection": {
"fields": {
"article_id": {
"Column": {
"column": "id",
"nested_selection": null,
"arguments": {}
}
},
"title": {
"Column": {
"column": "title",
"nested_selection": null,
"arguments": {}
"permission_filter": null,
"relationship_join_filter": null
},
"limit": null,
"offset": null,
"order_by": null,
"selection": {
"fields": {
"article_id": {
"Column": {
"column": "id",
"nested_selection": null,
"arguments": {}
}
},
"title": {
"Column": {
"column": "title",
"nested_selection": null,
"arguments": {}
}
}
}
}
},
"aggregate_selection": null
},
"aggregate_selection": null
}
},
"type_container": {
"base": {
Expand Down
54 changes: 50 additions & 4 deletions v3/crates/graphql/ir/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod relationships;
mod selection_set;
mod types;
use crate::query_root::select_many::ModelSelectManySelection;
use crate::query_root::select_one::ModelSelectOneSelection;
use crate::{
ApolloFederationRootFields, MutationRootField, ProcedureBasedCommand, QueryRootField,
SubscriptionRootField, IR,
Expand Down Expand Up @@ -133,8 +134,30 @@ fn plan_subscription<'s, 'ir>(
selection_set,
polling_interval_ms,
} => {
let execution_tree =
model_selection::plan_query_execution(&ir.model_selection, unique_number)?;
let execution_tree = match ir.model_selection {
ModelSelectOneSelection::Ir(ref model_selection) => {
model_selection::plan_query_execution(model_selection, unique_number)
}
ModelSelectOneSelection::OpenDd(ref model_selection) => {
// TODO: expose more specific function in `plan` for just model selections
let (single_node_execution_plan, _) = plan::query_to_plan(
&open_dds::query::Query::Model(model_selection.clone()),
metadata,
session,
request_headers,
unique_number,
)
.unwrap();
match single_node_execution_plan {
plan::SingleNodeExecutionPlan::Query(execution_tree) => Ok(execution_tree),
plan::SingleNodeExecutionPlan::Mutation(_) => {
// we should use a more specific planning function to avoid
// this as it _should not_ happen
Err(error::Error::PlanExpectedQueryGotMutation)
}
}
}
}?;
let query_execution_plan = reject_remote_joins(execution_tree)?;
Ok(SubscriptionSelect {
selection_set,
Expand Down Expand Up @@ -256,8 +279,31 @@ fn plan_query<'n, 's, 'ir>(
schema,
},
QueryRootField::ModelSelectOne { ir, selection_set } => {
let execution_tree =
model_selection::plan_query_execution(&ir.model_selection, unique_number)?;
let execution_tree = match ir.model_selection {
ModelSelectOneSelection::Ir(ref model_selection) => {
model_selection::plan_query_execution(model_selection, unique_number)
}
ModelSelectOneSelection::OpenDd(ref model_selection) => {
// TODO: expose more specific function in `plan` for just model selections
let (single_node_execution_plan, _) = plan::query_to_plan(
&open_dds::query::Query::Model(model_selection.clone()),
metadata,
session,
request_headers,
unique_number,
)
.unwrap();
match single_node_execution_plan {
plan::SingleNodeExecutionPlan::Query(execution_tree) => Ok(execution_tree),
plan::SingleNodeExecutionPlan::Mutation(_) => {
// we should use a more specific planning function to avoid
// this as it _should not_ happen
Err(error::Error::PlanExpectedQueryGotMutation)
}
}
}
}?;

NodeQueryPlan::NDCQueryExecution {
selection_set,
query_execution: NDCQueryExecution {
Expand Down
1 change: 1 addition & 0 deletions v3/crates/graphql/ir/src/query_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ pub fn generate_model_rootfield_ir<'n, 's>(
RootFieldKind::SelectOne => root_field::QueryRootField::ModelSelectOne {
selection_set: &field.selection_set,
ir: select_one::select_one_generate_ir(
request_pipeline,
field,
field_call,
data_type,
Expand Down
Loading

0 comments on commit 11f9890

Please sign in to comment.