Skip to content

Commit

Permalink
fix: query graph should extract join results using prisma field name (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky committed Feb 16, 2024
1 parent c9d2b81 commit 8110687
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod prisma_13405;
mod prisma_14001;
mod prisma_14696;
mod prisma_14703;
mod prisma_15177;
mod prisma_15204;
mod prisma_15264;
mod prisma_15467;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use indoc::indoc;
use query_engine_tests::*;

#[test_suite(schema(schema), exclude(MongoDb))]
mod prisma_15177 {
fn schema() -> String {
let schema = indoc! {
r#"model Customer {
#id(userId, Int, @id @map("user id"))
}"#
};

schema.to_owned()
}

// Should allow CRUD methods on a table column that has a space
#[connector_test]
async fn repro(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneCustomer(data: { userId: 1 }) { userId } }"#),
@r###"{"data":{"createOneCustomer":{"userId":1}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"{ findManyCustomer { userId } }"#),
@r###"{"data":{"findManyCustomer":[{"userId":1}]}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { updateOneCustomer(where: { userId: 1 }, data: { userId: 2 }) { userId } }"#),
@r###"{"data":{"updateOneCustomer":{"userId":2}}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { deleteOneCustomer(where: { userId: 2 }) { userId } }"#),
@r###"{"data":{"deleteOneCustomer":{"userId":2}}}"###
);

Ok(())
}
}
2 changes: 1 addition & 1 deletion query-engine/core/src/interpreter/interpreter_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ExpressionResult {
),
QueryResult::RecordSelectionWithRelations(rsr) => Some(
rsr.records
.extract_selection_results(field_selection)
.extract_selection_results_from_prisma_name(field_selection)
.expect("Expected record selection to contain required model ID fields.")
.into_iter()
.collect(),
Expand Down
27 changes: 27 additions & 0 deletions query-engine/query-structure/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ impl ManyRecords {
.collect()
}

/// Builds `SelectionResults` from this `ManyRecords` based on the given FieldSelection.
pub fn extract_selection_results_from_prisma_name(
&self,
selections: &FieldSelection,
) -> crate::Result<Vec<SelectionResult>> {
self.records
.iter()
.map(|record| record.extract_selection_result_from_prisma_name(&self.field_names, selections))
.collect()
}

/// Maps into a Vector of (field_name, value) tuples
pub fn as_pairs(&self) -> Vec<Vec<(String, PrismaValue)>> {
self.records
Expand Down Expand Up @@ -180,6 +191,22 @@ impl Record {
Ok(SelectionResult::new(pairs))
}

pub fn extract_selection_result_from_prisma_name(
&self,
field_names: &[String],
extraction_selection: &FieldSelection,
) -> crate::Result<SelectionResult> {
let pairs: Vec<_> = extraction_selection
.selections()
.map(|selection| {
self.get_field_value(field_names, &selection.prisma_name())
.and_then(|val| Ok((selection.clone(), selection.coerce_value(val.clone())?)))
})
.collect::<crate::Result<Vec<_>>>()?;

Ok(SelectionResult::new(pairs))
}

pub fn identifying_values(
&self,
field_names: &[String],
Expand Down

0 comments on commit 8110687

Please sign in to comment.