feat: add more efficient getDmmf method to the node-api QE class
Note: this dmmf method can only be called on a connected engine.
@@ -7,7 +7,7 @@ use query_core::{
schema_builder, set_parent_context_from_json_str, QueryExecutor, TxId,
};
use query_engine_metrics::{MetricFormat, MetricRegistry};
-use request_handlers::{GraphQLSchemaRenderer, GraphQlHandler, TxInput};
+use request_handlers::{dmmf, GraphQLSchemaRenderer, GraphQlHandler, TxInput};
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::{
@@ -377,6 +377,18 @@ impl QueryEngine {
.await
}
+ #[napi]
+ pub async fn dmmf(&self) -> napi::Result<String> {
+ async_panic_to_js_error(async {
+ let inner = self.inner.read().await;
+ let engine = inner.as_engine()?;
+ let dmmf = dmmf::render_dmmf(engine.query_schema.clone());
+
+ Ok(serde_json::to_string(&dmmf)?)
+ })
+ .await
+ }
+
/// If connected, attempts to roll back a transaction with id `tx_id` in the core.
#[napi]
pub async fn rollback_transaction(&self, tx_id: String, _trace: String) -> napi::Result<String> {
