Skip to content

Commit

Permalink
Revert "query-engine-node-api: delete getConfig() (#3608)" (#3619)
Browse files Browse the repository at this point in the history
We deleted getConfig from the node api builds of the query-engine for a
30kb gain with the assumption that it wasn't used at all anymore in the
CLI. It is not the case.

This reverts commit 7e6991a.
  • Loading branch information
tomhoule authored Jan 20, 2023
1 parent ef34c0d commit 653fbd4
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion query-engine/query-engine-node-api/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use crate::error::ApiError;
use napi::{bindgen_prelude::*, JsUnknown};
use napi_derive::napi;
use query_core::{schema::QuerySchemaRef, schema_builder};
use request_handlers::dmmf;
use std::sync::Arc;
use std::{
collections::{BTreeMap, HashMap},
sync::Arc,
};

#[derive(serde::Serialize, Clone, Copy)]
#[napi(object)]
Expand Down Expand Up @@ -35,6 +39,43 @@ pub fn dmmf(datamodel_string: String) -> napi::Result<String> {
Ok(serde_json::to_string(&dmmf)?)
}

#[napi]
pub fn get_config(js_env: Env, options: JsUnknown) -> napi::Result<JsUnknown> {
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct GetConfigOptions {
datamodel: String,
#[serde(default)]
ignore_env_var_errors: bool,
#[serde(default)]
datasource_overrides: BTreeMap<String, String>,
#[serde(default)]
env: HashMap<String, String>,
}

let options: GetConfigOptions = js_env.from_js_value(options)?;

let GetConfigOptions {
datamodel,
ignore_env_var_errors,
datasource_overrides,
env,
} = options;

let overrides: Vec<(_, _)> = datasource_overrides.into_iter().collect();
let mut config = psl::parse_configuration(&datamodel).map_err(|errors| ApiError::conversion(errors, &datamodel))?;

if !ignore_env_var_errors {
config
.resolve_datasource_urls_from_env(&overrides, |key| env.get(key).map(ToString::to_string))
.map_err(|errors| ApiError::conversion(errors, &datamodel))?;
}

let serialized = psl::get_config::config_to_mcf_json_value(&config);

js_env.to_js_value(&serialized)
}

#[napi]
pub fn debug_panic(panic_message: Option<String>) -> napi::Result<()> {
let user_facing = user_facing_errors::Error::from_panic_payload(Box::new(
Expand Down

0 comments on commit 653fbd4

Please sign in to comment.