-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qe: Fix nested objects with
$type
key in JSON protocol
Introduce another special value to JSON protocol, `"$type": "Raw"`. When encountered, no other nested `$type` keys would be interpreted as special and will be written to DB as is. Main usecase is JSON column values with user-provided `$type` keys. This is an alternative to #4668, that might look cleaner on the engine side. Part of the fix for prisma/prisma#21454, will require client adjustments as well.
- Loading branch information
Sergey Tatarintsev
committed
Jan 24, 2024
1 parent
c1c3774
commit b25998a
Showing
7 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_21454.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use query_engine_tests::*; | ||
|
||
#[test_suite(schema(schema), capabilities(Json))] | ||
mod prisma_21454 { | ||
|
||
fn schema() -> String { | ||
let schema = indoc! { | ||
r#" | ||
model Model { | ||
#id(id, String, @id) | ||
json Json | ||
} | ||
"# | ||
}; | ||
|
||
schema.to_owned() | ||
} | ||
|
||
#[connector_test] | ||
async fn dollar_type_in_json(runner: Runner) -> TestResult<()> { | ||
let res = runner | ||
.query_json( | ||
r#"{ | ||
"modelName": "Model", | ||
"action": "createOne", | ||
"query": { | ||
"selection": { "json": true }, | ||
"arguments": { | ||
"data": { | ||
"id": "123", | ||
"json": { "$type": "Raw", "value": {"$type": "Something" } } | ||
} | ||
} | ||
} | ||
}"#, | ||
) | ||
.await?; | ||
|
||
res.assert_success(); | ||
|
||
insta::assert_snapshot!(res.to_string(), @r###"{"data":{"createOneModel":{"json":{"$type":"Json","value":"{\"$type\":\"Something\"}"}}}}"###); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[connector_test] | ||
async fn nested_dollar_type_in_json(runner: Runner) -> TestResult<()> { | ||
let res = runner | ||
.query_json( | ||
r#"{ | ||
"modelName": "Model", | ||
"action": "createOne", | ||
"query": { | ||
"selection": { "json": true }, | ||
"arguments": { | ||
"data": { | ||
"id": "123", | ||
"json": { | ||
"something": { "$type": "Raw", "value": {"$type": "Something" } } | ||
} | ||
} | ||
} | ||
} | ||
}"#, | ||
) | ||
.await?; | ||
|
||
res.assert_success(); | ||
|
||
insta::assert_snapshot!(res.to_string(), @r###"{"data":{"createOneModel":{"json":{"$type":"Json","value":"{\"something\":{\"$type\":\"Something\"}}"}}}}"###); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters