Skip to content

Commit

Permalink
Change format, so the model name is infix rather than suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Nov 4, 2022
1 parent 96b2b4f commit 8481c0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ mod find_first_or_throw_query {

assert_query!(
runner,
"query { findFirstOrThrowTestModel(where: { id: 1 }) { id }}",
r#"{"data":{"findFirstOrThrowTestModel":{"id":1}}}"#
"query { findFirstTestModelOrThrow(where: { id: 1 }) { id }}",
r#"{"data":{"findFirstTestModelOrThrow":{"id":1}}}"#
);

assert_query!(
runner,
"query { findFirstOrThrowTestModel(where: { field: { not: null }}) { id }}",
r#"{"data":{"findFirstOrThrowTestModel":{"id":1}}}"#
"query { findFirstTestModelOrThrow(where: { field: { not: null }}) { id }}",
r#"{"data":{"findFirstTestModelOrThrow":{"id":1}}}"#
);

assert_query!(
runner,
"query { findFirstOrThrowTestModel(where: { field: { not: null }}, orderBy: { id: desc }) { id }}",
r#"{"data":{"findFirstOrThrowTestModel":{"id":5}}}"#
"query { findFirstTestModelOrThrow(where: { field: { not: null }}, orderBy: { id: desc }) { id }}",
r#"{"data":{"findFirstTestModelOrThrow":{"id":5}}}"#
);

assert_query!(
runner,
"query { findFirstOrThrowTestModel(where: { field: { not: null }}, cursor: { id: 1 }, take: 1, skip: 1, orderBy: { id: asc }) { id }}",
r#"{"data":{"findFirstOrThrowTestModel":{"id":2}}}"#
"query { findFirstTestModelOrThrow(where: { field: { not: null }}, cursor: { id: 1 }, take: 1, skip: 1, orderBy: { id: asc }) { id }}",
r#"{"data":{"findFirstTestModelOrThrow":{"id":2}}}"#
);

Ok(())
Expand All @@ -41,7 +41,7 @@ mod find_first_or_throw_query {

assert_error!(
&runner,
"query { findFirstOrThrowTestModel(where: { id: 6 }) { id }}",
"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."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ mod find_unique_or_throw {

assert_query!(
&runner,
r#"query { findUniqueOrThrowUser(where: { email: "a@b.com" }) { id } }"#,
r#"{"data":{"findUniqueOrThrowUser":{"id":1}}}"#
r#"query { findUniqueUserOrThrow(where: { email: "a@b.com" }) { id } }"#,
r#"{"data":{"findUniqueUserOrThrow":{"id":1}}}"#
);

assert_query!(
&runner,
r#"query { findUniqueOrThrowUser(where: { first_name_last_name: { first_name: "Elongated", last_name: "Muskrat" } }) { id } }"#,
r#"{"data":{"findUniqueOrThrowUser":{"id":1}}}"#
r#"query { findUniqueUserOrThrow(where: { first_name_last_name: { first_name: "Elongated", last_name: "Muskrat" } }) { id } }"#,
r#"{"data":{"findUniqueUserOrThrow":{"id":1}}}"#
);

assert_query!(
runner,
"query { findUniqueOrThrowUser(where: { id: 1 }) { id } }",
r#"{"data":{"findUniqueOrThrowUser":{"id":1}}}"#
"query { findUniqueUserOrThrow(where: { id: 1 }) { id } }",
r#"{"data":{"findUniqueUserOrThrow":{"id":1}}}"#
);

Ok(())
Expand All @@ -35,7 +35,7 @@ mod find_unique_or_throw {

assert_error!(
&runner,
"query { findUniqueOrThrowUser(where: { id: 2 }) { id } }",
"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."
);
Expand All @@ -49,7 +49,7 @@ mod find_unique_or_throw {

assert_error!(
&runner,
r#"query { findUniqueOrThrowUser(where: { email: "b@a.com" }) { id } }"#,
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."
);
Expand All @@ -63,7 +63,7 @@ mod find_unique_or_throw {

assert_error!(
&runner,
r#"query { findUniqueOrThrowUser(where: { first_name_last_name: { first_name: "Doesn't", last_name: "Exist" } }) { id } }"#,
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."
);
Expand Down
4 changes: 2 additions & 2 deletions query-engine/schema-builder/src/output_types/query_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn find_unique_field(ctx: &mut BuilderContext, model: &ModelRef) -> Option<Outpu
/// that will throw a NotFoundError if the item is not found
fn find_unique_or_throw_field(ctx: &mut BuilderContext, model: &ModelRef) -> Option<OutputField> {
arguments::where_unique_argument(ctx, model).map(|arg| {
let field_name = format!("findUniqueOrThrow{}", model.name);
let field_name = format!("findUnique{}OrThrow", model.name);

field(
field_name,
Expand Down Expand Up @@ -92,7 +92,7 @@ fn find_first_field(ctx: &mut BuilderContext, model: &ModelRef) -> OutputField {
/// not exist
fn find_first_or_throw_field(ctx: &mut BuilderContext, model: &ModelRef) -> OutputField {
let args = arguments::relation_selection_arguments(ctx, model, true);
let field_name = format!("findFirstOrThrow{}", model.name);
let field_name = format!("findFirst{}OrThrow", model.name);

field(
field_name,
Expand Down

0 comments on commit 8481c0d

Please sign in to comment.