-
Notifications
You must be signed in to change notification settings - Fork 242
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
Support multiple gateways in the same process #261
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,24 +10,30 @@ static mut DATA: Vec<QueryPlanner> = vec![]; | |
#[wasm_bindgen(js_name = getQueryPlanner)] | ||
pub fn get_query_planner(schema: JsString) -> usize { | ||
unsafe { | ||
if SCHEMA.is_empty() { | ||
SCHEMA.push(String::from(schema)); | ||
DATA.push(QueryPlanner::new(&SCHEMA[0])); | ||
} else { | ||
SCHEMA[0] = String::from(schema); | ||
DATA[0] = QueryPlanner::new(&SCHEMA[0]); | ||
let idx = SCHEMA.len(); | ||
SCHEMA.push(String::from(schema)); | ||
DATA.push(QueryPlanner::new(&SCHEMA[idx])); | ||
idx | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_name = updatePlannerSchema)] | ||
pub fn update_planner_schema(idx: usize, schema: JsString) { | ||
unsafe { | ||
if SCHEMA.get(idx).is_none() { | ||
panic!("Index {} not found", idx) | ||
} | ||
let data = &DATA[0]; | ||
data as *const QueryPlanner as usize | ||
|
||
SCHEMA[idx] = String::from(schema); | ||
DATA[idx] = QueryPlanner::new(&SCHEMA[idx]); | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_name = getQueryPlan)] | ||
pub fn get_query_plan(planner_ptr: usize, query: &str, options: &JsValue) -> JsValue { | ||
pub fn get_query_plan(idx: usize, query: &str, options: &JsValue) -> JsValue { | ||
let options: QueryPlanningOptions = options.into_serde().unwrap(); | ||
unsafe { | ||
let planner = planner_ptr as *const QueryPlanner; | ||
let planner: &QueryPlanner = &*planner; | ||
let planner = &DATA[idx]; | ||
let plan = planner.plan(query, options).unwrap(); | ||
JsValue::from_serde(&plan).unwrap() | ||
} | ||
|
@@ -64,4 +70,30 @@ mod tests { | |
let plan = result.into_serde::<QueryPlan>().unwrap(); | ||
assert_eq!(plan, expected); | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
fn multiple_query_planners() { | ||
let schema_multiple_keys = include_str!( | ||
"../../stargate/crates/query-planner/tests/features/multiple-keys/csdl.graphql" | ||
); | ||
let planner_multiple_keys = get_query_planner(JsString::from(schema_multiple_keys)); | ||
let query_multiple_keys = "query { reviews { body } }"; | ||
|
||
let schema_basic = | ||
include_str!("../../stargate/crates/query-planner/tests/features/basic/csdl.graphql"); | ||
let planner_basic = get_query_planner(JsString::from(schema_basic)); | ||
let query_basic = "query { me { name } }"; | ||
|
||
let options = QueryPlanningOptionsBuilder::default().build().unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should at least make these unwraps expects.. if these were to fail it would be very unpleasant to debug |
||
let options = JsValue::from_serde(&options).unwrap(); | ||
|
||
let result_basic = get_query_plan(planner_basic, query_basic, &options); | ||
let plan_basic = result_basic.into_serde::<QueryPlan>().unwrap(); | ||
|
||
let result_multiple_keys = | ||
get_query_plan(planner_multiple_keys, query_multiple_keys, &options); | ||
let plan_multiple_keys = result_multiple_keys.into_serde::<QueryPlan>().unwrap(); | ||
|
||
assert_ne!(plan_multiple_keys, plan_basic); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason we're stringly typing paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this seems to pass on windows but i am surprised)