diff --git a/CHANGELOG.md b/CHANGELOG.md index 63297b38..edfe3954 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ described by [ndc-spec](https://hasura.github.io/ndc-spec/). Version 0.2 makes a number of improvements to the spec, and enables features that were previously not possible. Highlights of those new features include: +- relationships can use a nested object field on the target side as a join key - grouping result documents, and aggregating on groups of documents (pending implementation in the mongo connector) - queries on fields of nested collections (document fields that are arrays of objects) - filtering on scalar values inside array document fields - previously it was possible to filter on fields of objects inside arrays, but not on scalars diff --git a/crates/integration-tests/src/tests/local_relationship.rs b/crates/integration-tests/src/tests/local_relationship.rs index 13d3b051..5906d8eb 100644 --- a/crates/integration-tests/src/tests/local_relationship.rs +++ b/crates/integration-tests/src/tests/local_relationship.rs @@ -1,6 +1,9 @@ use crate::{connector::Connector, graphql_query, run_connector_query}; use insta::assert_yaml_snapshot; -use ndc_test_helpers::{asc, field, query, query_request, relation_field, relationship}; +use ndc_test_helpers::{ + asc, binop, exists, field, query, query_request, related, relation_field, + relationship, target, value, +}; #[tokio::test] async fn joins_local_relationships() -> anyhow::Result<()> { @@ -210,3 +213,33 @@ async fn joins_on_field_names_that_require_escaping() -> anyhow::Result<()> { ); Ok(()) } + +#[tokio::test] +async fn joins_relationships_on_nested_key() -> anyhow::Result<()> { + assert_yaml_snapshot!( + run_connector_query( + Connector::TestCases, + query_request() + .collection("departments") + .query( + query() + .predicate(exists( + related!("schools_departments"), + binop("_eq", target!("name"), value!("West Valley")) + )) + .fields([ + relation_field!("departments" => "schools_departments", query().fields([ + field!("name") + ])) + ]) + .order_by([asc!("_id")]) + ) + .relationships([( + "schools_departments", + relationship("schools", [("_id", &["departments", "math_department_id"])]) + )]) + ) + .await? + ); + Ok(()) +} diff --git a/crates/integration-tests/src/tests/snapshots/integration_tests__tests__local_relationship__joins_relationships_on_nested_key.snap b/crates/integration-tests/src/tests/snapshots/integration_tests__tests__local_relationship__joins_relationships_on_nested_key.snap new file mode 100644 index 00000000..2200e9e1 --- /dev/null +++ b/crates/integration-tests/src/tests/snapshots/integration_tests__tests__local_relationship__joins_relationships_on_nested_key.snap @@ -0,0 +1,8 @@ +--- +source: crates/integration-tests/src/tests/local_relationship.rs +expression: "run_connector_query(Connector::TestCases,\nquery_request().collection(\"departments\").query(query().predicate(exists(related!(\"schools_departments\"),\nbinop(\"_eq\", target!(\"name\"),\nvalue!(\"West Valley\")))).fields([relation_field!(\"departments\" =>\n\"schools_departments\",\nquery().fields([field!(\"name\")]))]).order_by([asc!(\"_id\")])).relationships([(\"schools_departments\",\nrelationship(\"schools\",\n[(\"_id\", &[\"departments\", \"math_department_id\"])]))])).await?" +--- +- rows: + - departments: + rows: + - name: West Valley