diff --git a/crates/ndc-sqlserver/tests/goldenfiles/very_nested_recursive_relationship.json b/crates/ndc-sqlserver/tests/goldenfiles/very_nested_recursive_relationship.json new file mode 100644 index 00000000..3e73f9c7 --- /dev/null +++ b/crates/ndc-sqlserver/tests/goldenfiles/very_nested_recursive_relationship.json @@ -0,0 +1,129 @@ +{ + "collection": "Artist", + "query": { + "fields": { + "0Name": { + "type": "column", + "column": "Name", + "arguments": {} + }, + "Albums": { + "type": "relationship", + "relationship": "ArtistAlbums", + "arguments": {}, + "query": { + "fields": { + "0Title": { + "type": "column", + "column": "Title", + "arguments": {} + }, + "Artist": { + "type": "relationship", + "relationship": "AlbumArtist", + "arguments": {}, + "query": { + "fields": { + "0ArtistId": { + "type": "column", + "column": "ArtistId", + "arguments": {} + }, + + "Albums": { + "type": "relationship", + "relationship": "ArtistAlbums", + "arguments": {}, + "query": { + "fields": { + "0Title": { + "type": "column", + "column": "Title", + "arguments": {} + }, + "Artist": { + "type": "relationship", + "relationship": "AlbumArtist", + "arguments": {}, + "query": { + "fields": { + "0Name": { + "type": "column", + "column": "Name", + "arguments": {} + } + } + } + } + }, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "AlbumId", + "path": [] + } + } + ] + }, + "limit": 3 + } + } + } + } + } + }, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "AlbumId", + "path": [] + } + } + ] + }, + "limit": 3 + } + } + }, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "ArtistId", + "path": [] + } + } + ] + }, + "limit": 3 + }, + "arguments": {}, + "collection_relationships": { + "ArtistAlbums": { + "column_mapping": { + "ArtistId": "ArtistId" + }, + "relationship_type": "array", + "source_collection_or_type": "Artist", + "target_collection": "Album", + "arguments": {} + }, + "AlbumArtist": { + "column_mapping": { + "ArtistId": "ArtistId" + }, + "relationship_type": "object", + "source_collection_or_type": "Album", + "target_collection": "Artist", + "arguments": {} + } + } +} diff --git a/crates/ndc-sqlserver/tests/query_tests.rs b/crates/ndc-sqlserver/tests/query_tests.rs index 283bed48..3afaae21 100644 --- a/crates/ndc-sqlserver/tests/query_tests.rs +++ b/crates/ndc-sqlserver/tests/query_tests.rs @@ -268,4 +268,10 @@ mod relationships { let result = run_query("dup_array_relationship").await; insta::assert_json_snapshot!(result); } + + #[tokio::test] + async fn very_nested_recursive_relationship() { + let result = run_query("very_nested_recursive_relationship").await; + insta::assert_json_snapshot!(result); + } } diff --git a/crates/ndc-sqlserver/tests/snapshots/query_tests__relationships__very_nested_recursive_relationship.snap b/crates/ndc-sqlserver/tests/snapshots/query_tests__relationships__very_nested_recursive_relationship.snap new file mode 100644 index 00000000..6939f490 --- /dev/null +++ b/crates/ndc-sqlserver/tests/snapshots/query_tests__relationships__very_nested_recursive_relationship.snap @@ -0,0 +1,191 @@ +--- +source: crates/ndc-sqlserver/tests/query_tests.rs +expression: result +--- +[ + { + "rows": [ + { + "0Name": "AC/DC", + "Albums": { + "rows": [ + { + "0Title": "For Those About To Rock We Salute You", + "Artist": { + "rows": [ + { + "0ArtistId": 1, + "Albums": { + "rows": [ + { + "0Title": "For Those About To Rock We Salute You", + "Artist": { + "rows": [ + { + "0Name": "AC/DC" + } + ] + } + }, + { + "0Title": "Let There Be Rock", + "Artist": { + "rows": [ + { + "0Name": "AC/DC" + } + ] + } + } + ] + } + } + ] + } + }, + { + "0Title": "Let There Be Rock", + "Artist": { + "rows": [ + { + "0ArtistId": 1, + "Albums": { + "rows": [ + { + "0Title": "For Those About To Rock We Salute You", + "Artist": { + "rows": [ + { + "0Name": "AC/DC" + } + ] + } + }, + { + "0Title": "Let There Be Rock", + "Artist": { + "rows": [ + { + "0Name": "AC/DC" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + }, + { + "0Name": "Accept", + "Albums": { + "rows": [ + { + "0Title": "Balls to the Wall", + "Artist": { + "rows": [ + { + "0ArtistId": 2, + "Albums": { + "rows": [ + { + "0Title": "Balls to the Wall", + "Artist": { + "rows": [ + { + "0Name": "Accept" + } + ] + } + }, + { + "0Title": "Restless and Wild", + "Artist": { + "rows": [ + { + "0Name": "Accept" + } + ] + } + } + ] + } + } + ] + } + }, + { + "0Title": "Restless and Wild", + "Artist": { + "rows": [ + { + "0ArtistId": 2, + "Albums": { + "rows": [ + { + "0Title": "Balls to the Wall", + "Artist": { + "rows": [ + { + "0Name": "Accept" + } + ] + } + }, + { + "0Title": "Restless and Wild", + "Artist": { + "rows": [ + { + "0Name": "Accept" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + }, + { + "0Name": "Aerosmith", + "Albums": { + "rows": [ + { + "0Title": "Big Ones", + "Artist": { + "rows": [ + { + "0ArtistId": 3, + "Albums": { + "rows": [ + { + "0Title": "Big Ones", + "Artist": { + "rows": [ + { + "0Name": "Aerosmith" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } + ] + } +]