Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(query-engine-wasm): slimmer core on wasm32 target arch #4624

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d9d82a7
feat(query-engine-wasm): fix JSON protocol on wasm32
jkomyno Jan 2, 2024
1f390e8
feat(query-engine-wasm): move clone to reduce binary size
jkomyno Jan 2, 2024
ff82105
feat(query-engine-wasm): remove clone from PrismaValue::try_from
jkomyno Jan 2, 2024
b4a63b6
feat(query-engine-wasm): remove redundant mut and unwrap
jkomyno Jan 2, 2024
efb435f
feat(query-engine-wasm): remove redundant clone
jkomyno Jan 2, 2024
e735c82
feat(query-engine-wasm): remove redundant clone
jkomyno Jan 2, 2024
27e9262
Revert "feat(query-engine-wasm): remove redundant clone" due to binar…
jkomyno Jan 2, 2024
eb129a2
Revert "feat(query-engine-wasm): remove redundant clone" due to size …
jkomyno Jan 2, 2024
c823a6b
chore(query-engine-wasm): fix clippy
jkomyno Jan 2, 2024
753d9db
chore(query-engine-wasm): fix clippy
jkomyno Jan 2, 2024
b8797af
Merge branch 'main' into fix/clippy
jkomyno Jan 2, 2024
43ae805
chore(query-engine-wasm): fix clippy
jkomyno Jan 2, 2024
52d4bb8
Merge branch 'fix/clippy' of github.com:prisma/prisma-engines into fi…
jkomyno Jan 2, 2024
9abaa12
Merge branch 'fix/clippy' into feat/slimmer-core-wasm
jkomyno Jan 2, 2024
d8e6a9e
chore(query-engine-wasm): fix clippy
jkomyno Jan 2, 2024
b00902f
Merge branch 'fix/clippy' into feat/slimmer-core-wasm
jkomyno Jan 2, 2024
a4f39a7
chore(query-engine-wasm): fix clippy
jkomyno Jan 2, 2024
3adfa58
chore(query-engine-wasm): fix clippy
jkomyno Jan 2, 2024
f88155e
chore(query-engine-wasm): fix clippy
jkomyno Jan 2, 2024
1b12707
Merge branch 'fix/clippy' into feat/slimmer-core-wasm
jkomyno Jan 2, 2024
4ac1dde
Merge branch 'main' into feat/slimmer-core-wasm
jkomyno Jan 3, 2024
bf7f1c7
chore(query-engine-wasm): fix query validation tests
jkomyno Jan 3, 2024
a00dc8e
Merge branch 'feat/slimmer-core-wasm' of github.com:prisma/prisma-eng…
jkomyno Jan 3, 2024
34bfe42
chore(query-engine-wasm): fix clippy
jkomyno Jan 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions libs/prisma-value/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ pub fn decode_bytes(s: &str) -> PrismaValueResult<Vec<u8>> {
base64::decode(s).map_err(|_| ConversionFailure::new("base64 encoded bytes", "PrismaValue::Bytes"))
}

