diff --git a/juniper/src/tests/fixtures/starwars/schema.rs b/juniper/src/tests/fixtures/starwars/schema.rs index 7e0431f1..d5eebbe5 100644 --- a/juniper/src/tests/fixtures/starwars/schema.rs +++ b/juniper/src/tests/fixtures/starwars/schema.rs @@ -78,6 +78,7 @@ pub struct Human { name: String, friend_ids: Vec, appears_in: Vec, + #[allow(dead_code)] secret_backstory: Option, home_planet: Option, } @@ -164,6 +165,7 @@ pub struct Droid { name: String, friend_ids: Vec, appears_in: Vec, + #[allow(dead_code)] secret_backstory: Option, primary_function: Option, } diff --git a/juniper_actix/Cargo.toml b/juniper_actix/Cargo.toml index 93f90a29..fb01ee65 100644 --- a/juniper_actix/Cargo.toml +++ b/juniper_actix/Cargo.toml @@ -9,7 +9,7 @@ documentation = "https://docs.rs/juniper_actix" repository = "https://github.com/graphql-rust/juniper" [features] -subscriptions = ["juniper_graphql_ws"] +subscriptions = ["juniper_graphql_ws", "tokio"] [dependencies] actix = "0.12" @@ -26,12 +26,13 @@ futures = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" +tokio = { version = "1.0", features = ["sync"], optional = true } [dev-dependencies] actix-rt = "2" actix-cors = "0.6.0-beta.2" actix-identity = "0.4.0-beta.2" -tokio = "1" +tokio = "1.0" async-stream = "0.3" actix-test = "0.1.0-beta.3" diff --git a/juniper_actix/src/lib.rs b/juniper_actix/src/lib.rs index 8912e139..279f246a 100644 --- a/juniper_actix/src/lib.rs +++ b/juniper_actix/src/lib.rs @@ -211,10 +211,7 @@ pub async fn playground_handler( /// [1]: https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md #[cfg(feature = "subscriptions")] pub mod subscriptions { - use std::{ - fmt, - sync::{Arc, Mutex}, - }; + use std::{fmt, sync::Arc}; use actix::{prelude::*, Actor, StreamHandler}; use actix_web::{ @@ -222,7 +219,6 @@ pub mod subscriptions { web, HttpRequest, HttpResponse, }; use actix_web_actors::ws; - use juniper::{ futures::{ stream::{SplitSink, SplitStream, StreamExt}, @@ -231,6 +227,7 @@ pub mod subscriptions { GraphQLSubscriptionType, GraphQLTypeAsync, RootNode, ScalarValue, }; use juniper_graphql_ws::{ArcSchema, ClientMessage, Connection, Init, ServerMessage}; + use tokio::sync::Mutex; /// Serves the graphql-ws protocol over a WebSocket connection. /// @@ -326,8 +323,9 @@ pub mod subscriptions { let tx = self.graphql_tx.clone(); async move { - let mut tx = tx.lock().unwrap(); - tx.send(msg) + tx.lock() + .await + .send(msg) .await .expect("Infallible: this should not happen"); } @@ -363,7 +361,7 @@ pub mod subscriptions { let addr = ctx.address(); let fut = async move { - let mut stream = stream.lock().unwrap(); + let mut stream = stream.lock().await; while let Some(message) = stream.next().await { // sending the message to self so that it can be forwarded back to the client addr.do_send(ServerMessageWrapper { message });