diff --git a/query-engine/core/Cargo.toml b/query-engine/core/Cargo.toml index 1b7c52e59de9..da9e8331dfdf 100644 --- a/query-engine/core/Cargo.toml +++ b/query-engine/core/Cargo.toml @@ -5,6 +5,7 @@ version = "0.1.0" [features] metrics = ["query-engine-metrics"] +graphql-protocol = [] [dependencies] async-trait = "0.1" @@ -19,7 +20,9 @@ indexmap = { version = "1.7", features = ["serde-1"] } itertools = "0.10" once_cell = "1" petgraph = "0.4" -query-structure = { path = "../query-structure", features = ["default_generators"] } +query-structure = { path = "../query-structure", features = [ + "default_generators", +] } opentelemetry = { version = "0.17.0", features = ["rt-tokio", "serialize"] } query-engine-metrics = { path = "../metrics", optional = true } serde.workspace = true diff --git a/query-engine/core/src/protocol.rs b/query-engine/core/src/protocol.rs index 75e8dbc0fd70..e92438d5e92d 100644 --- a/query-engine/core/src/protocol.rs +++ b/query-engine/core/src/protocol.rs @@ -3,6 +3,7 @@ use serde::Deserialize; #[derive(Debug, Clone, Copy, Deserialize)] #[serde(rename_all = "camelCase")] pub enum EngineProtocol { + #[cfg(feature = "graphql-protocol")] Graphql, Json, } @@ -14,6 +15,7 @@ impl EngineProtocol { } /// Returns `true` if the engine protocol is [`Graphql`]. + #[cfg(feature = "graphql-protocol")] pub fn is_graphql(&self) -> bool { matches!(self, Self::Graphql) } @@ -22,6 +24,7 @@ impl EngineProtocol { impl From<&String> for EngineProtocol { fn from(s: &String) -> Self { match s.as_str() { + #[cfg(feature = "graphql-protocol")] "graphql" => EngineProtocol::Graphql, "json" => EngineProtocol::Json, x => panic!("Unknown engine protocol '{x}'. Must be 'graphql' or 'json'."), diff --git a/query-engine/core/src/response_ir/internal.rs b/query-engine/core/src/response_ir/internal.rs index 7becb19e768b..bbda8d7bd05d 100644 --- a/query-engine/core/src/response_ir/internal.rs +++ b/query-engine/core/src/response_ir/internal.rs @@ -552,11 +552,13 @@ fn serialize_scalar(field: &OutputField<'_>, value: PrismaValue) -> crate::Resul fn convert_prisma_value(field: &OutputField<'_>, value: PrismaValue, st: &ScalarType) -> crate::Result { match crate::executor::get_engine_protocol() { + #[cfg(feature = "graphql-protocol")] EngineProtocol::Graphql => convert_prisma_value_graphql_protocol(field, value, st), EngineProtocol::Json => convert_prisma_value_json_protocol(field, value, st), } } +#[cfg(feature = "graphql-protocol")] fn convert_prisma_value_graphql_protocol( field: &OutputField<'_>, value: PrismaValue, diff --git a/query-engine/query-engine-node-api/src/functions.rs b/query-engine/query-engine-node-api/src/functions.rs index 868178f7361d..bcb64e240cae 100644 --- a/query-engine/query-engine-node-api/src/functions.rs +++ b/query-engine/query-engine-node-api/src/functions.rs @@ -1,4 +1,3 @@ -use crate::error::ApiError; use napi_derive::napi; use request_handlers::dmmf; use std::sync::Arc; diff --git a/query-engine/query-engine-wasm/Cargo.toml b/query-engine/query-engine-wasm/Cargo.toml index 6d3dc33050b7..e08d412d5f97 100644 --- a/query-engine/query-engine-wasm/Cargo.toml +++ b/query-engine/query-engine-wasm/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [lib] doc = false crate-type = ["cdylib"] -name = "query_engine" +name = "query_engine_wasm" [dependencies] diff --git a/query-engine/query-engine-wasm/src/wasm/engine.rs b/query-engine/query-engine-wasm/src/wasm/engine.rs index 19f442106b97..a40dfbd4ff94 100644 --- a/query-engine/query-engine-wasm/src/wasm/engine.rs +++ b/query-engine/query-engine-wasm/src/wasm/engine.rs @@ -14,7 +14,7 @@ use query_core::{ telemetry, QueryExecutor, TransactionOptions, TxId, }; use request_handlers::ConnectorMode; -use request_handlers::{dmmf, load_executor, render_graphql_schema, RequestBody, RequestHandler}; +use request_handlers::{load_executor, RequestBody, RequestHandler}; use serde::{Deserialize, Serialize}; use serde_json::json; use std::{ @@ -385,28 +385,6 @@ impl QueryEngine { .await } - #[wasm_bindgen] - pub async fn dmmf(&self, trace: String) -> Result { - let inner = self.inner.read().await; - let engine = inner.as_engine()?; - - let dispatcher = self.logger.dispatcher(); - - tracing::dispatcher::with_default(&dispatcher, || { - let span = tracing::info_span!("prisma:engine:dmmf"); - let _ = telemetry::helpers::set_parent_context_from_json_str(&span, &trace); - let _guard = span.enter(); - let dmmf = dmmf::render_dmmf(&engine.query_schema); - - let json = { - let _span = tracing::info_span!("prisma:engine:dmmf_to_json").entered(); - serde_json::to_string(&dmmf)? - }; - - Ok(json) - }) - } - /// If connected, attempts to roll back a transaction with id `tx_id` in the core. #[wasm_bindgen(js_name = rollbackTransaction)] pub async fn rollback_transaction(&self, tx_id: String, trace: String) -> Result { @@ -425,15 +403,6 @@ impl QueryEngine { .await } - /// Loads the query schema. Only available when connected. - #[wasm_bindgen(js_name = sdlSchema)] - pub async fn sdl_schema(&self) -> Result { - let inner = self.inner.read().await; - let engine = inner.as_engine()?; - - Ok(render_graphql_schema(engine.query_schema())) - } - #[wasm_bindgen] pub async fn metrics(&self, json_options: String) -> Result<(), wasm_bindgen::JsError> { log::info!("Called `QueryEngine::metrics()`"); diff --git a/query-engine/query-engine-wasm/src/wasm/functions.rs b/query-engine/query-engine-wasm/src/wasm/functions.rs index 9767b22fb811..5aa2a8d6ba2a 100644 --- a/query-engine/query-engine-wasm/src/wasm/functions.rs +++ b/query-engine/query-engine-wasm/src/wasm/functions.rs @@ -1,7 +1,4 @@ -use crate::error::ApiError; -use request_handlers::dmmf; use serde::Serialize; -use std::sync::Arc; use tsify::Tsify; use wasm_bindgen::prelude::wasm_bindgen; @@ -21,21 +18,6 @@ pub fn version() -> Version { } } -#[wasm_bindgen] -pub fn dmmf(datamodel_string: String) -> Result { - let mut schema = psl::validate(datamodel_string.into()); - - schema - .diagnostics - .to_result() - .map_err(|errors| ApiError::conversion(errors, schema.db.source()))?; - - let query_schema = query_core::schema::build(Arc::new(schema), true); - let dmmf = dmmf::render_dmmf(&query_schema); - - Ok(serde_json::to_string(&dmmf)?) -} - #[wasm_bindgen] pub fn debug_panic(panic_message: Option) -> Result<(), wasm_bindgen::JsError> { let user_facing = user_facing_errors::Error::from_panic_payload(Box::new( diff --git a/query-engine/request-handlers/Cargo.toml b/query-engine/request-handlers/Cargo.toml index 51ed4bd8b5ad..3686f14154af 100644 --- a/query-engine/request-handlers/Cargo.toml +++ b/query-engine/request-handlers/Cargo.toml @@ -20,7 +20,7 @@ bigdecimal = "0.3" thiserror = "1" tracing = "0.1" url = "2" -connection-string.workspace = true +connection-string.workspace = true once_cell = "1.15" mongodb-query-connector = { path = "../connectors/mongodb-query-connector", optional = true } @@ -32,11 +32,17 @@ schema = { path = "../schema" } codspeed-criterion-compat = "1.1.0" [features] -default = ["sql", "mongodb", "native"] +default = ["sql", "mongodb", "native", "graphql-protocol"] mongodb = ["mongodb-query-connector"] sql = ["sql-query-connector"] driver-adapters = ["sql-query-connector/driver-adapters"] -native = ["mongodb", "sql-query-connector", "quaint/native", "query-core/metrics"] +native = [ + "mongodb", + "sql-query-connector", + "quaint/native", + "query-core/metrics", +] +graphql-protocol = ["query-core/graphql-protocol"] [[bench]] name = "query_planning_bench" diff --git a/query-engine/request-handlers/src/lib.rs b/query-engine/request-handlers/src/lib.rs index 361e5c628bdf..949c26b302f3 100644 --- a/query-engine/request-handlers/src/lib.rs +++ b/query-engine/request-handlers/src/lib.rs @@ -12,7 +12,9 @@ mod response; pub use self::{error::HandlerError, load_executor::load as load_executor}; pub use connector_mode::ConnectorMode; pub use handler::*; -pub use protocols::{graphql::*, json::*, RequestBody}; +#[cfg(feature = "graphql-protocol")] +pub use protocols::graphql::*; +pub use protocols::{json::*, RequestBody}; pub use response::*; pub type Result = std::result::Result; diff --git a/query-engine/request-handlers/src/protocols/mod.rs b/query-engine/request-handlers/src/protocols/mod.rs index e2c50c2e7f1f..93bac460fecb 100644 --- a/query-engine/request-handlers/src/protocols/mod.rs +++ b/query-engine/request-handlers/src/protocols/mod.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "graphql-protocol")] pub mod graphql; pub mod json; @@ -5,6 +6,7 @@ use query_core::{protocol::EngineProtocol, schema::QuerySchemaRef, QueryDocument #[derive(Debug)] pub enum RequestBody { + #[cfg(feature = "graphql-protocol")] Graphql(graphql::GraphqlBody), Json(json::JsonBody), } @@ -12,6 +14,7 @@ pub enum RequestBody { impl RequestBody { pub fn into_doc(self, query_schema: &QuerySchemaRef) -> crate::Result { match self { + #[cfg(feature = "graphql-protocol")] RequestBody::Graphql(body) => body.into_doc(), RequestBody::Json(body) => body.into_doc(query_schema), } @@ -19,6 +22,7 @@ impl RequestBody { pub fn try_from_str(val: &str, engine_protocol: EngineProtocol) -> Result { match engine_protocol { + #[cfg(feature = "graphql-protocol")] EngineProtocol::Graphql => serde_json::from_str::(val).map(Self::from), EngineProtocol::Json => serde_json::from_str::(val).map(Self::from), } @@ -26,12 +30,14 @@ impl RequestBody { pub fn try_from_slice(val: &[u8], engine_protocol: EngineProtocol) -> Result { match engine_protocol { + #[cfg(feature = "graphql-protocol")] EngineProtocol::Graphql => serde_json::from_slice::(val).map(Self::from), EngineProtocol::Json => serde_json::from_slice::(val).map(Self::from), } } } +#[cfg(feature = "graphql-protocol")] impl From for RequestBody { fn from(body: graphql::GraphqlBody) -> Self { Self::Graphql(body)