impl TryFrom<serde_json::Value> for PrismaValue {
impl TryFrom<&serde_json::Value> for PrismaValue {
type Error = crate::error::ConversionFailure;

fn try_from(v: serde_json::Value) -> PrismaValueResult<Self> {
fn try_from(v: &serde_json::Value) -> PrismaValueResult<Self> {
match v {
serde_json::Value::String(s) => Ok(PrismaValue::String(s)),
serde_json::Value::String(s) => Ok(PrismaValue::String(s.to_owned())),
serde_json::Value::Array(v) => {
let vals: PrismaValueResult<Vec<PrismaValue>> = v.into_iter().map(PrismaValue::try_from).collect();
let vals: PrismaValueResult<Vec<PrismaValue>> = v.iter().map(PrismaValue::try_from).collect();
Ok(PrismaValue::List(vals?))
}
serde_json::Value::Null => Ok(PrismaValue::Null),
serde_json::Value::Bool(b) => Ok(PrismaValue::Boolean(b)),
serde_json::Value::Bool(b) => Ok(PrismaValue::Boolean(*b)),
serde_json::Value::Number(num) => {
if num.is_i64() {
Ok(PrismaValue::Int(num.as_i64().unwrap()))
Expand Down
23 changes: 23 additions & 0 deletions query-engine/core/src/executor/request_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,26 @@ where
REQUEST_CONTEXT.scope(ctx, fut).await
}
}

#[cfg(target_arch = "wasm32")]
mod arch {
#[inline(always)]
pub(crate) fn is_engine_protocol_json() -> bool {
true
}
}

#[cfg(not(target_arch = "wasm32"))]
mod arch {
use super::*;

pub(crate) fn is_engine_protocol_json() -> bool {
REQUEST_CONTEXT
.try_with(|rc| rc.engine_protocol)
.ok()
.map(|p| p.is_json())
== Some(true)
}
}

pub(crate) use arch::is_engine_protocol_json;
20 changes: 10 additions & 10 deletions query-engine/core/src/query_document/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::{executor::get_engine_protocol, schema::*};
use crate::{executor::is_engine_protocol_json, schema::*};
use bigdecimal::{BigDecimal, ToPrimitive};
use chrono::prelude::*;
use core::fmt;
Expand Down Expand Up @@ -229,29 +229,29 @@ impl QueryDocumentParser {
};
}

let is_protocol_json = is_engine_protocol_json();

for input_type in possible_input_types {
match (value.clone(), input_type) {
match (&value, input_type) {
// With the JSON protocol, JSON values are sent as deserialized values.
// This means JSON can match with pretty much anything. A string, an int, an object, an array.
// This is an early catch-all.
// We do not get into this catch-all _if_ the value is already Json, if it's a FieldRef or if it's an Enum.
// We don't because they've already been desambiguified at the procotol adapter level.
(value, InputType::<'a>::Scalar(ScalarType::Json))
if value.should_be_parsed_as_json() && get_engine_protocol().is_json() =>
if value.should_be_parsed_as_json() && is_protocol_json =>
{
return Ok(ParsedInputValue::Single(self.to_json(
&selection_path,
&argument_path,
&value,
value,
)?))
}
// With the JSON protocol, JSON values are sent as deserialized values.
// This means that a JsonList([1, 2]) will be coerced as an `ArgumentValue::List([1, 2])`.
// We need this early matcher to make sure we coerce this array back to JSON.
(list @ ArgumentValue::List(_), InputType::Scalar(ScalarType::JsonList))
if get_engine_protocol().is_json() =>
{
let json_val = serde_json::to_value(list.clone()).map_err(|err| {
(list @ ArgumentValue::List(_), InputType::Scalar(ScalarType::JsonList)) if is_protocol_json => {
let json_val = serde_json::to_value(list).map_err(|err| {
ValidationError::invalid_argument_value(
selection_path.segments(),
argument_path.segments(),
Expand All @@ -264,7 +264,7 @@ impl QueryDocumentParser {

return Ok(ParsedInputValue::Single(json_list));
}
(ArgumentValue::Scalar(pv), input_type) => match (pv, input_type) {
(ArgumentValue::Scalar(pv), input_type) => match (pv.clone(), input_type) {
// Null handling
(PrismaValue::Null, InputType::Scalar(ScalarType::Null)) => {
return Ok(ParsedInputValue::Single(PrismaValue::Null))
Expand Down Expand Up @@ -502,7 +502,7 @@ impl QueryDocumentParser {
let mut prisma_values = Vec::with_capacity(values.len());

for v in values.iter() {
let pv = PrismaValue::try_from(v.clone()).map_err(|err| {
let pv = PrismaValue::try_from(v).map_err(|err| {
ValidationError::invalid_argument_value(
selection_path.segments(),
argument_path.segments(),
Expand Down
4 changes: 2 additions & 2 deletions query-engine/core/src/query_graph_builder/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a> QueryGraphBuilder<'a> {
root_object: ObjectType<'a>, // Either the query or mutation object.
root_object_fields: &dyn Fn(&str) -> Option<OutputField<'a>>,
) -> QueryGraphBuilderResult<(QueryGraph, IrSerializer<'a>)> {
let mut selections = vec![selection];
let selections = vec![selection.clone()];
let mut parsed_object = QueryDocumentParser::new(crate::executor::get_request_now()).parse(
&selections,
&root_object,
Expand All @@ -53,7 +53,7 @@ impl<'a> QueryGraphBuilder<'a> {

// Because we're processing root objects, there can only be one query / mutation.
let field_pair = parsed_object.fields.pop().unwrap();
let serializer = Self::derive_serializer(&selections.pop().unwrap(), field_pair.schema_field.clone());
let serializer = Self::derive_serializer(&selection, field_pair.schema_field.clone());

if field_pair.schema_field.query_info().is_some() {
let graph = self.dispatch_build(field_pair)?;
Expand Down
Loading