diff --git a/examples/juniper/Cargo.toml b/examples/juniper/Cargo.toml index ffcd6616e..9e52b0a83 100644 --- a/examples/juniper/Cargo.toml +++ b/examples/juniper/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "juniper-example" version = "0.1.0" -authors = ["Nikolay Kim "] +authors = ["pyros2097 "] workspace = "../.." [dependencies] @@ -15,4 +15,3 @@ serde_json = "1.0" serde_derive = "1.0" juniper = "0.9.2" -lazy_static = "1.0" diff --git a/examples/juniper/src/main.rs b/examples/juniper/src/main.rs index ba9c6bf00..91441f4ba 100644 --- a/examples/juniper/src/main.rs +++ b/examples/juniper/src/main.rs @@ -6,8 +6,6 @@ extern crate serde_json; #[macro_use] extern crate serde_derive; #[macro_use] -extern crate lazy_static; -#[macro_use] extern crate juniper; extern crate futures; extern crate actix; @@ -26,10 +24,6 @@ mod schema; use schema::Schema; use schema::create_schema; -lazy_static! { - static ref SCHEMA: Schema = create_schema(); -} - struct State { executor: Addr, } @@ -41,7 +35,17 @@ impl Message for GraphQLData { type Result = Result; } -pub struct GraphQLExecutor; +pub struct GraphQLExecutor { + schema: std::sync::Arc +} + +impl GraphQLExecutor { + fn new(schema: std::sync::Arc) -> GraphQLExecutor { + GraphQLExecutor { + schema: schema, + } + } +} impl Actor for GraphQLExecutor { type Context = SyncContext; @@ -51,7 +55,7 @@ impl Handler for GraphQLExecutor { type Result = Result; fn handle(&mut self, msg: GraphQLData, _: &mut Self::Context) -> Self::Result { - let res = msg.0.execute(&SCHEMA, &()); + let res = msg.0.execute(&self.schema, &()); let res_text = serde_json::to_string(&res)?; Ok(res_text) } @@ -86,8 +90,9 @@ fn main() { let _ = env_logger::init(); let sys = actix::System::new("juniper-example"); - let addr = SyncArbiter::start(3, || { - GraphQLExecutor{} + let schema = std::sync::Arc::new(create_schema()); + let addr = SyncArbiter::start(3, move || { + GraphQLExecutor::new(schema.clone()) }); // Start http server