Skip to content

Commit

Permalink
Add compile method on wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Oct 27, 2024
1 parent c4bbaaf commit d79058d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions query-engine/query-engine-wasm/src/wasm/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,28 @@ impl QueryEngine {
pub async fn metrics(&self, json_options: String) -> Result<(), wasm_bindgen::JsError> {
Err(ApiError::configuration("Metrics is not enabled in Wasm.").into())
}

#[wasm_bindgen]
pub async fn compile(
&self,
request: String,
_human_readable: bool, // ignored on wasm to not compile it in
) -> Result<String, wasm_bindgen::JsError> {
let dispatcher = self.logger.dispatcher();

async {
let inner = self.inner.read().await;
let engine = inner.as_engine()?;

let request = RequestBody::try_from_str(&request, engine.engine_protocol())?;
let query_doc = request
.into_doc(engine.query_schema())
.map_err(|err| napi::Error::from_reason(err.to_string()))?;

Check failure on line 295 in query-engine/query-engine-wasm/src/wasm/engine.rs

View workflow job for this annotation

GitHub Actions / clippy linting

failed to resolve: use of undeclared crate or module `napi`

let plan = query_core::compiler::compile(engine.query_schema(), query_doc).map_err(ApiError::from)?;
Ok(serde_json::to_string(&plan)?)
}
.with_subscriber(dispatcher)
.await
}
}

0 comments on commit d79058d

Please sign in to comment.