-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(qe): Implement findFirstOrThrow and findUniqeOrThrow in the engine #3356
Changes from all commits
3fed088
0af8b74
e9c78ea
a9c2311
9ce5fbf
0dd9c8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ mod find_first_query { | |
use query_engine_tests::assert_query; | ||
|
||
#[connector_test] | ||
async fn fetch_first_matching(runner: Runner) -> TestResult<()> { | ||
async fn find_first_matching(runner: Runner) -> TestResult<()> { | ||
test_data(&runner).await?; | ||
|
||
assert_query!( | ||
|
@@ -35,6 +35,19 @@ mod find_first_query { | |
Ok(()) | ||
} | ||
|
||
#[connector_test] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a failure case for |
||
async fn find_first_not_matching(runner: Runner) -> TestResult<()> { | ||
test_data(&runner).await?; | ||
|
||
assert_query!( | ||
runner, | ||
"query { findFirstTestModel(where: { id: 6 }) { id }}", | ||
r#"{"data":{"findFirstTestModel":null}}"# | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn test_data(runner: &Runner) -> TestResult<()> { | ||
test_row(runner, r#"{ id: 1, field: "test1" }"#).await?; | ||
test_row(runner, r#"{ id: 2, field: "test2" }"#).await?; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use query_engine_tests::*; | ||
|
||
#[test_suite(schema(schemas::generic))] | ||
mod find_first_or_throw_query { | ||
use query_engine_tests::assert_query; | ||
|
||
#[connector_test] | ||
async fn find_first_or_throw_matching(runner: Runner) -> TestResult<()> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test case to ensure that |
||
test_data(&runner).await?; | ||
|
||
assert_query!( | ||
runner, | ||
"query { findFirstTestModelOrThrow(where: { id: 1 }) { id }}", | ||
r#"{"data":{"findFirstTestModelOrThrow":{"id":1}}}"# | ||
); | ||
|
||
assert_query!( | ||
runner, | ||
"query { findFirstTestModelOrThrow(where: { field: { not: null }}) { id }}", | ||
r#"{"data":{"findFirstTestModelOrThrow":{"id":1}}}"# | ||
); | ||
|
||
assert_query!( | ||
runner, | ||
"query { findFirstTestModelOrThrow(where: { field: { not: null }}, orderBy: { id: desc }) { id }}", | ||
r#"{"data":{"findFirstTestModelOrThrow":{"id":5}}}"# | ||
); | ||
|
||
assert_query!( | ||
runner, | ||
"query { findFirstTestModelOrThrow(where: { field: { not: null }}, cursor: { id: 1 }, take: 1, skip: 1, orderBy: { id: asc }) { id }}", | ||
r#"{"data":{"findFirstTestModelOrThrow":{"id":2}}}"# | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[connector_test] | ||
async fn find_first_or_throw_not_matching(runner: Runner) -> TestResult<()> { | ||
test_data(&runner).await?; | ||
|
||
assert_error!( | ||
&runner, | ||
"query { findFirstTestModelOrThrow(where: { id: 6 }) { id }}", | ||
2025, | ||
"An operation failed because it depends on one or more records that were required but not found. Expected a record, found none." | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn test_data(runner: &Runner) -> TestResult<()> { | ||
test_row(runner, r#"{ id: 1, field: "test1" }"#).await?; | ||
test_row(runner, r#"{ id: 2, field: "test2" }"#).await?; | ||
test_row(runner, r#"{ id: 3 }"#).await?; | ||
test_row(runner, r#"{ id: 4 }"#).await?; | ||
test_row(runner, r#"{ id: 5, field: "test3" }"#).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn test_row(runner: &Runner, data: &str) -> TestResult<()> { | ||
runner | ||
.query(format!("mutation {{ createOneTestModel(data: {}) {{ id }} }}", data)) | ||
.await? | ||
.assert_success(); | ||
Ok(()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use query_engine_tests::*; | ||
|
||
#[test_suite(schema(schemas::user))] | ||
mod find_unique_or_throw { | ||
use query_engine_tests::assert_query; | ||
|
||
#[connector_test] | ||
async fn find_unique_or_throw_when_record_is_found(runner: Runner) -> TestResult<()> { | ||
test_user(&runner).await?; | ||
|
||
assert_query!( | ||
&runner, | ||
r#"query { findUniqueUserOrThrow(where: { email: "a@b.com" }) { id } }"#, | ||
r#"{"data":{"findUniqueUserOrThrow":{"id":1}}}"# | ||
); | ||
|
||
assert_query!( | ||
&runner, | ||
r#"query { findUniqueUserOrThrow(where: { first_name_last_name: { first_name: "Elongated", last_name: "Muskrat" } }) { id } }"#, | ||
r#"{"data":{"findUniqueUserOrThrow":{"id":1}}}"# | ||
); | ||
|
||
assert_query!( | ||
runner, | ||
"query { findUniqueUserOrThrow(where: { id: 1 }) { id } }", | ||
r#"{"data":{"findUniqueUserOrThrow":{"id":1}}}"# | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[connector_test] | ||
async fn no_result_find_unique_by_id(runner: Runner) -> TestResult<()> { | ||
test_user(&runner).await?; | ||
|
||
assert_error!( | ||
&runner, | ||
"query { findUniqueUserOrThrow(where: { id: 2 }) { id } }", | ||
2025, | ||
"An operation failed because it depends on one or more records that were required but not found. Expected a record, found none." | ||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the error returned to the user, which as per this method is a ConnectorError rendering this |
||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[connector_test] | ||
async fn no_result_find_unique_by_single_unique(runner: Runner) -> TestResult<()> { | ||
test_user(&runner).await?; | ||
|
||
assert_error!( | ||
&runner, | ||
r#"query { findUniqueUserOrThrow(where: { email: "b@a.com" }) { id } }"#, | ||
2025, | ||
"An operation failed because it depends on one or more records that were required but not found. Expected a record, found none." | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[connector_test] | ||
async fn no_result_find_unique_by_multi_unique(runner: Runner) -> TestResult<()> { | ||
test_user(&runner).await?; | ||
|
||
assert_error!( | ||
&runner, | ||
r#"query { findUniqueUserOrThrow(where: { first_name_last_name: { first_name: "Doesn't", last_name: "Exist" } }) { id } }"#, | ||
2025, | ||
"An operation failed because it depends on one or more records that were required but not found. Expected a record, found none." | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn test_user(runner: &Runner) -> TestResult<()> { | ||
runner | ||
.query(r#"mutation { createOneUser(data: { id: 1, email: "a@b.com", first_name: "Elongated", last_name: "Muskrat" }) { id } }"#) | ||
.await?.assert_success(); | ||
|
||
Ok(()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a small replacement of fetch -> find on the test cases