graphql-engine/v3/crates/metadata-resolve/tests/failing/aggregate_expressions
Daniel Chambers 0624a7553d Aggregate relationships GraphQL schema and execution (#756)
## Description
This PR implements the GraphQL schema and execution for aggregate
relationships.

In the `schema` crate, the new `model_aggregate_relationship_field`
function handles generating schema for ModelAggregateTarget
relationships. It mostly delegates the meat of its implementation to
reused logic; some refactoring has occurred to make this possible.
This involved changes in `select_many`, `select_aggregate` and
`model_arguments`. The creation of the model arguments field argument
now exists in `model_arguments` and is reused by `select_many` and
`select_aggregate`. The creation of all aggregate field arguments is now
in `select_aggregate::generate_select_aggregate_arguments`, and is then
reused when generating the aggregate relationship field. That field is
annotated with the new `RelationshipToModelAggregate` annotation.

In the `execute` crate, the logic around generating an the aggregate
selection IR was moved from `select_aggregate` into `model_selection`.
This was so it can be reused by the logic in `relationship` that now
uses it to generate an aggregate selection when encountering an
`RelationshipToModelAggregate` field.
Inside `relationship` some rearranging was done so that
`build_local_model_relationship` and `build_remote_relationship` could
work with either a normal model selection IR or the new aggregate
selection IR. The necessitated moving the creation of that IR outside
those functions into the caller, so the different callers can create
different IR (normal vs aggregate IR). This also reduced code
duplication.

New tests have been added to `engine` that cover aggregate relationships
and also remote joined aggregate relationships.

This PR also corrects two bugs in metadata resolve revealed by new
testing:
* The filter input field name in `GraphqlConfig` must be specified if
using an aggregate relationship
* The filter input type name defined on a `Model` must be specified if
that model is the target of an aggregate relationship. Conversely, the
filter input type name can be specified if the `Model` itself doesn't
define an aggregate, but is still involved in a aggregate relationship
(this previously produced an error).

This PR completes the feature, but it is still hidden behind the
experimental flag. There will be a follow up PR to remove that and
expose the functionality by default.

JIRA: [V3ENGINE-160](https://hasurahq.atlassian.net/browse/V3ENGINE-160)

[V3ENGINE-160]:
https://hasurahq.atlassian.net/browse/V3ENGINE-160?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

V3_GIT_ORIGIN_REV_ID: d499371906f7af71a4017c7c3ae75b7693cd3fa7
2024-06-26 09:10:33 +00:00
..
aggregatable_field_agg_exp_type_mismatch Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
aggregatable_field_not_found Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
aggregation_function_return_array_type_mismatch_to_named Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
aggregation_function_return_named_type_mismatch_to_array Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
aggregation_function_return_nullability_mismatch_with_data_connector Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
aggregation_function_return_object_missing_mapping Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
aggregation_function_return_type_repr_mismatch Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
conflict_between_count_and_aggregatable_field Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
conflict_between_count_and_aggregation_function Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
conflict_between_count_distinct_and_aggregatable_field Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
conflict_between_count_distinct_and_aggregation_function Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
data_connector_function_return_not_a_scalar Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
data_connector_lacks_aggregates_capability Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
data_connector_lacks_nested_fields_aggregates_capability Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
disallow_count_distinct_on_models Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
disallow_duplicate_graphql_select_type_name Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
disallow_duplicate_model_filter_input_type_name Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
disallow_duplicate_name Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
disallow_model_filter_input_type_without_aggregate_expression Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
disallow_multiple_nested_array_agg Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
duplicated_aggregatable_fields Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
duplicated_aggregation_functions Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_aggregate_exp_from_model Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_aggregate_graphql_config Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_aggregation_function_data_connector Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_aggregation_function_data_connector_function Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_aggregation_function_data_connector_mapping Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_aggregation_function_data_connector_operand_type Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_aggregation_function_mappings_to_model_data_connector Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_aggregation_function_return_type Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_data_connector_scalar_type_repr Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_filter_input_field_name_in_graphql_config Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_model_filter_input_field_type Aggregate relationships GraphQL schema and execution (#756) 2024-06-26 09:10:33 +00:00
missing_model_source Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_operand_object_field_agg_exp Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_operand_object_type Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
missing_operand_scalar_type Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00
model_aggregate_exp_type_mismatch Take snapshots of passing and failing metadata resolution. (#763) 2024-06-26 08:15:29 +00:00