From 9eaabd116fb3bc7297bf2f4e00fae2d08afce879 Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Tue, 23 Jul 2024 13:41:47 +0530 Subject: [PATCH] fix: generate relationship definition for nested selection (#855) ### What Previously, while generating relationship definitions for NDC, we would ignore columns with nested selection. This PR fixes that. Closes https://hasurahq.atlassian.net/browse/V3ENGINE-247 ### How While matching on `FieldSelection::Column`, don't ignore it. Check if it contains nested selection, if it does, call `collect_relationships_from_nested_selection` V3_GIT_ORIGIN_REV_ID: 9db94744d8e2d35f8430bded07209ef519175205 --- v3/changelog.md | 8 +- v3/crates/custom-connector/data/actors.json | 1 + .../command_argument_presets/expected.json | 5 + .../expected.json | 5 + .../multiple_arguments/expected.json | 10 + .../command_permissions/expected.json | 10 + .../output_permissions/expected.json | 5 + .../command_permissions/expected.json | 10 + .../output_permissions/expected.json | 5 + .../scalar_array_output_type/expected.json | 2 + .../nested_select/relationship/expected.json | 93 ++++++++++ .../nested_select/relationship/metadata.json | 171 ++++++++++++++++++ .../nested_select/relationship/request.gql | 24 +++ .../relationship/session_variables.json | 3 + .../across_namespace/expected.json | 9 + .../across_namespace/expected.json | 24 +++ .../command_to_model/expected.json | 24 +++ .../model_to_command/expected.json | 8 + .../command/remote_in_local/expected.json | 7 + .../multi_field_mapping/expected.json | 6 + .../mutually_recursive/expected.json | 6 + .../remote_in_local/expected.json | 31 ++++ .../custom_ndc_and_pg_ndc/expected.json | 27 +++ v3/crates/engine/tests/execution.rs | 11 ++ v3/crates/execute/src/plan/relationships.rs | 15 +- 25 files changed, 516 insertions(+), 4 deletions(-) create mode 100644 v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/expected.json create mode 100644 v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/metadata.json create mode 100644 v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/request.gql create mode 100644 v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/session_variables.json diff --git a/v3/changelog.md b/v3/changelog.md index 9ef48f76a813c..43e0f8e09557b 100644 --- a/v3/changelog.md +++ b/v3/changelog.md @@ -6,6 +6,10 @@ ### Fixed +- Fixes a bug where relationships within nested columns would throw an internal + error. While generating NDC relationship definitions, engine would ignore + columns with nested selection. + - Renamed the `ArgumentPreset` for data connectors to `DataConnectorArgumentPreset` to avoid ambiguity in generated JSONSchema. @@ -56,9 +60,9 @@ your GraphQL queries more versatile and powerful. - Build-time check to ensure boolean expressions cannot be built over nested array fields until these are supported. -- Fixed a bug where command targeted relationships were not using the Open DD +- Fixed a bug where command targeted relationships were not using the OpenDD argument name instead of the data connector's argument name when querying the - data connector + data connector. ## [v2024.07.10] diff --git a/v3/crates/custom-connector/data/actors.json b/v3/crates/custom-connector/data/actors.json index c4c6f8802f587..991b836eb7b0f 100644 --- a/v3/crates/custom-connector/data/actors.json +++ b/v3/crates/custom-connector/data/actors.json @@ -1,3 +1,4 @@ +{"id":0,"name":"Peter","movie_id":2,"favourite_author_id":1} {"id":1,"name":"Leonardo DiCaprio","movie_id":1,"favourite_author_id":1} {"id":2,"name":"Kate Winslet","movie_id":1,"favourite_author_id":2} {"id":3,"name":"Irfan Khan","movie_id":2,"favourite_author_id":1} diff --git a/v3/crates/engine/tests/execute/commands/functions/command_argument_presets/expected.json b/v3/crates/engine/tests/execute/commands/functions/command_argument_presets/expected.json index f9d2a35bfb20d..4f12071573fa5 100644 --- a/v3/crates/engine/tests/execute/commands/functions/command_argument_presets/expected.json +++ b/v3/crates/engine/tests/execute/commands/functions/command_argument_presets/expected.json @@ -2,6 +2,11 @@ { "data": { "getActorsByMovieIdBounds": [ + { + "actor_id": 0, + "movie_id": 2, + "name": "Peter" + }, { "actor_id": 3, "movie_id": 2, diff --git a/v3/crates/engine/tests/execute/commands/functions/model_argument_presets_select_many/expected.json b/v3/crates/engine/tests/execute/commands/functions/model_argument_presets_select_many/expected.json index 4ca75a0065ed0..865e09acf3484 100644 --- a/v3/crates/engine/tests/execute/commands/functions/model_argument_presets_select_many/expected.json +++ b/v3/crates/engine/tests/execute/commands/functions/model_argument_presets_select_many/expected.json @@ -18,6 +18,11 @@ { "data": { "ActorsByMovieMany": [ + { + "actor_id": 0, + "movie_id": 2, + "name": "Peter" + }, { "actor_id": 3, "movie_id": 2, diff --git a/v3/crates/engine/tests/execute/commands/functions/multiple_arguments/expected.json b/v3/crates/engine/tests/execute/commands/functions/multiple_arguments/expected.json index aaa54c0e672f9..80bca138073b6 100644 --- a/v3/crates/engine/tests/execute/commands/functions/multiple_arguments/expected.json +++ b/v3/crates/engine/tests/execute/commands/functions/multiple_arguments/expected.json @@ -2,6 +2,11 @@ { "data": { "getActorsByMovieIdBounds": [ + { + "actor_id": 0, + "movie_id": 2, + "name": "Peter" + }, { "actor_id": 3, "movie_id": 2, @@ -28,6 +33,11 @@ { "data": { "getActorsByMovieIdBounds": [ + { + "actor_id": 0, + "movie_id": 2, + "name": "Peter" + }, { "actor_id": 3, "movie_id": 2, diff --git a/v3/crates/engine/tests/execute/commands/functions/object_array_output_type/command_permissions/expected.json b/v3/crates/engine/tests/execute/commands/functions/object_array_output_type/command_permissions/expected.json index 397152119e063..2f5342a6bc796 100644 --- a/v3/crates/engine/tests/execute/commands/functions/object_array_output_type/command_permissions/expected.json +++ b/v3/crates/engine/tests/execute/commands/functions/object_array_output_type/command_permissions/expected.json @@ -2,6 +2,11 @@ { "data": { "getAllActors": [ + { + "actor_id": 0, + "name": "Peter", + "movie_id": 2 + }, { "actor_id": 1, "name": "Leonardo DiCaprio", @@ -43,6 +48,11 @@ { "data": { "getAllActors": [ + { + "actor_id": 0, + "name": "Peter", + "movie_id": 2 + }, { "actor_id": 1, "name": "Leonardo DiCaprio", diff --git a/v3/crates/engine/tests/execute/commands/functions/object_array_output_type/output_permissions/expected.json b/v3/crates/engine/tests/execute/commands/functions/object_array_output_type/output_permissions/expected.json index 2fbf80a741be1..510de6df5b670 100644 --- a/v3/crates/engine/tests/execute/commands/functions/object_array_output_type/output_permissions/expected.json +++ b/v3/crates/engine/tests/execute/commands/functions/object_array_output_type/output_permissions/expected.json @@ -2,6 +2,11 @@ { "data": { "getAllActors": [ + { + "actor_id": 0, + "name": "Peter", + "movie_id": 2 + }, { "actor_id": 1, "name": "Leonardo DiCaprio", diff --git a/v3/crates/engine/tests/execute/commands/procedures/object_array_output_type/command_permissions/expected.json b/v3/crates/engine/tests/execute/commands/procedures/object_array_output_type/command_permissions/expected.json index 6e305ae76cf45..0e53ee8c2290c 100644 --- a/v3/crates/engine/tests/execute/commands/procedures/object_array_output_type/command_permissions/expected.json +++ b/v3/crates/engine/tests/execute/commands/procedures/object_array_output_type/command_permissions/expected.json @@ -2,6 +2,11 @@ { "data": { "uppercaseAllActorNames": [ + { + "actor_id": 0, + "movie_id": 2, + "name": "PETER" + }, { "actor_id": 1, "movie_id": 1, @@ -43,6 +48,11 @@ { "data": { "uppercaseAllActorNames": [ + { + "actor_id": 0, + "movie_id": 2, + "name": "PETER" + }, { "actor_id": 1, "movie_id": 1, diff --git a/v3/crates/engine/tests/execute/commands/procedures/object_array_output_type/output_permissions/expected.json b/v3/crates/engine/tests/execute/commands/procedures/object_array_output_type/output_permissions/expected.json index e8e465c6d8c3b..b875d21ecbc40 100644 --- a/v3/crates/engine/tests/execute/commands/procedures/object_array_output_type/output_permissions/expected.json +++ b/v3/crates/engine/tests/execute/commands/procedures/object_array_output_type/output_permissions/expected.json @@ -2,6 +2,11 @@ { "data": { "uppercaseAllActorNames": [ + { + "actor_id": 0, + "movie_id": 2, + "name": "PETER" + }, { "actor_id": 1, "movie_id": 1, diff --git a/v3/crates/engine/tests/execute/commands/procedures/scalar_array_output_type/expected.json b/v3/crates/engine/tests/execute/commands/procedures/scalar_array_output_type/expected.json index f2fb600154253..a6de7dbfe80b8 100644 --- a/v3/crates/engine/tests/execute/commands/procedures/scalar_array_output_type/expected.json +++ b/v3/crates/engine/tests/execute/commands/procedures/scalar_array_output_type/expected.json @@ -2,6 +2,7 @@ { "data": { "uppercaseAllActorNamesReturnNames": [ + "PETER", "LEONARDO DICAPRIO", "KATE WINSLET", "IRFAN KHAN", @@ -15,6 +16,7 @@ { "data": { "uppercaseAllActorNamesReturnNames": [ + "PETER", "LEONARDO DICAPRIO", "KATE WINSLET", "IRFAN KHAN", diff --git a/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/expected.json b/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/expected.json new file mode 100644 index 0000000000000..da016f55b9a74 --- /dev/null +++ b/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/expected.json @@ -0,0 +1,93 @@ +{ + "data": { + "InstitutionMany": [ + { + "id": 1, + "location": { + "city": "London", + "campuses": [ + "Mile End", + "Whitechapel", + "Charterhouse Square", + "West Smithfield" + ] + }, + "location_country": { + "country": "UK" + }, + "staff": [ + { + "last_name": "Landin", + "specialities": ["Computer Science", "Education"], + "actor": { + "name": "Peter" + } + } + ], + "staff_first_name": [ + { + "first_name": "Peter" + } + ], + "departments": [ + "Humanities and Social Sciences", + "Science and Engineering", + "Medicine and Dentistry" + ] + }, + { + "id": 2, + "location": { + "city": "Gothenburg", + "campuses": ["Johanneberg", "Lindholmen"] + }, + "location_country": { + "country": "Sweden" + }, + "staff": [ + { + "last_name": "Hughes", + "specialities": [ + "Computer Science", + "Functional Programming", + "Software Testing" + ], + "actor": null + }, + { + "last_name": "Claessen", + "specialities": [ + "Computer Science", + "Functional Programming", + "Automated Reasoning" + ], + "actor": null + } + ], + "staff_first_name": [ + { + "first_name": "John" + }, + { + "first_name": "Koen" + } + ], + "departments": [ + "Architecture and Civil Engineering", + "Computer Science and Engineering", + "Electrical Engineering", + "Physics", + "Industrial and Materials Science" + ] + }, + { + "id": 3, + "location": null, + "location_country": null, + "staff": null, + "staff_first_name": null, + "departments": ["nothing", null] + } + ] + } +} diff --git a/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/metadata.json b/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/metadata.json new file mode 100644 index 0000000000000..807ccccd528d6 --- /dev/null +++ b/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/metadata.json @@ -0,0 +1,171 @@ +{ + "version": "v2", + "subgraphs": [ + { + "name": "default", + "objects": [ + { + "kind": "ObjectType", + "version": "v1", + "definition": { + "name": "actor", + "fields": [ + { + "name": "actor_id", + "type": "Int!" + }, + { + "name": "name", + "type": "String!" + }, + { + "name": "movie_id", + "type": "Int!" + } + ], + "graphql": { + "typeName": "Actor" + }, + "dataConnectorTypeMapping": [ + { + "dataConnectorName": "custom", + "dataConnectorObjectType": "actor", + "fieldMapping": { + "actor_id": { + "column": { + "name": "id" + } + }, + "name": { + "column": { + "name": "name" + } + }, + "movie_id": { + "column": { + "name": "movie_id" + } + } + } + } + ] + } + }, + { + "kind": "TypePermissions", + "version": "v1", + "definition": { + "typeName": "actor", + "permissions": [ + { + "role": "admin", + "output": { + "allowedFields": ["actor_id", "name", "movie_id"] + } + }, + { + "role": "user", + "output": { + "allowedFields": ["actor_id", "name", "movie_id"] + } + } + ] + } + }, + { + "kind": "Model", + "version": "v1", + "definition": { + "name": "Actors", + "objectType": "actor", + "source": { + "dataConnectorName": "custom", + "collection": "actors" + }, + "graphql": { + "selectUniques": [], + "selectMany": { + "queryRootField": "ActorMany" + } + }, + "orderableFields": [ + { + "fieldName": "actor_id", + "orderByDirections": { + "enableAll": true + } + }, + { + "fieldName": "name", + "orderByDirections": { + "enableAll": true + } + }, + { + "fieldName": "movie_id", + "orderByDirections": { + "enableAll": true + } + } + ] + } + }, + { + "kind": "ModelPermissions", + "version": "v1", + "definition": { + "modelName": "Actors", + "permissions": [ + { + "role": "admin", + "select": { + "filter": null + } + }, + { + "role": "user", + "select": { + "filter": null + } + } + ] + } + }, + { + "kind": "Relationship", + "version": "v1", + "definition": { + "name": "actor", + "sourceType": "staff_member", + "target": { + "model": { + "name": "Actors", + "subgraph": "default", + "relationshipType": "Object" + } + }, + "mapping": [ + { + "source": { + "fieldPath": [ + { + "fieldName": "first_name" + } + ] + }, + "target": { + "modelField": [ + { + "fieldName": "name" + } + ] + } + } + ], + "description": "Random mapping of a staff member to an actor" + } + } + ] + } + ] +} diff --git a/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/request.gql b/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/request.gql new file mode 100644 index 0000000000000..6736f606776bd --- /dev/null +++ b/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/request.gql @@ -0,0 +1,24 @@ +query RelationshipInNestedObject { + InstitutionMany { + id + location { + city + campuses + } + location_country: location { + country + } + staff { + last_name + specialities + # nested object -> relationship + actor { + name + } + } + staff_first_name: staff { + first_name + } + departments + } +} diff --git a/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/session_variables.json b/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/session_variables.json new file mode 100644 index 0000000000000..939ffd9a413db --- /dev/null +++ b/v3/crates/engine/tests/execute/models/select_many/nested_select/relationship/session_variables.json @@ -0,0 +1,3 @@ +{ + "x-hasura-role": "admin" +} diff --git a/v3/crates/engine/tests/execute/relationships/command_to_command/across_namespace/expected.json b/v3/crates/engine/tests/execute/relationships/command_to_command/across_namespace/expected.json index 82ace82f3bf4f..e79f158fce31b 100644 --- a/v3/crates/engine/tests/execute/relationships/command_to_command/across_namespace/expected.json +++ b/v3/crates/engine/tests/execute/relationships/command_to_command/across_namespace/expected.json @@ -2,6 +2,15 @@ { "data": { "getAllActors": [ + { + "MovieFromActor": { + "movie_id": 2, + "rating": 5, + "title": "Slumdog Millionaire" + }, + "actor_id": 0, + "name": "Peter" + }, { "MovieFromActor": { "movie_id": 1, diff --git a/v3/crates/engine/tests/execute/relationships/command_to_model/across_namespace/expected.json b/v3/crates/engine/tests/execute/relationships/command_to_model/across_namespace/expected.json index 93150628ab274..b6616a3d5ca9e 100644 --- a/v3/crates/engine/tests/execute/relationships/command_to_model/across_namespace/expected.json +++ b/v3/crates/engine/tests/execute/relationships/command_to_model/across_namespace/expected.json @@ -2,6 +2,15 @@ { "data": { "getAllActors": [ + { + "Movies": { + "movie_id": 2, + "rating": 5, + "title": "Slumdog Millionaire" + }, + "actor_id": 0, + "name": "Peter" + }, { "Movies": { "movie_id": 1, @@ -71,6 +80,11 @@ { "data": { "getAllActors": [ + { + "Movies": null, + "actor_id": 0, + "name": "Peter" + }, { "Movies": { "movie_id": 1, @@ -120,6 +134,11 @@ { "data": { "getAllActors": [ + { + "Movies": null, + "actor_id": 0, + "name": "Peter" + }, { "Movies": null, "actor_id": 1, @@ -161,6 +180,11 @@ { "data": { "getAllActors": [ + { + "Movies": null, + "actor_id": 0, + "name": "Peter" + }, { "Movies": null, "actor_id": 1, diff --git a/v3/crates/engine/tests/execute/relationships/command_to_model/expected.json b/v3/crates/engine/tests/execute/relationships/command_to_model/expected.json index 93150628ab274..b6616a3d5ca9e 100644 --- a/v3/crates/engine/tests/execute/relationships/command_to_model/expected.json +++ b/v3/crates/engine/tests/execute/relationships/command_to_model/expected.json @@ -2,6 +2,15 @@ { "data": { "getAllActors": [ + { + "Movies": { + "movie_id": 2, + "rating": 5, + "title": "Slumdog Millionaire" + }, + "actor_id": 0, + "name": "Peter" + }, { "Movies": { "movie_id": 1, @@ -71,6 +80,11 @@ { "data": { "getAllActors": [ + { + "Movies": null, + "actor_id": 0, + "name": "Peter" + }, { "Movies": { "movie_id": 1, @@ -120,6 +134,11 @@ { "data": { "getAllActors": [ + { + "Movies": null, + "actor_id": 0, + "name": "Peter" + }, { "Movies": null, "actor_id": 1, @@ -161,6 +180,11 @@ { "data": { "getAllActors": [ + { + "Movies": null, + "actor_id": 0, + "name": "Peter" + }, { "Movies": null, "actor_id": 1, diff --git a/v3/crates/engine/tests/execute/relationships/model_to_command/expected.json b/v3/crates/engine/tests/execute/relationships/model_to_command/expected.json index d6afd7b6e2522..b22675a4cc421 100644 --- a/v3/crates/engine/tests/execute/relationships/model_to_command/expected.json +++ b/v3/crates/engine/tests/execute/relationships/model_to_command/expected.json @@ -2,6 +2,14 @@ { "data": { "ActorMany": [ + { + "MovieFromCommand": { + "movie_id": 2, + "rating": 5, + "title": "Slumdog Millionaire" + }, + "name": "Peter" + }, { "MovieFromCommand": { "movie_id": 1, diff --git a/v3/crates/engine/tests/execute/remote_relationships/command/remote_in_local/expected.json b/v3/crates/engine/tests/execute/remote_relationships/command/remote_in_local/expected.json index aa5502be552be..061fd3dbca5df 100644 --- a/v3/crates/engine/tests/execute/remote_relationships/command/remote_in_local/expected.json +++ b/v3/crates/engine/tests/execute/remote_relationships/command/remote_in_local/expected.json @@ -24,6 +24,13 @@ { "title": "Slumdog Millionaire", "Actors": [ + { + "name": "Peter", + "MovieFromCommand": { + "title": "Slumdog Millionaire", + "rating": 5 + } + }, { "name": "Irfan Khan", "MovieFromCommand": { diff --git a/v3/crates/engine/tests/execute/remote_relationships/multi_field_mapping/expected.json b/v3/crates/engine/tests/execute/remote_relationships/multi_field_mapping/expected.json index 14c18349312c5..4b9363331ce1c 100644 --- a/v3/crates/engine/tests/execute/remote_relationships/multi_field_mapping/expected.json +++ b/v3/crates/engine/tests/execute/remote_relationships/multi_field_mapping/expected.json @@ -45,6 +45,9 @@ "Movie": { "title": "Slumdog Millionaire", "Actors": [ + { + "name": "Peter" + }, { "name": "Irfan Khan" } @@ -120,6 +123,9 @@ "Movie": { "title": "Slumdog Millionaire", "Actors": [ + { + "name": "Peter" + }, { "name": "Irfan Khan" } diff --git a/v3/crates/engine/tests/execute/remote_relationships/mutually_recursive/expected.json b/v3/crates/engine/tests/execute/remote_relationships/mutually_recursive/expected.json index 14c18349312c5..4b9363331ce1c 100644 --- a/v3/crates/engine/tests/execute/remote_relationships/mutually_recursive/expected.json +++ b/v3/crates/engine/tests/execute/remote_relationships/mutually_recursive/expected.json @@ -45,6 +45,9 @@ "Movie": { "title": "Slumdog Millionaire", "Actors": [ + { + "name": "Peter" + }, { "name": "Irfan Khan" } @@ -120,6 +123,9 @@ "Movie": { "title": "Slumdog Millionaire", "Actors": [ + { + "name": "Peter" + }, { "name": "Irfan Khan" } diff --git a/v3/crates/engine/tests/execute/remote_relationships/remote_in_local/expected.json b/v3/crates/engine/tests/execute/remote_relationships/remote_in_local/expected.json index 9136be669f101..0871592dd73da 100644 --- a/v3/crates/engine/tests/execute/remote_relationships/remote_in_local/expected.json +++ b/v3/crates/engine/tests/execute/remote_relationships/remote_in_local/expected.json @@ -42,6 +42,18 @@ "title": "Slumdog Millionaire", "rating": 5, "Actors": [ + { + "name": "Peter", + "Movie": { + "title": "Slumdog Millionaire", + "Analytics": [ + { + "num_users_faved": 4, + "num_views_day": 13 + } + ] + } + }, { "name": "Irfan Khan", "Movie": { @@ -136,6 +148,18 @@ "title": "Slumdog Millionaire", "rating": 5, "Actors": [ + { + "name": "Peter", + "Movie": { + "title": "Slumdog Millionaire", + "Analytics": [ + { + "num_users_faved": 4, + "num_views_day": 13 + } + ] + } + }, { "name": "Irfan Khan", "Movie": { @@ -166,6 +190,13 @@ "title": "Slumdog Millionaire", "rating": 5, "Actors": [ + { + "name": "Peter", + "Movie": { + "title": "Slumdog Millionaire", + "Analytics": [] + } + }, { "name": "Irfan Khan", "Movie": { diff --git a/v3/crates/engine/tests/execute/remote_relationships/remote_in_local/local_array_remote_object/custom_ndc_and_pg_ndc/expected.json b/v3/crates/engine/tests/execute/remote_relationships/remote_in_local/local_array_remote_object/custom_ndc_and_pg_ndc/expected.json index b322d2b6b40ee..65dc013f04974 100644 --- a/v3/crates/engine/tests/execute/remote_relationships/remote_in_local/local_array_remote_object/custom_ndc_and_pg_ndc/expected.json +++ b/v3/crates/engine/tests/execute/remote_relationships/remote_in_local/local_array_remote_object/custom_ndc_and_pg_ndc/expected.json @@ -30,6 +30,15 @@ "title": "Slumdog Millionaire", "rating": 5, "Actors": [ + { + "name": "Peter", + "favourite_author_id": 1, + "FavouriteAuthor": { + "author_id": 1, + "first_name": "Peter", + "last_name": "Landin" + } + }, { "name": "Irfan Khan", "favourite_author_id": 1, @@ -105,6 +114,15 @@ "title": "Slumdog Millionaire", "rating": 5, "Actors": [ + { + "name": "Peter", + "favourite_author_id": 1, + "FavouriteAuthor": { + "author_id": 1, + "first_name": "Peter", + "last_name": "Landin" + } + }, { "name": "Irfan Khan", "favourite_author_id": 1, @@ -126,6 +144,15 @@ "title": "Slumdog Millionaire", "rating": 5, "Actors": [ + { + "name": "Peter", + "favourite_author_id": 1, + "FavouriteAuthor": { + "author_id": 1, + "first_name": "Peter", + "last_name": "Landin" + } + }, { "name": "Irfan Khan", "favourite_author_id": 1, diff --git a/v3/crates/engine/tests/execution.rs b/v3/crates/engine/tests/execution.rs index 09398f161611f..68251bef708ae 100644 --- a/v3/crates/engine/tests/execution.rs +++ b/v3/crates/engine/tests/execution.rs @@ -116,6 +116,17 @@ fn test_model_select_many_nested_select_no_explicit_type_mapping() -> anyhow::Re common::test_execution_expectation_legacy(test_path_string, &[common_metadata_path_string]) } +// Same test as the nested selection +#[test] +fn test_model_select_many_nested_select_with_relationship() -> anyhow::Result<()> { + let test_path_string = "execute/models/select_many/nested_select/relationship"; + let common_metadata_paths = [ + "execute/common_metadata/custom_connector_schema.json", + "execute/models/select_many/nested_select/metadata.json", + ]; + common::test_execution_expectation_legacy(test_path_string, &common_metadata_paths) +} + // nested selection tests, using Postgres #[test] fn test_model_select_many_nested_select_postgres() -> anyhow::Result<()> { diff --git a/v3/crates/execute/src/plan/relationships.rs b/v3/crates/execute/src/plan/relationships.rs index 72d8520b433ca..487cd15543cea 100644 --- a/v3/crates/execute/src/plan/relationships.rs +++ b/v3/crates/execute/src/plan/relationships.rs @@ -47,10 +47,21 @@ pub(crate) fn collect_relationships( )?; } } - FieldSelection::Column { .. } + FieldSelection::Column { + arguments: _, + column: _, + nested_selection, + } => { + if let Some(nested_selection) = &nested_selection { + selection_set::collect_relationships_from_nested_selection( + nested_selection, + relationships, + )?; + } + } // we ignore remote relationships as we are generating relationship // definition for one data connector - | FieldSelection::ModelRelationshipRemote { .. } + FieldSelection::ModelRelationshipRemote { .. } | FieldSelection::CommandRelationshipRemote { .. } => (), }; }