Skip to content

Commit 8eff7f5

Browse files
committed
feat(qc): make placeholders typed at JSON protocol level (#5738)
Require placeholder types to be specified in the JSON protocol representation of the placholders and parse them in `JsonProtocolAdapter`.
1 parent 3f83219 commit 8eff7f5

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

libs/prisma-value/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl std::fmt::Display for PrismaValueType {
129129
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, PartialOrd, Ord)]
130130
pub struct Placeholder {
131131
pub name: Cow<'static, str>,
132+
#[serde(flatten)]
132133
pub r#type: PrismaValueType,
133134
}
134135

query-compiler/query-compiler-playground/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ pub fn main() -> anyhow::Result<()> {
4545
"where": {
4646
"email": {
4747
"$type": "Param",
48-
"value": "userEmail"
48+
"value": {
49+
"name": "userEmail",
50+
"type": "String"
51+
}
4952
}
5053
}
5154
},

query-compiler/request-handlers/src/protocols/json/protocol_adapter.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use query_core::{
66
constants::custom_types,
77
schema::{ObjectType, OutputField, QuerySchema},
88
};
9-
use query_structure::{Field, PrismaValue, PrismaValueType, decode_bytes, parse_datetime, prelude::ParentContainer};
9+
use query_structure::{Field, PrismaValue, decode_bytes, parse_datetime, prelude::ParentContainer};
1010
use serde_json::Value as JsonValue;
1111
use std::str::FromStr;
1212

@@ -244,15 +244,11 @@ impl<'a> JsonProtocolAdapter<'a> {
244244
Ok(ArgumentValue::FieldRef(values))
245245
}
246246
Some(custom_types::PARAM) => {
247-
let name = obj
248-
.get(custom_types::VALUE)
249-
.and_then(|v| v.as_str())
250-
.ok_or_else(build_err)?
251-
.to_owned();
252-
253-
let placeholder = PrismaValue::placeholder(name, PrismaValueType::Any);
247+
let value = obj.remove(custom_types::VALUE).ok_or_else(build_err)?;
248+
let placeholder =
249+
serde_json::from_value(value).map_err(|e| HandlerError::QueryConversion(e.to_string()))?;
254250

255-
Ok(ArgumentValue::Scalar(placeholder))
251+
Ok(ArgumentValue::Scalar(PrismaValue::Placeholder(placeholder)))
256252
}
257253
_ => {
258254
let values = obj

0 commit comments

Comments
 (0)