Skip to content

Commit

Permalink
test query on relationship using nested key
Browse files Browse the repository at this point in the history
  • Loading branch information
hallettj committed Jan 14, 2025
1 parent 97215f2 commit 15d4e1a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 34 additions & 1 deletion crates/integration-tests/src/tests/local_relationship.rs
Original file line number Diff line number Diff line change
@@ -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<()> {
Expand Down Expand Up @@ -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(())
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 15d4e1a

Please sign in to comment.