Skip to content

Commit

Permalink
OpenDd execution: Implement order by for model and relationship selec…
Browse files Browse the repository at this point in the history
…tion in GraphQL frontend (#1550)

### What

Implement order by input argument resolution for model (select_many and
select_aggregate) and relationship selection in GraphQL for openDd IR
conversion.

V3_GIT_ORIGIN_REV_ID: a20dacf611ecaa2b86439392f6e97884a8dba5b3
  • Loading branch information
rakeshkky authored and hasura-bot committed Jan 20, 2025
1 parent 324f867 commit 55cb567
Show file tree
Hide file tree
Showing 13 changed files with 451 additions and 69 deletions.
22 changes: 11 additions & 11 deletions v3/crates/engine/tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ fn test_model_select_many_order_by() -> anyhow::Result<()> {
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand All @@ -239,7 +239,7 @@ fn test_model_select_many_order_by_with_model_v2() -> anyhow::Result<()> {
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand All @@ -250,7 +250,7 @@ fn test_model_select_many_order_by_nested() -> anyhow::Result<()> {
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand All @@ -272,7 +272,7 @@ fn test_model_select_many_order_by_nested_legacy() -> anyhow::Result<()> {
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand All @@ -283,7 +283,7 @@ fn test_model_select_many_order_by_filter() -> anyhow::Result<()> {
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand All @@ -295,7 +295,7 @@ fn test_model_select_many_order_by_with_graphql_config() -> anyhow::Result<()> {
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string, metadata_graphql_json],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand All @@ -313,7 +313,7 @@ fn test_model_select_many_order_by_multiple_columns() -> anyhow::Result<()> {
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand All @@ -324,7 +324,7 @@ fn test_model_select_many_order_by_multiple_columns_validation_check() -> anyhow
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand All @@ -337,7 +337,7 @@ fn test_model_select_many_order_by_multiple_nested_columns_validation_check() ->
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand All @@ -349,7 +349,7 @@ fn test_model_select_many_type_permission_order_by() -> anyhow::Result<()> {
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

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

Expand Down
4 changes: 2 additions & 2 deletions v3/crates/engine/tests/relationship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn test_local_relationships_model_to_model_array_with_arguments() -> anyhow::Res
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand All @@ -77,7 +77,7 @@ fn test_relationships_array_with_arguments_with_graphql_config() -> anyhow::Resu
common::test_execution_expectation(
test_path_string,
&[common_metadata_path_string, common_metadata_graphql_config],
common::TestOpenDDPipeline::Skip,
common::TestOpenDDPipeline::YesPlease,
)
}

Expand Down
15 changes: 15 additions & 0 deletions v3/crates/graphql/ir/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ pub fn generate_command_info<'n, 's>(
/// Generates the OpenDD IR for a 'command' operation
#[allow(irrefutable_let_patterns)]
pub fn generate_command_info_open_dd<'n, 's>(
models: &'s IndexMap<
metadata_resolve::Qualified<open_dds::models::ModelName>,
metadata_resolve::ModelWithPermissions,
>,
command_name: &Qualified<commands::CommandName>,
field: &'n normalized_ast::Field<'s, GDS>,
field_call: &'n normalized_ast::FieldCall<'s, GDS>,
Expand Down Expand Up @@ -218,6 +222,7 @@ pub fn generate_command_info_open_dd<'n, 's>(
result_type,
result_base_type_kind,
metadata_resolve::FieldNestedness::NotNested,
models,
&command_source.type_mappings,
selection_set::NestedSelectionType::CommandRootSelection,
field,
Expand Down Expand Up @@ -336,6 +341,10 @@ pub fn generate_function_based_command<'n, 's>(

/// Generates the OpenDD IR for a 'function based command' operation
pub fn generate_function_based_command_open_dd<'n, 's>(
models: &'s IndexMap<
metadata_resolve::Qualified<open_dds::models::ModelName>,
metadata_resolve::ModelWithPermissions,
>,
command_name: &Qualified<commands::CommandName>,
function_name: &'s open_dds::commands::FunctionName,
field: &'n normalized_ast::Field<'s, GDS>,
Expand All @@ -348,6 +357,7 @@ pub fn generate_function_based_command_open_dd<'n, 's>(
usage_counts: &mut UsagesCounts,
) -> Result<FunctionBasedCommand<'s>, error::Error> {
let command_info = generate_command_info_open_dd(
models,
command_name,
field,
field_call,
Expand Down Expand Up @@ -417,6 +427,10 @@ pub fn generate_procedure_based_command<'n, 's>(

/// Generates the OpenDD IR for a 'procedure based command' operation
pub fn generate_procedure_based_command_open_dd<'n, 's>(
models: &'s IndexMap<
metadata_resolve::Qualified<open_dds::models::ModelName>,
metadata_resolve::ModelWithPermissions,
>,
command_name: &Qualified<commands::CommandName>,
procedure_name: &'s open_dds::commands::ProcedureName,
field: &'n normalized_ast::Field<'s, GDS>,
Expand All @@ -430,6 +444,7 @@ pub fn generate_procedure_based_command_open_dd<'n, 's>(
let mut usage_counts = UsagesCounts::new();

let command_info = generate_command_info_open_dd(
models,
command_name,
field,
field_call,
Expand Down
19 changes: 7 additions & 12 deletions v3/crates/graphql/ir/src/model_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ struct FilterInputArguments<'s> {
pub fn model_selection_open_dd_ir(
selection_set: &normalized_ast::SelectionSet<'_, GDS>,
model_name: &Qualified<ModelName>,
models: &IndexMap<
metadata_resolve::Qualified<open_dds::models::ModelName>,
metadata_resolve::ModelWithPermissions,
>,
type_mappings: &BTreeMap<
metadata_resolve::Qualified<CustomTypeName>,
metadata_resolve::TypeMapping,
>,
model_arguments: Option<IndexMap<open_dds::query::ArgumentName, open_dds::query::Value>>,
where_clause: Option<open_dds::query::BooleanExpression>,
order_by: Vec<open_dds::query::OrderByElement>,
limit: Option<u32>,
offset: Option<u32>,
session_variables: &SessionVariables,
Expand All @@ -86,6 +91,7 @@ pub fn model_selection_open_dd_ir(
let selection = selection_set::generate_selection_set_open_dd_ir(
selection_set,
metadata_resolve::FieldNestedness::NotNested,
models,
type_mappings,
session_variables,
request_headers,
Expand All @@ -107,12 +113,6 @@ pub fn model_selection_open_dd_ir(
// TODO: append select permissions etc
let filter = where_clause;

// MADE UP EMPTY VALUES TO GET THINGS STARTED
// TODO: these will be replaced with correct values as we go
let order_by = vec![];

// END OF MADE UP VALUES

let target = open_dds::query::ModelTarget {
subgraph: model_name.subgraph.clone(),
model_name: model_name.name.clone(),
Expand All @@ -135,6 +135,7 @@ pub fn model_aggregate_selection_open_dd_ir<'s>(
model_name: &Qualified<ModelName>,
model_arguments: Option<IndexMap<open_dds::query::ArgumentName, open_dds::query::Value>>,
where_clause: Option<open_dds::query::BooleanExpression>,
order_by: Vec<open_dds::query::OrderByElement>,
limit: Option<u32>,
offset: Option<u32>,
usage_counts: &mut UsagesCounts,
Expand All @@ -158,12 +159,6 @@ pub fn model_aggregate_selection_open_dd_ir<'s>(
// TODO: append select permissions etc
let filter = where_clause;

// MADE UP EMPTY VALUES TO GET THINGS STARTED
// TODO: these will be replaced with correct values as we go
let order_by = vec![];

// END OF MADE UP VALUES

let target = open_dds::query::ModelTarget {
subgraph: model_name.subgraph.clone(),
model_name: model_name.name.clone(),
Expand Down
1 change: 1 addition & 0 deletions v3/crates/graphql/ir/src/mutation_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub fn generate_ir<'n, 's>(
}
GraphqlRequestPipeline::OpenDd => {
commands::generate_procedure_based_command_open_dd(
&metadata.models,
name,
procedure_name,
field,
Expand Down
Loading

0 comments on commit 55cb567

Please sign in to comment.