From 62178d2ceb4221d02e846b04a8b1a3df3e4f53d2 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Fri, 12 Apr 2024 12:50:57 -0700 Subject: [PATCH 1/8] unit test for request with variables and empty response set --- .../mongodb-agent-common/src/query/foreach.rs | 156 +++++++++++++++++- 1 file changed, 155 insertions(+), 1 deletion(-) diff --git a/crates/mongodb-agent-common/src/query/foreach.rs b/crates/mongodb-agent-common/src/query/foreach.rs index 2b9bc8aa..6d8e120b 100644 --- a/crates/mongodb-agent-common/src/query/foreach.rs +++ b/crates/mongodb-agent-common/src/query/foreach.rs @@ -133,7 +133,9 @@ fn facet_name(index: usize) -> String { #[cfg(test)] mod tests { - use dc_api_types::{QueryRequest, QueryResponse}; + use dc_api_types::{ + BinaryComparisonOperator, ComparisonColumn, Field, Query, QueryRequest, QueryResponse, + }; use mongodb::{ bson::{doc, from_document}, options::AggregateOptions, @@ -400,4 +402,156 @@ mod tests { Ok(()) } + + #[tokio::test] + async fn executes_foreach_with_variables() -> Result<(), anyhow::Error> { + let query_request = QueryRequest { + foreach: None, + variables: Some(vec![ + [("artistId".to_owned(), json!(1))].into(), + [("artistId".to_owned(), json!(2))].into(), + [("artistId".to_owned(), json!(3))].into(), + ]), + target: dc_api_types::Target::TTable { + name: vec!["tracks".to_owned()], + }, + relationships: Default::default(), + query: Box::new(Query { + r#where: Some(dc_api_types::Expression::ApplyBinaryComparison { + column: ComparisonColumn::new( + "int".to_owned(), + dc_api_types::ColumnSelector::Column("artistId".to_owned()), + ), + operator: BinaryComparisonOperator::Equal, + value: dc_api_types::ComparisonValue::Variable { + name: "artistId".to_owned(), + }, + }), + fields: Some(Some( + [ + ( + "albumId".to_owned(), + Field::Column { + column: "albumId".to_owned(), + column_type: "int".to_owned(), + }, + ), + ( + "title".to_owned(), + Field::Column { + column: "title".to_owned(), + column_type: "string".to_owned(), + }, + ), + ] + .into(), + )), + aggregates: None, + aggregates_limit: None, + limit: None, + offset: None, + order_by: None, + }), + }; + + let expected_pipeline = json!([ + { + "$facet": { + "__FACET___0": [ + { "$match": { "artistId": {"$eq":1 } } }, + { "$replaceWith": { + "albumId": { "$ifNull": ["$albumId", null] }, + "title": { "$ifNull": ["$title", null] } + } }, + ], + "__FACET___1": [ + { "$match": { "artistId": {"$eq": 2 } } }, + { "$replaceWith": { + "albumId": { "$ifNull": ["$albumId", null] }, + "title": { "$ifNull": ["$title", null] } + } }, + ], + "__FACET___2": [ + { "$match": { "artistId": {"$eq": 3 } } }, + { "$replaceWith": { + "albumId": { "$ifNull": ["$albumId", null] }, + "title": { "$ifNull": ["$title", null] } + } }, + ] + }, + }, + { + "$replaceWith": { + "rows": [ + { "query": { "rows": "$__FACET___0" } }, + { "query": { "rows": "$__FACET___1" } }, + { "query": { "rows": "$__FACET___2" } }, + ] + }, + } + ]); + + let expected_response: QueryResponse = from_value(json! ({ + "rows": [ + { + "query": { + "rows": [ + { "albumId": 1, "title": "For Those About To Rock We Salute You" }, + { "albumId": 4, "title": "Let There Be Rock" } + ] + } + }, + { + "query": { + "rows": [] + } + }, + { + "query": { + "rows": [ + { "albumId": 2, "title": "Balls to the Wall" }, + { "albumId": 3, "title": "Restless and Wild" } + ] + } + } + ] + }))?; + + let mut collection = MockCollectionTrait::new(); + collection + .expect_aggregate() + .returning(move |pipeline, _: Option| { + assert_eq!(expected_pipeline, to_value(pipeline).unwrap()); + Ok(mock_stream(vec![Ok(from_document(doc! { + "rows": [ + { + "query": { + "rows": [ + { "albumId": 1, "title": "For Those About To Rock We Salute You" }, + { "albumId": 4, "title": "Let There Be Rock" } + ] + } + }, + { + "query": { + "rows": [] + } + }, + { + "query": { + "rows": [ + { "albumId": 2, "title": "Balls to the Wall" }, + { "albumId": 3, "title": "Restless and Wild" } + ] + } + } + ], + })?)])) + }); + + let result = execute_query_request(&collection, query_request).await?; + assert_eq!(expected_response, result); + + Ok(()) + } } From e5da251ed2c79318a46ffd571a4cd0b88541d2e8 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Sat, 13 Apr 2024 14:17:20 -0700 Subject: [PATCH 2/8] run two connectors --- arion-compose/project-connector.nix | 37 ++++++++++++++---- arion-compose/project-e2e-testing.nix | 3 +- arion-compose/service-engine.nix | 39 +++++++++++++------ .../{subgraphs => }/chinook/commands/.gitkeep | 0 .../chinook/commands/InsertArtist.hml | 0 .../chinook/dataconnectors/.gitkeep | 0 .../chinook/dataconnectors/chinook-types.hml | 22 +++++------ .../chinook/dataconnectors/chinook.hml | 0 .../{subgraphs => }/chinook/models/Album.hml | 10 ++--- .../{subgraphs => }/chinook/models/Artist.hml | 10 ++--- .../chinook/models/Customer.hml | 12 +++--- .../chinook/models/Employee.hml | 12 +++--- .../{subgraphs => }/chinook/models/Genre.hml | 10 ++--- .../chinook/models/Invoice.hml | 12 +++--- .../chinook/models/InvoiceLine.hml | 10 ++--- .../chinook/models/MediaType.hml | 10 ++--- .../chinook/models/Playlist.hml | 10 ++--- .../chinook/models/PlaylistTrack.hml | 10 ++--- .../{subgraphs => }/chinook/models/Track.hml | 10 ++--- .../chinook/relationships/album_artist.hml | 0 .../chinook/relationships/artist_albums.hml | 0 .../sample_mflix/dataconnectors/.gitkeep | 0 .../dataconnectors/sample_mflix-types.hml | 18 ++++----- .../dataconnectors/sample_mflix.hml | 0 .../sample_mflix/models/Comments.hml | 8 ++-- .../sample_mflix/models/Movies.hml | 28 ++++++------- .../sample_mflix/models/Sessions.hml | 8 ++-- .../sample_mflix/models/Theaters.hml | 20 +++++----- .../sample_mflix/models/Users.hml | 8 ++-- 29 files changed, 174 insertions(+), 133 deletions(-) rename fixtures/ddn/{subgraphs => }/chinook/commands/.gitkeep (100%) rename fixtures/ddn/{subgraphs => }/chinook/commands/InsertArtist.hml (100%) rename fixtures/ddn/{subgraphs => }/chinook/dataconnectors/.gitkeep (100%) rename fixtures/ddn/{subgraphs => }/chinook/dataconnectors/chinook-types.hml (65%) rename fixtures/ddn/{subgraphs => }/chinook/dataconnectors/chinook.hml (100%) rename fixtures/ddn/{subgraphs => }/chinook/models/Album.hml (92%) rename fixtures/ddn/{subgraphs => }/chinook/models/Artist.hml (91%) rename fixtures/ddn/{subgraphs => }/chinook/models/Customer.hml (96%) rename fixtures/ddn/{subgraphs => }/chinook/models/Employee.hml (96%) rename fixtures/ddn/{subgraphs => }/chinook/models/Genre.hml (91%) rename fixtures/ddn/{subgraphs => }/chinook/models/Invoice.hml (95%) rename fixtures/ddn/{subgraphs => }/chinook/models/InvoiceLine.hml (93%) rename fixtures/ddn/{subgraphs => }/chinook/models/MediaType.hml (91%) rename fixtures/ddn/{subgraphs => }/chinook/models/Playlist.hml (91%) rename fixtures/ddn/{subgraphs => }/chinook/models/PlaylistTrack.hml (90%) rename fixtures/ddn/{subgraphs => }/chinook/models/Track.hml (95%) rename fixtures/ddn/{subgraphs => }/chinook/relationships/album_artist.hml (100%) rename fixtures/ddn/{subgraphs => }/chinook/relationships/artist_albums.hml (100%) rename fixtures/ddn/{subgraphs => }/sample_mflix/dataconnectors/.gitkeep (100%) rename fixtures/ddn/{subgraphs => }/sample_mflix/dataconnectors/sample_mflix-types.hml (74%) rename fixtures/ddn/{subgraphs => }/sample_mflix/dataconnectors/sample_mflix.hml (100%) rename fixtures/ddn/{subgraphs => }/sample_mflix/models/Comments.hml (94%) rename fixtures/ddn/{subgraphs => }/sample_mflix/models/Movies.hml (94%) rename fixtures/ddn/{subgraphs => }/sample_mflix/models/Sessions.hml (92%) rename fixtures/ddn/{subgraphs => }/sample_mflix/models/Theaters.hml (89%) rename fixtures/ddn/{subgraphs => }/sample_mflix/models/Users.hml (93%) diff --git a/arion-compose/project-connector.nix b/arion-compose/project-connector.nix index 5af31152..2dfd9bc8 100644 --- a/arion-compose/project-connector.nix +++ b/arion-compose/project-connector.nix @@ -1,12 +1,15 @@ -# Run v3 MongoDB connector and engine with supporting databases. To start this -# project run: +# Run 2 MongoDB connectors and engine with supporting database. Running two +# connectors is useful for testing remote joins. +# +# To start this # project run: # # arion -f arion-compose/project-connector.nix up -d # { pkgs, ... }: let - connector = "7130"; + connector-port = "7130"; + connector-chinook-port = "7131"; engine-port = "7100"; mongodb-port = "27017"; in @@ -18,8 +21,21 @@ in inherit pkgs; configuration-dir = ../fixtures/connector/sample_mflix; database-uri = "mongodb://mongodb/sample_mflix"; - port = connector; - hostPort = connector; + port = connector-port; + hostPort = connector-port; + otlp-endpoint = "http://jaeger:4317"; + service.depends_on = { + jaeger.condition = "service_healthy"; + mongodb.condition = "service_healthy"; + }; + }; + + connector-chinook = import ./service-connector.nix { + inherit pkgs; + configuration-dir = ../fixtures/connector/chinook; + database-uri = "mongodb://mongodb/chinook"; + port = connector-chinook-port; + hostPort = connector-chinook-port; otlp-endpoint = "http://jaeger:4317"; service.depends_on = { jaeger.condition = "service_healthy"; @@ -41,8 +57,15 @@ in inherit pkgs; port = engine-port; hostPort = engine-port; - connectors = [ - { name = "sample_mflix"; url = "http://connector:${connector}"; subgraph = ../fixtures/ddn/subgraphs/sample_mflix; } + auth-webhook = { url = "http://auth-hook:3050/validate-request"; }; + connectors = { + chinook = "http://connector-chinook:${connector-chinook-port}"; + sample_mflix = "http://connector:${connector-port}"; + }; + ddn-dirs = [ + ../fixtures/ddn/chinook + ../fixtures/ddn/sample_mflix + # ../fixtures/ddn/remote-relationship-todo-todo ]; otlp-endpoint = "http://jaeger:4317"; service.depends_on = { diff --git a/arion-compose/project-e2e-testing.nix b/arion-compose/project-e2e-testing.nix index e8483684..7bf3d028 100644 --- a/arion-compose/project-e2e-testing.nix +++ b/arion-compose/project-e2e-testing.nix @@ -37,7 +37,8 @@ in engine = import ./service-engine.nix { inherit pkgs; port = engine-port; - connectors = [{ name = "chinook"; url = "http://connector:${connector-port}"; subgraph = ../fixtures/ddn/subgraphs/chinook; }]; + connectors.chinook = "http://connector:${connector-port}"; + ddn-dirs = [ ../fixtures/ddn/chinook ]; service.depends_on = { auth-hook.condition = "service_started"; }; diff --git a/arion-compose/service-engine.nix b/arion-compose/service-engine.nix index f6404d39..a95a789b 100644 --- a/arion-compose/service-engine.nix +++ b/arion-compose/service-engine.nix @@ -1,17 +1,34 @@ { pkgs , port ? "7100" , hostPort ? null -, connectors ? [{ name = "sample_mflix"; url = "http://connector:7130"; subgraph = ../fixtures/ddn/subgraphs/sample_mflix; }] + + # Each key in the `connectors` map should match + # a `DataConnectorLink.definition.name` value in one of the given `ddn-dirs` + # to correctly match up configuration to connector instances. +, connectors ? { sample_mflix = "http://connector:7130"; } +, ddn-dirs ? [ ../fixtures/ddn/subgraphs/sample_mflix ] , auth-webhook ? { url = "http://auth-hook:3050/validate-request"; } , otlp-endpoint ? "http://jaeger:4317" , service ? { } # additional options to customize this service configuration }: let - # Compile JSON metadata from HML fixture - metadata = pkgs.stdenv.mkDerivation { - name = "hasura-metadata.json"; - src = (builtins.head connectors).subgraph; + # Compile JSON metadata from HML fixtures + # + # Converts yaml documents from each ddn-dir into json objects, and combines + # objects into one big array. Produces a file in the Nix store of the form + # /nix/store/-hasura-metadata.json + metadata = pkgs.runCommand "hasura-metadata.json" { } '' + ${pkgs.jq}/bin/jq -s 'flatten(1)' \ + ${builtins.concatStringsSep " " (builtins.map compile-ddn ddn-dirs)} \ + > $out + ''; + + # Translate each yaml document from hml files into a json object, and combine + # all objects into an array + compile-ddn = ddn-dir: pkgs.stdenv.mkDerivation { + name = "ddn-${builtins.baseNameOf ddn-dir}.json"; + src = ddn-dir; nativeBuildInputs = with pkgs; [ findutils jq yq-go ]; # The yq command converts the input sequence of yaml docs to a sequence of @@ -20,7 +37,7 @@ let # The jq command combines those json docs into an array (due to the -s # switch), and modifies the json to update the data connector url. buildPhase = '' - combined=$(mktemp -t subgraph-XXXXXX.hml) + combined=$(mktemp -t ddn-${builtins.baseNameOf ddn-dir}-XXXXXX.hml) for obj in $(find . -name '*hml'); do echo "---" >> "$combined" cat "$obj" >> "$combined" @@ -29,21 +46,21 @@ let | yq -o=json \ ${connector-url-substituters} \ | jq -s 'map(select(type != "null"))' \ - > metadata.json + > ddn.json ''; installPhase = '' - cp metadata.json "$out" + cp ddn.json "$out" ''; }; # Pipe commands to replace data connector urls in fixture configuration with # urls of dockerized connector instances - connector-url-substituters = builtins.toString (builtins.map - ({ name, url, ... }: + connector-url-substituters = builtins.toString (builtins.attrValues (builtins.mapAttrs + (name: url: '' | jq 'if .kind == "DataConnectorLink" and .definition.name == "${name}" then .definition.url = { singleUrl: { value: "${url}" } } else . end' '' ) - connectors); + connectors)); auth-config = pkgs.writeText "auth_config.json" (builtins.toJSON { version = "v1"; diff --git a/fixtures/ddn/subgraphs/chinook/commands/.gitkeep b/fixtures/ddn/chinook/commands/.gitkeep similarity index 100% rename from fixtures/ddn/subgraphs/chinook/commands/.gitkeep rename to fixtures/ddn/chinook/commands/.gitkeep diff --git a/fixtures/ddn/subgraphs/chinook/commands/InsertArtist.hml b/fixtures/ddn/chinook/commands/InsertArtist.hml similarity index 100% rename from fixtures/ddn/subgraphs/chinook/commands/InsertArtist.hml rename to fixtures/ddn/chinook/commands/InsertArtist.hml diff --git a/fixtures/ddn/subgraphs/chinook/dataconnectors/.gitkeep b/fixtures/ddn/chinook/dataconnectors/.gitkeep similarity index 100% rename from fixtures/ddn/subgraphs/chinook/dataconnectors/.gitkeep rename to fixtures/ddn/chinook/dataconnectors/.gitkeep diff --git a/fixtures/ddn/subgraphs/chinook/dataconnectors/chinook-types.hml b/fixtures/ddn/chinook/dataconnectors/chinook-types.hml similarity index 65% rename from fixtures/ddn/subgraphs/chinook/dataconnectors/chinook-types.hml rename to fixtures/ddn/chinook/dataconnectors/chinook-types.hml index fb4f6592..8be96015 100644 --- a/fixtures/ddn/subgraphs/chinook/dataconnectors/chinook-types.hml +++ b/fixtures/ddn/chinook/dataconnectors/chinook-types.hml @@ -2,9 +2,9 @@ kind: ScalarType version: v1 definition: - name: ObjectId + name: Chinook_ObjectId graphql: - typeName: App_ObjectId + typeName: Chinook_ObjectId --- kind: DataConnectorScalarRepresentation @@ -12,9 +12,9 @@ version: v1 definition: dataConnectorName: chinook dataConnectorScalarType: ObjectId - representation: ObjectId + representation: Chinook_ObjectId graphql: - comparisonExpressionTypeName: App_ObjectIdComparisonExp + comparisonExpressionTypeName: Chinook_ObjectIdComparisonExp --- kind: DataConnectorScalarRepresentation @@ -24,7 +24,7 @@ definition: dataConnectorScalarType: Int representation: Int graphql: - comparisonExpressionTypeName: App_IntComparisonExp + comparisonExpressionTypeName: IntComparisonExp --- kind: DataConnectorScalarRepresentation @@ -34,15 +34,15 @@ definition: dataConnectorScalarType: String representation: String graphql: - comparisonExpressionTypeName: App_StringComparisonExp + comparisonExpressionTypeName: StringComparisonExp --- kind: ScalarType version: v1 definition: - name: ExtendedJson + name: Chinook_ExtendedJson graphql: - typeName: App_ExtendedJson + typeName: Chinook_ExtendedJson --- kind: DataConnectorScalarRepresentation @@ -50,9 +50,9 @@ version: v1 definition: dataConnectorName: chinook dataConnectorScalarType: ExtendedJSON - representation: ExtendedJson + representation: Chinook_ExtendedJson graphql: - comparisonExpressionTypeName: App_ExtendedJsonComparisonExp + comparisonExpressionTypeName: Chinook_ExtendedJsonComparisonExp --- kind: DataConnectorScalarRepresentation @@ -62,4 +62,4 @@ definition: dataConnectorScalarType: Float representation: Float graphql: - comparisonExpressionTypeName: App_FloatComparisonExp + comparisonExpressionTypeName: FloatComparisonExp diff --git a/fixtures/ddn/subgraphs/chinook/dataconnectors/chinook.hml b/fixtures/ddn/chinook/dataconnectors/chinook.hml similarity index 100% rename from fixtures/ddn/subgraphs/chinook/dataconnectors/chinook.hml rename to fixtures/ddn/chinook/dataconnectors/chinook.hml diff --git a/fixtures/ddn/subgraphs/chinook/models/Album.hml b/fixtures/ddn/chinook/models/Album.hml similarity index 92% rename from fixtures/ddn/subgraphs/chinook/models/Album.hml rename to fixtures/ddn/chinook/models/Album.hml index f332e8a4..a17cf54c 100644 --- a/fixtures/ddn/subgraphs/chinook/models/Album.hml +++ b/fixtures/ddn/chinook/models/Album.hml @@ -5,7 +5,7 @@ definition: name: Album fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: albumId type: Int! - name: artistId @@ -13,8 +13,8 @@ definition: - name: title type: String! graphql: - typeName: App_Album - inputTypeName: App_AlbumInput + typeName: Album + inputTypeName: AlbumInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: Album @@ -68,7 +68,7 @@ definition: operators: enableAll: true graphql: - typeName: App_AlbumBoolExp + typeName: AlbumBoolExp --- kind: Model @@ -100,7 +100,7 @@ definition: - queryRootField: albumById uniqueIdentifier: - id - orderByExpressionType: App_AlbumOrderBy + orderByExpressionType: AlbumOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/models/Artist.hml b/fixtures/ddn/chinook/models/Artist.hml similarity index 91% rename from fixtures/ddn/subgraphs/chinook/models/Artist.hml rename to fixtures/ddn/chinook/models/Artist.hml index 971975ea..b88dccf6 100644 --- a/fixtures/ddn/subgraphs/chinook/models/Artist.hml +++ b/fixtures/ddn/chinook/models/Artist.hml @@ -5,14 +5,14 @@ definition: name: Artist fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: artistId type: Int! - name: name type: String! graphql: - typeName: App_Artist - inputTypeName: App_ArtistInput + typeName: Artist + inputTypeName: ArtistInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: Artist @@ -59,7 +59,7 @@ definition: operators: enableAll: true graphql: - typeName: App_ArtistBoolExp + typeName: ArtistBoolExp --- kind: Model @@ -88,7 +88,7 @@ definition: - queryRootField: artistById uniqueIdentifier: - id - orderByExpressionType: App_ArtistOrderBy + orderByExpressionType: ArtistOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/models/Customer.hml b/fixtures/ddn/chinook/models/Customer.hml similarity index 96% rename from fixtures/ddn/subgraphs/chinook/models/Customer.hml rename to fixtures/ddn/chinook/models/Customer.hml index 54917793..a579f1ca 100644 --- a/fixtures/ddn/subgraphs/chinook/models/Customer.hml +++ b/fixtures/ddn/chinook/models/Customer.hml @@ -5,7 +5,7 @@ definition: name: Customer fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: address type: String! - name: city @@ -27,14 +27,14 @@ definition: - name: phone type: String! - name: postalCode - type: ExtendedJson + type: Chinook_ExtendedJson - name: state type: String! - name: supportRepId type: Int! graphql: - typeName: App_Customer - inputTypeName: App_CustomerInput + typeName: Customer + inputTypeName: CustomerInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: Customer @@ -158,7 +158,7 @@ definition: operators: enableAll: true graphql: - typeName: App_CustomerBoolExp + typeName: CustomerBoolExp --- kind: Model @@ -220,7 +220,7 @@ definition: - queryRootField: customerById uniqueIdentifier: - id - orderByExpressionType: App_CustomerOrderBy + orderByExpressionType: CustomerOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/models/Employee.hml b/fixtures/ddn/chinook/models/Employee.hml similarity index 96% rename from fixtures/ddn/subgraphs/chinook/models/Employee.hml rename to fixtures/ddn/chinook/models/Employee.hml index a59f3d73..c13b73c5 100644 --- a/fixtures/ddn/subgraphs/chinook/models/Employee.hml +++ b/fixtures/ddn/chinook/models/Employee.hml @@ -5,7 +5,7 @@ definition: name: Employee fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: address type: String! - name: birthDate @@ -31,14 +31,14 @@ definition: - name: postalCode type: String! - name: reportsTo - type: ExtendedJson + type: Chinook_ExtendedJson - name: state type: String! - name: title type: String! graphql: - typeName: App_Employee - inputTypeName: App_EmployeeInput + typeName: Employee + inputTypeName: EmployeeInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: Employee @@ -176,7 +176,7 @@ definition: operators: enableAll: true graphql: - typeName: App_EmployeeBoolExp + typeName: EmployeeBoolExp --- kind: Model @@ -244,7 +244,7 @@ definition: - queryRootField: employeeById uniqueIdentifier: - id - orderByExpressionType: App_EmployeeOrderBy + orderByExpressionType: EmployeeOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/models/Genre.hml b/fixtures/ddn/chinook/models/Genre.hml similarity index 91% rename from fixtures/ddn/subgraphs/chinook/models/Genre.hml rename to fixtures/ddn/chinook/models/Genre.hml index 1af381cc..916ab2e1 100644 --- a/fixtures/ddn/subgraphs/chinook/models/Genre.hml +++ b/fixtures/ddn/chinook/models/Genre.hml @@ -5,14 +5,14 @@ definition: name: Genre fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: genreId type: Int! - name: name type: String! graphql: - typeName: App_Genre - inputTypeName: App_GenreInput + typeName: Genre + inputTypeName: GenreInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: Genre @@ -59,7 +59,7 @@ definition: operators: enableAll: true graphql: - typeName: App_GenreBoolExp + typeName: GenreBoolExp --- kind: Model @@ -88,7 +88,7 @@ definition: - queryRootField: genreById uniqueIdentifier: - id - orderByExpressionType: App_GenreOrderBy + orderByExpressionType: GenreOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/models/Invoice.hml b/fixtures/ddn/chinook/models/Invoice.hml similarity index 95% rename from fixtures/ddn/subgraphs/chinook/models/Invoice.hml rename to fixtures/ddn/chinook/models/Invoice.hml index 2773af88..50b6558d 100644 --- a/fixtures/ddn/subgraphs/chinook/models/Invoice.hml +++ b/fixtures/ddn/chinook/models/Invoice.hml @@ -5,7 +5,7 @@ definition: name: Invoice fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: billingAddress type: String! - name: billingCity @@ -13,7 +13,7 @@ definition: - name: billingCountry type: String! - name: billingPostalCode - type: ExtendedJson + type: Chinook_ExtendedJson - name: billingState type: String! - name: customerId @@ -25,8 +25,8 @@ definition: - name: total type: Float! graphql: - typeName: App_Invoice - inputTypeName: App_InvoiceInput + typeName: Invoice + inputTypeName: InvoiceInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: Invoice @@ -122,7 +122,7 @@ definition: operators: enableAll: true graphql: - typeName: App_InvoiceBoolExp + typeName: InvoiceBoolExp --- kind: Model @@ -172,7 +172,7 @@ definition: - queryRootField: invoiceById uniqueIdentifier: - id - orderByExpressionType: App_InvoiceOrderBy + orderByExpressionType: InvoiceOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/models/InvoiceLine.hml b/fixtures/ddn/chinook/models/InvoiceLine.hml similarity index 93% rename from fixtures/ddn/subgraphs/chinook/models/InvoiceLine.hml rename to fixtures/ddn/chinook/models/InvoiceLine.hml index f0259b38..39513adc 100644 --- a/fixtures/ddn/subgraphs/chinook/models/InvoiceLine.hml +++ b/fixtures/ddn/chinook/models/InvoiceLine.hml @@ -5,7 +5,7 @@ definition: name: InvoiceLine fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: invoiceId type: Int! - name: invoiceLineId @@ -17,8 +17,8 @@ definition: - name: unitPrice type: Float! graphql: - typeName: App_InvoiceLine - inputTypeName: App_InvoiceLineInput + typeName: InvoiceLine + inputTypeName: InvoiceLineInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: InvoiceLine @@ -86,7 +86,7 @@ definition: operators: enableAll: true graphql: - typeName: App_InvoiceLineBoolExp + typeName: InvoiceLineBoolExp --- kind: Model @@ -124,7 +124,7 @@ definition: - queryRootField: invoiceLineById uniqueIdentifier: - id - orderByExpressionType: App_InvoiceLineOrderBy + orderByExpressionType: InvoiceLineOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/models/MediaType.hml b/fixtures/ddn/chinook/models/MediaType.hml similarity index 91% rename from fixtures/ddn/subgraphs/chinook/models/MediaType.hml rename to fixtures/ddn/chinook/models/MediaType.hml index fab30969..e01e6657 100644 --- a/fixtures/ddn/subgraphs/chinook/models/MediaType.hml +++ b/fixtures/ddn/chinook/models/MediaType.hml @@ -5,14 +5,14 @@ definition: name: MediaType fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: mediaTypeId type: Int! - name: name type: String! graphql: - typeName: App_MediaType - inputTypeName: App_MediaTypeInput + typeName: MediaType + inputTypeName: MediaTypeInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: MediaType @@ -59,7 +59,7 @@ definition: operators: enableAll: true graphql: - typeName: App_MediaTypeBoolExp + typeName: MediaTypeBoolExp --- kind: Model @@ -88,7 +88,7 @@ definition: - queryRootField: mediaTypeById uniqueIdentifier: - id - orderByExpressionType: App_MediaTypeOrderBy + orderByExpressionType: MediaTypeOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/models/Playlist.hml b/fixtures/ddn/chinook/models/Playlist.hml similarity index 91% rename from fixtures/ddn/subgraphs/chinook/models/Playlist.hml rename to fixtures/ddn/chinook/models/Playlist.hml index d5ae7143..6479bbe4 100644 --- a/fixtures/ddn/subgraphs/chinook/models/Playlist.hml +++ b/fixtures/ddn/chinook/models/Playlist.hml @@ -5,14 +5,14 @@ definition: name: Playlist fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: name type: String! - name: playlistId type: Int! graphql: - typeName: App_Playlist - inputTypeName: App_PlaylistInput + typeName: Playlist + inputTypeName: PlaylistInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: Playlist @@ -59,7 +59,7 @@ definition: operators: enableAll: true graphql: - typeName: App_PlaylistBoolExp + typeName: PlaylistBoolExp --- kind: Model @@ -88,7 +88,7 @@ definition: - queryRootField: playlistById uniqueIdentifier: - id - orderByExpressionType: App_PlaylistOrderBy + orderByExpressionType: PlaylistOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/models/PlaylistTrack.hml b/fixtures/ddn/chinook/models/PlaylistTrack.hml similarity index 90% rename from fixtures/ddn/subgraphs/chinook/models/PlaylistTrack.hml rename to fixtures/ddn/chinook/models/PlaylistTrack.hml index 20c16e5e..1ce858c7 100644 --- a/fixtures/ddn/subgraphs/chinook/models/PlaylistTrack.hml +++ b/fixtures/ddn/chinook/models/PlaylistTrack.hml @@ -5,14 +5,14 @@ definition: name: PlaylistTrack fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: playlistId type: Int! - name: trackId type: Int! graphql: - typeName: App_PlaylistTrack - inputTypeName: App_PlaylistTrackInput + typeName: PlaylistTrack + inputTypeName: PlaylistTrackInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: PlaylistTrack @@ -59,7 +59,7 @@ definition: operators: enableAll: true graphql: - typeName: App_PlaylistTrackBoolExp + typeName: PlaylistTrackBoolExp --- kind: Model @@ -88,7 +88,7 @@ definition: - queryRootField: playlistTrackById uniqueIdentifier: - id - orderByExpressionType: App_PlaylistTrackOrderBy + orderByExpressionType: PlaylistTrackOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/models/Track.hml b/fixtures/ddn/chinook/models/Track.hml similarity index 95% rename from fixtures/ddn/subgraphs/chinook/models/Track.hml rename to fixtures/ddn/chinook/models/Track.hml index 1b684e18..83c8a7ae 100644 --- a/fixtures/ddn/subgraphs/chinook/models/Track.hml +++ b/fixtures/ddn/chinook/models/Track.hml @@ -5,7 +5,7 @@ definition: name: Track fields: - name: id - type: ObjectId! + type: Chinook_ObjectId! - name: albumId type: Int! - name: bytes @@ -25,8 +25,8 @@ definition: - name: unitPrice type: Float! graphql: - typeName: App_Track - inputTypeName: App_TrackInput + typeName: Track + inputTypeName: TrackInput dataConnectorTypeMapping: - dataConnectorName: chinook dataConnectorObjectType: Track @@ -122,7 +122,7 @@ definition: operators: enableAll: true graphql: - typeName: App_TrackBoolExp + typeName: TrackBoolExp --- kind: Model @@ -172,7 +172,7 @@ definition: - queryRootField: trackById uniqueIdentifier: - id - orderByExpressionType: App_TrackOrderBy + orderByExpressionType: TrackOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/chinook/relationships/album_artist.hml b/fixtures/ddn/chinook/relationships/album_artist.hml similarity index 100% rename from fixtures/ddn/subgraphs/chinook/relationships/album_artist.hml rename to fixtures/ddn/chinook/relationships/album_artist.hml diff --git a/fixtures/ddn/subgraphs/chinook/relationships/artist_albums.hml b/fixtures/ddn/chinook/relationships/artist_albums.hml similarity index 100% rename from fixtures/ddn/subgraphs/chinook/relationships/artist_albums.hml rename to fixtures/ddn/chinook/relationships/artist_albums.hml diff --git a/fixtures/ddn/subgraphs/sample_mflix/dataconnectors/.gitkeep b/fixtures/ddn/sample_mflix/dataconnectors/.gitkeep similarity index 100% rename from fixtures/ddn/subgraphs/sample_mflix/dataconnectors/.gitkeep rename to fixtures/ddn/sample_mflix/dataconnectors/.gitkeep diff --git a/fixtures/ddn/subgraphs/sample_mflix/dataconnectors/sample_mflix-types.hml b/fixtures/ddn/sample_mflix/dataconnectors/sample_mflix-types.hml similarity index 74% rename from fixtures/ddn/subgraphs/sample_mflix/dataconnectors/sample_mflix-types.hml rename to fixtures/ddn/sample_mflix/dataconnectors/sample_mflix-types.hml index 39bb6889..dd8459ea 100644 --- a/fixtures/ddn/subgraphs/sample_mflix/dataconnectors/sample_mflix-types.hml +++ b/fixtures/ddn/sample_mflix/dataconnectors/sample_mflix-types.hml @@ -4,7 +4,7 @@ version: v1 definition: name: ObjectId graphql: - typeName: App_ObjectId + typeName: ObjectId --- kind: ScalarType @@ -12,7 +12,7 @@ version: v1 definition: name: Date graphql: - typeName: App_Date + typeName: Date --- kind: DataConnectorScalarRepresentation @@ -22,7 +22,7 @@ definition: dataConnectorScalarType: ObjectId representation: ObjectId graphql: - comparisonExpressionTypeName: App_ObjectIdComparisonExp + comparisonExpressionTypeName: ObjectIdComparisonExp --- kind: DataConnectorScalarRepresentation @@ -32,7 +32,7 @@ definition: dataConnectorScalarType: Date representation: Date graphql: - comparisonExpressionTypeName: App_DateComparisonExp + comparisonExpressionTypeName: DateComparisonExp --- kind: DataConnectorScalarRepresentation @@ -42,7 +42,7 @@ definition: dataConnectorScalarType: String representation: String graphql: - comparisonExpressionTypeName: App_StringComparisonExp + comparisonExpressionTypeName: StringComparisonExp --- kind: ScalarType @@ -50,7 +50,7 @@ version: v1 definition: name: ExtendedJson graphql: - typeName: App_ExtendedJson + typeName: ExtendedJson --- kind: DataConnectorScalarRepresentation @@ -60,7 +60,7 @@ definition: dataConnectorScalarType: Int representation: Int graphql: - comparisonExpressionTypeName: App_IntComparisonExp + comparisonExpressionTypeName: IntComparisonExp --- kind: DataConnectorScalarRepresentation @@ -70,7 +70,7 @@ definition: dataConnectorScalarType: ExtendedJSON representation: ExtendedJson graphql: - comparisonExpressionTypeName: App_ExtendedJsonComparisonExp + comparisonExpressionTypeName: ExtendedJsonComparisonExp --- kind: DataConnectorScalarRepresentation @@ -80,4 +80,4 @@ definition: dataConnectorScalarType: Float representation: Float graphql: - comparisonExpressionTypeName: App_FloatComparisonExp + comparisonExpressionTypeName: FloatComparisonExp diff --git a/fixtures/ddn/subgraphs/sample_mflix/dataconnectors/sample_mflix.hml b/fixtures/ddn/sample_mflix/dataconnectors/sample_mflix.hml similarity index 100% rename from fixtures/ddn/subgraphs/sample_mflix/dataconnectors/sample_mflix.hml rename to fixtures/ddn/sample_mflix/dataconnectors/sample_mflix.hml diff --git a/fixtures/ddn/subgraphs/sample_mflix/models/Comments.hml b/fixtures/ddn/sample_mflix/models/Comments.hml similarity index 94% rename from fixtures/ddn/subgraphs/sample_mflix/models/Comments.hml rename to fixtures/ddn/sample_mflix/models/Comments.hml index 0c6964e7..a525e184 100644 --- a/fixtures/ddn/subgraphs/sample_mflix/models/Comments.hml +++ b/fixtures/ddn/sample_mflix/models/Comments.hml @@ -17,8 +17,8 @@ definition: - name: text type: String! graphql: - typeName: App_Comments - inputTypeName: App_CommentsInput + typeName: Comments + inputTypeName: CommentsInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: comments @@ -86,7 +86,7 @@ definition: operators: enableAll: true graphql: - typeName: App_CommentsBoolExp + typeName: CommentsBoolExp --- kind: Model @@ -124,7 +124,7 @@ definition: - queryRootField: commentsById uniqueIdentifier: - id - orderByExpressionType: App_CommentsOrderBy + orderByExpressionType: CommentsOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/sample_mflix/models/Movies.hml b/fixtures/ddn/sample_mflix/models/Movies.hml similarity index 94% rename from fixtures/ddn/subgraphs/sample_mflix/models/Movies.hml rename to fixtures/ddn/sample_mflix/models/Movies.hml index 9f144777..a4c6f5de 100644 --- a/fixtures/ddn/subgraphs/sample_mflix/models/Movies.hml +++ b/fixtures/ddn/sample_mflix/models/Movies.hml @@ -11,8 +11,8 @@ definition: - name: wins type: Int! graphql: - typeName: App_MoviesAwards - inputTypeName: App_MoviesAwardsInput + typeName: MoviesAwards + inputTypeName: MoviesAwardsInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: movies_awards @@ -43,8 +43,8 @@ definition: - name: votes type: Int! graphql: - typeName: App_MoviesImdb - inputTypeName: App_MoviesImdbInput + typeName: MoviesImdb + inputTypeName: MoviesImdbInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: movies_imdb @@ -75,8 +75,8 @@ definition: - name: rating type: ExtendedJson graphql: - typeName: App_MoviesTomatoesCritic - inputTypeName: App_MoviesTomatoesCriticInput + typeName: MoviesTomatoesCritic + inputTypeName: MoviesTomatoesCriticInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: movies_tomatoes_critic @@ -107,8 +107,8 @@ definition: - name: rating type: ExtendedJson graphql: - typeName: App_MoviesTomatoesViewer - inputTypeName: App_MoviesTomatoesViewerInput + typeName: MoviesTomatoesViewer + inputTypeName: MoviesTomatoesViewerInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: movies_tomatoes_viewer @@ -153,8 +153,8 @@ definition: - name: website type: String graphql: - typeName: App_MoviesTomatoes - inputTypeName: App_MoviesTomatoesInput + typeName: MoviesTomatoes + inputTypeName: MoviesTomatoesInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: movies_tomatoes @@ -230,8 +230,8 @@ definition: - name: year type: Int! graphql: - typeName: App_Movies - inputTypeName: App_MoviesInput + typeName: Movies + inputTypeName: MoviesInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: movies @@ -411,7 +411,7 @@ definition: operators: enableAll: true graphql: - typeName: App_MoviesBoolExp + typeName: MoviesBoolExp --- kind: Model @@ -497,7 +497,7 @@ definition: - queryRootField: moviesById uniqueIdentifier: - id - orderByExpressionType: App_MoviesOrderBy + orderByExpressionType: MoviesOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/sample_mflix/models/Sessions.hml b/fixtures/ddn/sample_mflix/models/Sessions.hml similarity index 92% rename from fixtures/ddn/subgraphs/sample_mflix/models/Sessions.hml rename to fixtures/ddn/sample_mflix/models/Sessions.hml index 3cc3436c..50f3969f 100644 --- a/fixtures/ddn/subgraphs/sample_mflix/models/Sessions.hml +++ b/fixtures/ddn/sample_mflix/models/Sessions.hml @@ -11,8 +11,8 @@ definition: - name: userId type: String! graphql: - typeName: App_Sessions - inputTypeName: App_SessionsInput + typeName: Sessions + inputTypeName: SessionsInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: sessions @@ -59,7 +59,7 @@ definition: operators: enableAll: true graphql: - typeName: App_SessionsBoolExp + typeName: SessionsBoolExp --- kind: Model @@ -88,7 +88,7 @@ definition: - queryRootField: sessionsById uniqueIdentifier: - id - orderByExpressionType: App_SessionsOrderBy + orderByExpressionType: SessionsOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/sample_mflix/models/Theaters.hml b/fixtures/ddn/sample_mflix/models/Theaters.hml similarity index 89% rename from fixtures/ddn/subgraphs/sample_mflix/models/Theaters.hml rename to fixtures/ddn/sample_mflix/models/Theaters.hml index b294e615..0c534319 100644 --- a/fixtures/ddn/subgraphs/sample_mflix/models/Theaters.hml +++ b/fixtures/ddn/sample_mflix/models/Theaters.hml @@ -15,8 +15,8 @@ definition: - name: zipcode type: String! graphql: - typeName: App_TheatersLocationAddress - inputTypeName: App_TheatersLocationAddressInput + typeName: TheatersLocationAddress + inputTypeName: TheatersLocationAddressInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: theaters_location_address @@ -47,8 +47,8 @@ definition: - name: type type: String! graphql: - typeName: App_TheatersLocationGeo - inputTypeName: App_TheatersLocationGeoInput + typeName: TheatersLocationGeo + inputTypeName: TheatersLocationGeoInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: theaters_location_geo @@ -76,8 +76,8 @@ definition: - name: geo type: TheatersLocationGeo! graphql: - typeName: App_TheatersLocation - inputTypeName: App_TheatersLocationInput + typeName: TheatersLocation + inputTypeName: TheatersLocationInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: theaters_location @@ -107,8 +107,8 @@ definition: - name: theaterId type: Int! graphql: - typeName: App_Theaters - inputTypeName: App_TheatersInput + typeName: Theaters + inputTypeName: TheatersInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: theaters @@ -155,7 +155,7 @@ definition: operators: enableAll: true graphql: - typeName: App_TheatersBoolExp + typeName: TheatersBoolExp --- kind: Model @@ -184,7 +184,7 @@ definition: - queryRootField: theatersById uniqueIdentifier: - id - orderByExpressionType: App_TheatersOrderBy + orderByExpressionType: TheatersOrderBy --- kind: ModelPermissions diff --git a/fixtures/ddn/subgraphs/sample_mflix/models/Users.hml b/fixtures/ddn/sample_mflix/models/Users.hml similarity index 93% rename from fixtures/ddn/subgraphs/sample_mflix/models/Users.hml rename to fixtures/ddn/sample_mflix/models/Users.hml index 9d0f656b..48f2c1f4 100644 --- a/fixtures/ddn/subgraphs/sample_mflix/models/Users.hml +++ b/fixtures/ddn/sample_mflix/models/Users.hml @@ -13,8 +13,8 @@ definition: - name: password type: String! graphql: - typeName: App_Users - inputTypeName: App_UsersInput + typeName: Users + inputTypeName: UsersInput dataConnectorTypeMapping: - dataConnectorName: sample_mflix dataConnectorObjectType: users @@ -68,7 +68,7 @@ definition: operators: enableAll: true graphql: - typeName: App_UsersBoolExp + typeName: UsersBoolExp --- kind: Model @@ -100,7 +100,7 @@ definition: - queryRootField: usersById uniqueIdentifier: - id - orderByExpressionType: App_UsersOrderBy + orderByExpressionType: UsersOrderBy --- kind: ModelPermissions From e59e62a5a2d45ae429678f6237b9d2b392b90e3d Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Sat, 13 Apr 2024 14:25:48 -0700 Subject: [PATCH 3/8] define a remote relationship --- arion-compose/project-connector.nix | 2 +- .../album_movie.hml | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 fixtures/ddn/remote-relationships_chinook-sample_mflix/album_movie.hml diff --git a/arion-compose/project-connector.nix b/arion-compose/project-connector.nix index 2dfd9bc8..16e58268 100644 --- a/arion-compose/project-connector.nix +++ b/arion-compose/project-connector.nix @@ -65,7 +65,7 @@ in ddn-dirs = [ ../fixtures/ddn/chinook ../fixtures/ddn/sample_mflix - # ../fixtures/ddn/remote-relationship-todo-todo + ../fixtures/ddn/remote-relationships_chinook-sample_mflix ]; otlp-endpoint = "http://jaeger:4317"; service.depends_on = { diff --git a/fixtures/ddn/remote-relationships_chinook-sample_mflix/album_movie.hml b/fixtures/ddn/remote-relationships_chinook-sample_mflix/album_movie.hml new file mode 100644 index 00000000..10d0bdf3 --- /dev/null +++ b/fixtures/ddn/remote-relationships_chinook-sample_mflix/album_movie.hml @@ -0,0 +1,17 @@ +# This is not a meaningful relationship, but it gives us something to test with. +kind: Relationship +version: v1 +definition: + name: movies + source: Album + target: + model: + name: Movies + relationshipType: Array + mapping: + - source: + fieldPath: + - fieldName: albumId + target: + modelField: + - fieldName: runtime From 2b7fa24dc3be7b470e27c89b5008399c457fc4b4 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Sat, 13 Apr 2024 18:24:04 -0700 Subject: [PATCH 4/8] update test to reproduce out-of-order foreach results --- .../mongodb-agent-common/src/query/foreach.rs | 89 ++++++++++++------- 1 file changed, 56 insertions(+), 33 deletions(-) diff --git a/crates/mongodb-agent-common/src/query/foreach.rs b/crates/mongodb-agent-common/src/query/foreach.rs index 6d8e120b..a2c92365 100644 --- a/crates/mongodb-agent-common/src/query/foreach.rs +++ b/crates/mongodb-agent-common/src/query/foreach.rs @@ -407,11 +407,12 @@ mod tests { async fn executes_foreach_with_variables() -> Result<(), anyhow::Error> { let query_request = QueryRequest { foreach: None, - variables: Some(vec![ - [("artistId".to_owned(), json!(1))].into(), - [("artistId".to_owned(), json!(2))].into(), - [("artistId".to_owned(), json!(3))].into(), - ]), + variables: Some( + (1..=12) + .into_iter() + .map(|artist_id| [("artistId".to_owned(), json!(artist_id))].into()) + .collect(), + ), target: dc_api_types::Target::TTable { name: vec!["tracks".to_owned()], }, @@ -454,30 +455,31 @@ mod tests { }), }; + fn facet(artist_id: i32) -> serde_json::Value { + json!([ + { "$match": { "artistId": {"$eq": artist_id } } }, + { "$replaceWith": { + "albumId": { "$ifNull": ["$albumId", null] }, + "title": { "$ifNull": ["$title", null] } + } }, + ]) + } + let expected_pipeline = json!([ { "$facet": { - "__FACET___0": [ - { "$match": { "artistId": {"$eq":1 } } }, - { "$replaceWith": { - "albumId": { "$ifNull": ["$albumId", null] }, - "title": { "$ifNull": ["$title", null] } - } }, - ], - "__FACET___1": [ - { "$match": { "artistId": {"$eq": 2 } } }, - { "$replaceWith": { - "albumId": { "$ifNull": ["$albumId", null] }, - "title": { "$ifNull": ["$title", null] } - } }, - ], - "__FACET___2": [ - { "$match": { "artistId": {"$eq": 3 } } }, - { "$replaceWith": { - "albumId": { "$ifNull": ["$albumId", null] }, - "title": { "$ifNull": ["$title", null] } - } }, - ] + "__FACET___0": facet(1), + "__FACET___1": facet(2), + "__FACET___2": facet(3), + "__FACET___3": facet(4), + "__FACET___4": facet(5), + "__FACET___5": facet(6), + "__FACET___6": facet(7), + "__FACET___7": facet(8), + "__FACET___8": facet(9), + "__FACET___9": facet(10), + "__FACET___10": facet(11), + "__FACET___11": facet(12), }, }, { @@ -486,6 +488,15 @@ mod tests { { "query": { "rows": "$__FACET___0" } }, { "query": { "rows": "$__FACET___1" } }, { "query": { "rows": "$__FACET___2" } }, + { "query": { "rows": "$__FACET___3" } }, + { "query": { "rows": "$__FACET___4" } }, + { "query": { "rows": "$__FACET___5" } }, + { "query": { "rows": "$__FACET___6" } }, + { "query": { "rows": "$__FACET___7" } }, + { "query": { "rows": "$__FACET___8" } }, + { "query": { "rows": "$__FACET___9" } }, + { "query": { "rows": "$__FACET___10" } }, + { "query": { "rows": "$__FACET___11" } }, ] }, } @@ -501,11 +512,7 @@ mod tests { ] } }, - { - "query": { - "rows": [] - } - }, + { "query": { "rows": [] } }, { "query": { "rows": [ @@ -513,7 +520,15 @@ mod tests { { "albumId": 3, "title": "Restless and Wild" } ] } - } + }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, ] }))?; @@ -544,7 +559,15 @@ mod tests { { "albumId": 3, "title": "Restless and Wild" } ] } - } + }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, + { "query": { "rows": [] } }, ], })?)])) }); From 723d9f99ba9388654244da90dfc3f8989718232f Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Sat, 13 Apr 2024 18:24:55 -0700 Subject: [PATCH 5/8] trace should be 'debug', not 'warn'; trace was crashing on query with variables --- .../mongodb-agent-common/src/query/execute_query_request.rs | 6 +++++- crates/mongodb-agent-common/src/query/mod.rs | 2 -- crates/mongodb-connector/src/mongo_connector.rs | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/mongodb-agent-common/src/query/execute_query_request.rs b/crates/mongodb-agent-common/src/query/execute_query_request.rs index 62a74fcd..33141295 100644 --- a/crates/mongodb-agent-common/src/query/execute_query_request.rs +++ b/crates/mongodb-agent-common/src/query/execute_query_request.rs @@ -11,7 +11,11 @@ pub async fn execute_query_request( query_request: QueryRequest, ) -> Result { let (pipeline, response_shape) = pipeline_for_query_request(&query_request)?; - tracing::debug!(pipeline = %serde_json::to_string(&pipeline).unwrap(), "aggregate pipeline"); + tracing::debug!( + ?query_request, + pipeline = %serde_json::to_string(&pipeline).unwrap(), + "executing query" + ); let document_cursor = collection.aggregate(pipeline, None).await?; diff --git a/crates/mongodb-agent-common/src/query/mod.rs b/crates/mongodb-agent-common/src/query/mod.rs index c5597604..515852c5 100644 --- a/crates/mongodb-agent-common/src/query/mod.rs +++ b/crates/mongodb-agent-common/src/query/mod.rs @@ -28,8 +28,6 @@ pub async fn handle_query_request( config: &MongoConfig, query_request: QueryRequest, ) -> Result { - tracing::debug!(?config, query_request = %serde_json::to_string(&query_request).unwrap(), "executing query"); - let database = config.client.database(&config.database); let collection = database.collection::(&collection_name(&query_request.target)); diff --git a/crates/mongodb-connector/src/mongo_connector.rs b/crates/mongodb-connector/src/mongo_connector.rs index e330095b..9479f947 100644 --- a/crates/mongodb-connector/src/mongo_connector.rs +++ b/crates/mongodb-connector/src/mongo_connector.rs @@ -149,6 +149,7 @@ impl Connector for MongoConnector { state: &Self::State, request: QueryRequest, ) -> Result, QueryError> { + tracing::debug!(query_request = %serde_json::to_string(&request).unwrap(), "received query request"); let v2_request = v3_to_v2_query_request( &QueryContext { functions: vec![], @@ -160,8 +161,6 @@ impl Connector for MongoConnector { let response = handle_query_request(state, v2_request) .await .map_err(mongo_agent_error_to_query_error)?; - let r = v2_to_v3_query_response(response); - tracing::warn!(v3_response = %serde_json::to_string(&r).unwrap()); - Ok(r.into()) + Ok(v2_to_v3_query_response(response).into()) } } From ae6012c2e9e4b5e65c53b9c4490389d10f3e9d44 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Sat, 13 Apr 2024 18:30:29 -0700 Subject: [PATCH 6/8] make order of query responses match order of variable sets --- crates/mongodb-agent-common/src/query/foreach.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/mongodb-agent-common/src/query/foreach.rs b/crates/mongodb-agent-common/src/query/foreach.rs index a2c92365..52d1cbd6 100644 --- a/crates/mongodb-agent-common/src/query/foreach.rs +++ b/crates/mongodb-agent-common/src/query/foreach.rs @@ -1,4 +1,4 @@ -use std::collections::{BTreeMap, HashMap}; +use std::collections::HashMap; use dc_api_types::comparison_column::ColumnSelector; use dc_api_types::{ @@ -56,7 +56,7 @@ pub fn pipeline_for_foreach( foreach: Vec, query_request: &QueryRequest, ) -> Result<(Pipeline, ResponseShape), MongoAgentError> { - let pipelines_with_response_shapes: BTreeMap = foreach + let pipelines_with_response_shapes: Vec<(String, (Pipeline, ResponseShape))> = foreach .into_iter() .enumerate() .map(|(index, foreach_variant)| { From 9bb0977e7b4e9a84f12c4dedeffdec2d6f85b24b Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Sat, 13 Apr 2024 18:36:45 -0700 Subject: [PATCH 7/8] lint fix --- crates/mongodb-agent-common/src/query/foreach.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/mongodb-agent-common/src/query/foreach.rs b/crates/mongodb-agent-common/src/query/foreach.rs index 52d1cbd6..0858fb0b 100644 --- a/crates/mongodb-agent-common/src/query/foreach.rs +++ b/crates/mongodb-agent-common/src/query/foreach.rs @@ -409,7 +409,6 @@ mod tests { foreach: None, variables: Some( (1..=12) - .into_iter() .map(|artist_id| [("artistId".to_owned(), json!(artist_id))].into()) .collect(), ), From 1d42d28b813a760dc904add4127b027bf8253f25 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Sat, 13 Apr 2024 18:46:34 -0700 Subject: [PATCH 8/8] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c329333..73621a7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This changelog documents the changes between release versions. - Fixed bug where use of aggregate functions in queries would fail ([#26](https://github.com/hasura/ndc-mongodb/pull/26)) - Rename Any type to ExtendedJSON to make its representation clearer ([#30](https://github.com/hasura/ndc-mongodb/pull/30)) - The collection primary key `_id` property now has a unique constraint generated in the NDC schema for it ([#32](https://github.com/hasura/ndc-mongodb/pull/32)) +- Fix incorrect order of results for query requests with more than 10 variable sets (#37) ## [0.0.3] - 2024-03-28 - Use separate schema files for each collection ([PR #14](https://github.com/hasura/ndc-mongodb/pull/14))