Skip to content

Commit

Permalink
fix(qe): coerce nulls to empty lists in nested relations with joins (#…
Browse files Browse the repository at this point in the history
…4547)

Currently we coerce database NULL values to empty scalar lists in the
regular code path that converts quaint values to `PrismaValue`s, but
this was missing in the new code path that converts the results of JSON
aggregation to `PrismaValue`s when using `relationJoins` preview feature.

Fixes: prisma/prisma#22303
  • Loading branch information
aqrln authored Dec 8, 2023
1 parent 3f58f40 commit e7a7287
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ in
nodejs.pkgs.typescript-language-server
nodejs.pkgs.pnpm

cargo-insta
jq
graphviz
wasm-bindgen-cli
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ mod scalar_relations {
bytes Bytes[]
bool Boolean[]
dt DateTime[]
empty Int[]
unset Int[]
}
"#
};
Expand All @@ -254,19 +256,20 @@ mod scalar_relations {
bytes: ["AQID", "Qk9OSk9VUg=="],
bool: [false, true],
dt: ["1900-10-10T01:10:10.001Z", "1999-12-12T21:12:12.121Z"],
empty: []
}"#,
)
.await?;
create_parent(&runner, r#"{ id: 1, children: { connect: [{ childId: 1 }] } }"#).await?;

insta::assert_snapshot!(
run_query!(&runner, r#"{ findManyParent { id children { childId string int bInt float bytes bool dt } } }"#),
@r###"{"data":{"findManyParent":[{"id":1,"children":[{"childId":1,"string":["abc","def"],"int":[1,-1,1234567],"bInt":["1","-1","9223372036854775807","-9223372036854775807"],"float":[1.5,-1.5,1.234567],"bytes":["AQID","Qk9OSk9VUg=="],"bool":[false,true],"dt":["1900-10-10T01:10:10.001Z","1999-12-12T21:12:12.121Z"]}]}]}}"###
run_query!(&runner, r#"{ findManyParent { id children { childId string int bInt float bytes bool dt empty unset } } }"#),
@r###"{"data":{"findManyParent":[{"id":1,"children":[{"childId":1,"string":["abc","def"],"int":[1,-1,1234567],"bInt":["1","-1","9223372036854775807","-9223372036854775807"],"float":[1.5,-1.5,1.234567],"bytes":["AQID","Qk9OSk9VUg=="],"bool":[false,true],"dt":["1900-10-10T01:10:10.001Z","1999-12-12T21:12:12.121Z"],"empty":[],"unset":[]}]}]}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"{ findUniqueParent(where: { id: 1 }) { id children { childId string int bInt float bytes bool dt } } }"#),
@r###"{"data":{"findUniqueParent":{"id":1,"children":[{"childId":1,"string":["abc","def"],"int":[1,-1,1234567],"bInt":["1","-1","9223372036854775807","-9223372036854775807"],"float":[1.5,-1.5,1.234567],"bytes":["AQID","Qk9OSk9VUg=="],"bool":[false,true],"dt":["1900-10-10T01:10:10.001Z","1999-12-12T21:12:12.121Z"]}]}}}"###
run_query!(&runner, r#"{ findUniqueParent(where: { id: 1 }) { id children { childId string int bInt float bytes bool dt empty unset } } }"#),
@r###"{"data":{"findUniqueParent":{"id":1,"children":[{"childId":1,"string":["abc","def"],"int":[1,-1,1234567],"bInt":["1","-1","9223372036854775807","-9223372036854775807"],"float":[1.5,-1.5,1.234567],"bytes":["AQID","Qk9OSk9VUg=="],"bool":[false,true],"dt":["1900-10-10T01:10:10.001Z","1999-12-12T21:12:12.121Z"],"empty":[],"unset":[]}]}}}"###
);

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ pub(crate) fn coerce_json_scalar_to_pv(value: serde_json::Value, sf: &ScalarFiel
}

match value {
serde_json::Value::Null => Ok(PrismaValue::Null),
serde_json::Value::Null => {
if sf.is_list() {
Ok(PrismaValue::List(vec![]))
} else {
Ok(PrismaValue::Null)
}
}
serde_json::Value::Bool(b) => Ok(PrismaValue::Boolean(b)),
serde_json::Value::Number(n) => match sf.type_identifier() {
TypeIdentifier::Int => Ok(PrismaValue::Int(n.as_i64().ok_or_else(|| {
Expand Down

0 comments on commit e7a7287

Please sign in to comment.