Upgraded tokio, warp, hyper and actix (#912)
* Upgraded tokio, warp, hyper and actix * Code formatting * actix-web temporary version fix specification * Error handling fix on juniper_rocket Co-authored-by: Christian Legnitto <LegNeato@users.noreply.github.com>
This commit is contained in:
parent
de4c0e9088
commit
739cc3bfc2
28 changed files with 135 additions and 118 deletions
|
@ -51,7 +51,7 @@ type StringStream = Pin<Box<dyn Stream<Item = Result<String, FieldError>> + Send
|
|||
#[graphql_subscription(context = Database)]
|
||||
impl Subscription {
|
||||
async fn hello_world() -> StringStream {
|
||||
let stream = tokio::stream::iter(vec![
|
||||
let stream = futures::stream::iter(vec![
|
||||
Ok(String::from("Hello")),
|
||||
Ok(String::from("World!"))
|
||||
]);
|
||||
|
@ -123,7 +123,7 @@ where [`Connection`][Connection] is a `Stream` of values returned by the operati
|
|||
# impl Subscription {
|
||||
# async fn hello_world() -> StringStream {
|
||||
# let stream =
|
||||
# tokio::stream::iter(vec![Ok(String::from("Hello")), Ok(String::from("World!"))]);
|
||||
# futures::stream::iter(vec![Ok(String::from("Hello")), Ok(String::from("World!"))]);
|
||||
# Box::pin(stream)
|
||||
# }
|
||||
# }
|
||||
|
|
|
@ -16,7 +16,7 @@ iron = "0.5"
|
|||
mount = "0.4"
|
||||
skeptic = "0.13"
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "0.2", features = ["blocking", "macros", "rt-core", "rt-util", "stream"] }
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
uuid = "0.8"
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -6,15 +6,15 @@ authors = ["Mihai Dinculescu <mihai.dinculescu@outlook.com>"]
|
|||
publish = false
|
||||
|
||||
[dependencies]
|
||||
actix-web = "3.3"
|
||||
actix-cors = "0.5"
|
||||
actix-web = "4.0.0-beta.5"
|
||||
actix-cors = "0.6.0-beta.1"
|
||||
futures = "0.3"
|
||||
tokio = { version = "0.2", features = ["macros", "rt-core"] }
|
||||
env_logger = "0.8"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
rand = "0.7"
|
||||
|
||||
rand = "0.8"
|
||||
tokio = "1.0"
|
||||
async-stream = "0.3"
|
||||
juniper = { path = "../../juniper", features = ["expose-test-schema"] }
|
||||
juniper_actix = { path = "../../juniper_actix", features = ["subscriptions"] }
|
||||
juniper_graphql_ws = { path = "../../juniper_graphql_ws" }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{env, pin::Pin, time::Duration};
|
||||
|
||||
use actix_cors::Cors;
|
||||
use actix_web::{middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
||||
use actix_web::{http::header, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
||||
|
||||
use juniper::{
|
||||
graphql_object, graphql_subscription,
|
||||
|
@ -64,27 +64,29 @@ impl Subscription {
|
|||
|
||||
use rand::{rngs::StdRng, Rng, SeedableRng};
|
||||
let mut rng = StdRng::from_entropy();
|
||||
|
||||
let stream = tokio::time::interval(Duration::from_secs(3)).map(move |_| {
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
||||
let stream = async_stream::stream! {
|
||||
counter += 1;
|
||||
loop {
|
||||
interval.tick().await;
|
||||
if counter == 2 {
|
||||
yield Err(FieldError::new(
|
||||
"some field error from handler",
|
||||
Value::Scalar(DefaultScalarValue::String(
|
||||
"some additional string".to_string(),
|
||||
)),
|
||||
))
|
||||
} else {
|
||||
let random_id = rng.gen_range(1000..1005).to_string();
|
||||
let human = context.get_human(&random_id).unwrap().clone();
|
||||
|
||||
if counter == 2 {
|
||||
Err(FieldError::new(
|
||||
"some field error from handler",
|
||||
Value::Scalar(DefaultScalarValue::String(
|
||||
"some additional string".to_string(),
|
||||
)),
|
||||
))
|
||||
} else {
|
||||
let random_id = rng.gen_range(1000, 1005).to_string();
|
||||
let human = context.get_human(&random_id).unwrap().clone();
|
||||
|
||||
Ok(RandomHuman {
|
||||
id: human.id().to_owned(),
|
||||
name: human.name().unwrap().to_owned(),
|
||||
})
|
||||
yield Ok(RandomHuman {
|
||||
id: human.id().to_owned(),
|
||||
name: human.name().unwrap().to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Box::pin(stream)
|
||||
}
|
||||
|
@ -117,7 +119,10 @@ async fn main() -> std::io::Result<()> {
|
|||
.wrap(middleware::Logger::default())
|
||||
.wrap(
|
||||
Cors::default()
|
||||
.allowed_origin("http://127.0.0.1:8080")
|
||||
.allowed_methods(vec!["POST", "GET"])
|
||||
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
|
||||
.allowed_header(header::CONTENT_TYPE)
|
||||
.supports_credentials()
|
||||
.max_age(3600),
|
||||
)
|
||||
|
@ -130,7 +135,7 @@ async fn main() -> std::io::Result<()> {
|
|||
.service(web::resource("/playground").route(web::get().to(playground)))
|
||||
.default_service(web::route().to(|| {
|
||||
HttpResponse::Found()
|
||||
.header("location", "/playground")
|
||||
.append_header((header::LOCATION, "/playground"))
|
||||
.finish()
|
||||
}))
|
||||
})
|
||||
|
|
|
@ -11,7 +11,7 @@ authors = ["Jordao Rosario <jordao.rosario01@gmail.com>"]
|
|||
futures = "0.3"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "0.2", features = ["rt-core", "macros", "stream"] }
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
|
||||
juniper = { path = "../../juniper" }
|
||||
juniper_subscriptions = { path = "../../juniper_subscriptions" }
|
||||
|
|
|
@ -37,7 +37,7 @@ type StringStream = Pin<Box<dyn Stream<Item = Result<String, FieldError>> + Send
|
|||
impl Subscription {
|
||||
async fn hello_world() -> StringStream {
|
||||
let stream =
|
||||
tokio::stream::iter(vec![Ok(String::from("Hello")), Ok(String::from("World!"))]);
|
||||
futures::stream::iter(vec![Ok(String::from("Hello")), Ok(String::from("World!"))]);
|
||||
Box::pin(stream)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,5 +13,5 @@ env_logger = "0.8.1"
|
|||
futures = "0.3.1"
|
||||
log = "0.4.8"
|
||||
reqwest = { version = "0.11", features = ["rustls-tls"] }
|
||||
tokio = { version = "0.2", features = ["rt-core", "macros"] }
|
||||
warp = "0.2"
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
warp = "0.3"
|
||||
|
|
|
@ -10,9 +10,9 @@ futures = "0.3.1"
|
|||
log = "0.4.8"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "0.2", features = ["rt-core", "macros"] }
|
||||
warp = "0.2.1"
|
||||
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
warp = "0.3"
|
||||
async-stream = "0.3"
|
||||
juniper = { path = "../../juniper" }
|
||||
juniper_graphql_ws = { path = "../../juniper_graphql_ws" }
|
||||
juniper_warp = { path = "../../juniper_warp", features = ["subscriptions"] }
|
||||
|
|
|
@ -109,23 +109,27 @@ struct Subscription;
|
|||
impl Subscription {
|
||||
async fn users() -> UsersStream {
|
||||
let mut counter = 0;
|
||||
let stream = tokio::time::interval(Duration::from_secs(5)).map(move |_| {
|
||||
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
||||
let stream = async_stream::stream! {
|
||||
counter += 1;
|
||||
if counter == 2 {
|
||||
Err(FieldError::new(
|
||||
"some field error from handler",
|
||||
Value::Scalar(DefaultScalarValue::String(
|
||||
"some additional string".to_string(),
|
||||
)),
|
||||
))
|
||||
} else {
|
||||
Ok(User {
|
||||
id: counter,
|
||||
kind: UserKind::Admin,
|
||||
name: "stream user".to_string(),
|
||||
})
|
||||
loop {
|
||||
interval.tick().await;
|
||||
if counter == 2 {
|
||||
yield Err(FieldError::new(
|
||||
"some field error from handler",
|
||||
Value::Scalar(DefaultScalarValue::String(
|
||||
"some additional string".to_string(),
|
||||
)),
|
||||
))
|
||||
} else {
|
||||
yield Ok(User {
|
||||
id: counter,
|
||||
kind: UserKind::Admin,
|
||||
name: "stream user".to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Box::pin(stream)
|
||||
}
|
||||
|
|
|
@ -8,4 +8,4 @@ publish = false
|
|||
[dependencies]
|
||||
juniper = { path = "../../juniper" }
|
||||
futures = "0.3.1"
|
||||
tokio = { version = "0.2", features = ["rt-core", "time", "macros"] }
|
||||
tokio = { version = "1", features = ["rt", "time", "macros"] }
|
|
@ -42,7 +42,7 @@ impl User {
|
|||
}
|
||||
|
||||
async fn delayed() -> bool {
|
||||
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ impl Query {
|
|||
}
|
||||
|
||||
async fn delayed() -> bool {
|
||||
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,5 +10,5 @@ futures = "0.3.1"
|
|||
|
||||
[dev-dependencies]
|
||||
serde_json = { version = "1" }
|
||||
tokio = { version = "0.2", features = ["rt-core", "time", "macros"] }
|
||||
tokio = { version = "1", features = ["rt", "time", "macros"] }
|
||||
trybuild = "1.0.25"
|
|
@ -14,4 +14,4 @@ juniper_subscriptions = { path = "../../juniper_subscriptions" }
|
|||
async-trait = "0.1.39"
|
||||
serde_json = "1.0"
|
||||
fnv = "1.0"
|
||||
tokio = { version = "0.2", features = ["macros", "rt-core", "time"] }
|
||||
tokio = { version = "1", features = ["rt", "macros", "time"] }
|
||||
|
|
|
@ -55,7 +55,7 @@ uuid = { version = "0.8", default-features = false, optional = true }
|
|||
bencher = "0.1.2"
|
||||
pretty_assertions = "0.7.1"
|
||||
serde_json = "1.0.2"
|
||||
tokio = { version = "0.2", features = ["macros", "rt-core", "time"] }
|
||||
tokio = { version = "1", features = ["macros", "time", "rt-multi-thread"] }
|
||||
|
||||
[[bench]]
|
||||
name = "bench"
|
||||
|
|
|
@ -39,7 +39,7 @@ impl User {
|
|||
}
|
||||
|
||||
async fn delayed() -> bool {
|
||||
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ impl Query {
|
|||
}
|
||||
|
||||
async fn delayed() -> bool {
|
||||
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "juniper_actix"
|
||||
version = "0.2.5"
|
||||
version = "0.3.0"
|
||||
edition = "2018"
|
||||
authors = ["Jordao Rosario <jordao.rosario01@gmail.com>"]
|
||||
description = "Juniper GraphQL integration with Actix"
|
||||
|
@ -12,27 +12,34 @@ repository = "https://github.com/graphql-rust/juniper"
|
|||
subscriptions = ["juniper_graphql_ws"]
|
||||
|
||||
[dependencies]
|
||||
actix = "0.10"
|
||||
actix-web = "3.3"
|
||||
actix-web-actors = "3.0"
|
||||
actix = "0.11"
|
||||
# actix-web had some problems in beta release see https://github.com/actix/actix-web/issues/2173#issuecomment-822758353
|
||||
# and we need these version specification to handle this issue temporarily while the stable release is not available
|
||||
# to understand these dependecy version specification see https://github.com/actix/actix-web/issues/2185 or https://github.com/LukeMathWalker/zero-to-production/issues/96
|
||||
actix-http = "=3.0.0-beta.5"
|
||||
actix-service = "=2.0.0-beta.5"
|
||||
actix-web = "=4.0.0-beta.5"
|
||||
actix-web-actors = "4.0.0-beta.4"
|
||||
|
||||
juniper = { version = "0.15.6", path = "../juniper", default-features = false }
|
||||
juniper_graphql_ws = { version = "0.2.5", path = "../juniper_graphql_ws", optional = true }
|
||||
|
||||
anyhow = "1.0"
|
||||
futures = "0.3.5"
|
||||
serde = { version = "1.0.116", features = ["derive"] }
|
||||
serde_json = "1.0.57"
|
||||
futures = "0.3"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
tokio = { version = "0.2", features = ["time"] }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "1.1"
|
||||
actix-cors = "0.5"
|
||||
actix-identity = "0.3"
|
||||
actix-rt = "2"
|
||||
actix-cors = "0.6.0-beta.1"
|
||||
actix-identity = "0.4.0-beta.1"
|
||||
tokio = "1"
|
||||
async-stream = "0.3"
|
||||
actix-test = "0.1.0-beta.1"
|
||||
|
||||
juniper = { version = "0.15.6", path = "../juniper", features = ["expose-test-schema"] }
|
||||
|
||||
bytes = "0.6"
|
||||
bytes = "1.0"
|
||||
env_logger = "0.8"
|
||||
log = "0.4"
|
||||
|
|
|
@ -6,6 +6,7 @@ use actix_cors::Cors;
|
|||
use actix_web::{http::header, middleware, web, App, Error, HttpResponse, HttpServer};
|
||||
use juniper::{graphql_object, EmptyMutation, EmptySubscription, GraphQLObject, RootNode};
|
||||
use juniper_actix::{graphiql_handler, graphql_handler, playground_handler};
|
||||
|
||||
#[derive(Clone, GraphQLObject)]
|
||||
///a user
|
||||
pub struct User {
|
||||
|
|
|
@ -215,7 +215,10 @@ 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};
|
||||
use std::{
|
||||
fmt,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use actix::{prelude::*, Actor, StreamHandler};
|
||||
use actix_web::{
|
||||
|
@ -224,8 +227,6 @@ pub mod subscriptions {
|
|||
};
|
||||
use actix_web_actors::ws;
|
||||
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use juniper::{
|
||||
futures::{
|
||||
stream::{SplitSink, SplitStream, StreamExt},
|
||||
|
@ -328,7 +329,7 @@ pub mod subscriptions {
|
|||
let tx = self.graphql_tx.clone();
|
||||
|
||||
async move {
|
||||
let mut tx = tx.lock().await;
|
||||
let mut tx = tx.lock().unwrap();
|
||||
tx.send(msg)
|
||||
.await
|
||||
.expect("Infallible: this should not happen");
|
||||
|
@ -365,7 +366,7 @@ pub mod subscriptions {
|
|||
let addr = ctx.address();
|
||||
|
||||
let fut = async move {
|
||||
let mut stream = stream.lock().await;
|
||||
let mut stream = stream.lock().unwrap();
|
||||
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 });
|
||||
|
@ -383,7 +384,7 @@ pub mod subscriptions {
|
|||
}
|
||||
|
||||
/// actor -> websocket response
|
||||
impl<Query, Mutation, Subscription, CtxT, S, I> Handler<ServerMessageWrapper<S>>
|
||||
impl<Query, Mutation, Subscription, CtxT, S, I> actix::prelude::Handler<ServerMessageWrapper<S>>
|
||||
for SubscriptionActor<Query, Mutation, Subscription, CtxT, S, I>
|
||||
where
|
||||
Query: GraphQLTypeAsync<S, Context = CtxT> + Send + 'static,
|
||||
|
@ -401,14 +402,11 @@ pub mod subscriptions {
|
|||
fn handle(
|
||||
&mut self,
|
||||
msg: ServerMessageWrapper<S>,
|
||||
ctx: &mut ws::WebsocketContext<Self>,
|
||||
ctx: &mut Self::Context,
|
||||
) -> Self::Result {
|
||||
let msg = serde_json::to_string(&msg.message);
|
||||
|
||||
match msg {
|
||||
Ok(msg) => {
|
||||
ctx.text(msg);
|
||||
}
|
||||
Ok(msg) => ctx.text(msg),
|
||||
Err(e) => {
|
||||
let reason = ws::CloseReason {
|
||||
code: ws::CloseCode::Error,
|
||||
|
@ -416,12 +414,12 @@ pub mod subscriptions {
|
|||
};
|
||||
|
||||
// TODO: trace
|
||||
ctx.close(Some(reason));
|
||||
ctx.close(Some(reason))
|
||||
}
|
||||
}
|
||||
};
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
struct ServerMessageWrapper<S>
|
||||
|
@ -483,6 +481,7 @@ mod tests {
|
|||
};
|
||||
|
||||
use super::*;
|
||||
use actix_web::http::header::ACCEPT;
|
||||
|
||||
type Schema =
|
||||
juniper::RootNode<'static, Query, EmptyMutation<Database>, EmptySubscription<Database>>;
|
||||
|
@ -523,7 +522,7 @@ mod tests {
|
|||
test::init_service(App::new().route("/", web::get().to(graphql_handler))).await;
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/")
|
||||
.header("accept", "text/html")
|
||||
.append_header((ACCEPT, "text/html"))
|
||||
.to_request();
|
||||
|
||||
let resp = test::call_service(&mut app, req).await;
|
||||
|
@ -539,7 +538,7 @@ mod tests {
|
|||
test::init_service(App::new().route("/", web::get().to(graphql_handler))).await;
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/")
|
||||
.header("accept", "text/html")
|
||||
.append_header((ACCEPT, "text/html"))
|
||||
.to_request();
|
||||
|
||||
let mut resp = test::call_service(&mut app, req).await;
|
||||
|
@ -564,7 +563,7 @@ mod tests {
|
|||
test::init_service(App::new().route("/", web::get().to(graphql_handler))).await;
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/")
|
||||
.header("accept", "text/html")
|
||||
.append_header((ACCEPT, "text/html"))
|
||||
.to_request();
|
||||
|
||||
let resp = test::call_service(&mut app, req).await;
|
||||
|
@ -580,7 +579,7 @@ mod tests {
|
|||
test::init_service(App::new().route("/", web::get().to(graphql_handler))).await;
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/")
|
||||
.header("accept", "text/html")
|
||||
.append_header((ACCEPT, "text/html"))
|
||||
.to_request();
|
||||
|
||||
let mut resp = test::call_service(&mut app, req).await;
|
||||
|
@ -602,7 +601,7 @@ mod tests {
|
|||
);
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.header("content-type", "application/json; charset=utf-8")
|
||||
.append_header(("content-type", "application/json; charset=utf-8"))
|
||||
.set_payload(
|
||||
r##"{ "variables": null, "query": "{ hero(episode: NEW_HOPE) { name } }" }"##,
|
||||
)
|
||||
|
@ -634,7 +633,7 @@ mod tests {
|
|||
);
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.header("content-type", "application/json")
|
||||
.append_header(("content-type", "application/json"))
|
||||
.uri("/?query=%7B%20hero%28episode%3A%20NEW_HOPE%29%20%7B%20name%20%7D%20%7D&variables=null")
|
||||
.to_request();
|
||||
|
||||
|
@ -668,7 +667,7 @@ mod tests {
|
|||
);
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.header("content-type", "application/json")
|
||||
.append_header(("content-type", "application/json"))
|
||||
.set_payload(
|
||||
r##"[
|
||||
{ "variables": null, "query": "{ hero(episode: NEW_HOPE) { name } }" },
|
||||
|
@ -706,7 +705,7 @@ mod tests {
|
|||
|
||||
impl TestActixWebIntegration {
|
||||
fn make_request(&self, req: test::TestRequest) -> TestResponse {
|
||||
actix_web::rt::System::new("request").block_on(async move {
|
||||
actix_web::rt::System::new().block_on(async move {
|
||||
let schema = Schema::new(
|
||||
Query,
|
||||
EmptyMutation::<Database>::new(),
|
||||
|
@ -730,7 +729,7 @@ mod tests {
|
|||
fn post_json(&self, url: &str, body: &str) -> TestResponse {
|
||||
self.make_request(
|
||||
test::TestRequest::post()
|
||||
.header("content-type", "application/json")
|
||||
.append_header(("content-type", "application/json"))
|
||||
.set_payload(body.to_string())
|
||||
.uri(url),
|
||||
)
|
||||
|
@ -739,7 +738,7 @@ mod tests {
|
|||
fn post_graphql(&self, url: &str, body: &str) -> TestResponse {
|
||||
self.make_request(
|
||||
test::TestRequest::post()
|
||||
.header("content-type", "application/graphql")
|
||||
.append_header(("content-type", "application/graphql"))
|
||||
.set_payload(body.to_string())
|
||||
.uri(url),
|
||||
)
|
||||
|
@ -768,7 +767,8 @@ mod tests {
|
|||
mod subscription_tests {
|
||||
use std::time::Duration;
|
||||
|
||||
use actix_web::{test, web, App, Error, HttpRequest, HttpResponse};
|
||||
use actix_test::start;
|
||||
use actix_web::{web, App, Error, HttpRequest, HttpResponse};
|
||||
use actix_web_actors::ws;
|
||||
use juniper::{
|
||||
futures::{SinkExt, StreamExt},
|
||||
|
@ -789,7 +789,7 @@ mod subscription_tests {
|
|||
&self,
|
||||
messages: Vec<WsIntegrationMessage>,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let mut server = test::start(|| {
|
||||
let mut server = start(|| {
|
||||
App::new()
|
||||
.data(Schema::new(
|
||||
Query,
|
||||
|
@ -804,7 +804,7 @@ mod subscription_tests {
|
|||
match message {
|
||||
WsIntegrationMessage::Send(body) => {
|
||||
framed
|
||||
.send(ws::Message::Text(body.to_owned()))
|
||||
.send(ws::Message::Text(body.to_owned().into()))
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("WS error: {:?}", e))?;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ juniper = { path = "../juniper" }
|
|||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
tokio = { version = "0.2", features = ["rt-core", "rt-threaded"] }
|
||||
tokio = { version = "1", features = ["rt-multi-thread"] }
|
||||
|
||||
[[bench]]
|
||||
name = "benchmark"
|
||||
|
|
|
@ -13,7 +13,7 @@ keywords = ["apollo", "graphql", "graphql-ws", "juniper"]
|
|||
juniper = { version = "0.15.6", path = "../juniper", default-features = false }
|
||||
juniper_subscriptions = { version = "0.15.5", path = "../juniper_subscriptions" }
|
||||
serde = { version = "1.0.8", features = ["derive"], default-features = false }
|
||||
tokio = { version = "0.2", features = ["macros", "rt-core", "time"], default-features = false }
|
||||
tokio = { version = "1", features = ["macros", "rt", "time"], default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0"
|
||||
|
|
|
@ -176,7 +176,7 @@ impl<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
|
|||
.boxed();
|
||||
s = s
|
||||
.chain(stream::unfold((), move |_| async move {
|
||||
tokio::time::delay_for(keep_alive_interval).await;
|
||||
tokio::time::sleep(keep_alive_interval).await;
|
||||
Some((
|
||||
Reaction::ServerMessage(ServerMessage::ConnectionKeepAlive),
|
||||
(),
|
||||
|
@ -658,7 +658,7 @@ mod test {
|
|||
impl Subscription {
|
||||
/// never never emits anything.
|
||||
async fn never(context: &Context) -> BoxStream<'static, FieldResult<i32>> {
|
||||
tokio::time::delay_for(Duration::from_secs(10000))
|
||||
tokio::time::sleep(Duration::from_secs(10000))
|
||||
.map(|_| unreachable!())
|
||||
.into_stream()
|
||||
.boxed()
|
||||
|
@ -668,7 +668,7 @@ mod test {
|
|||
async fn context(context: &Context) -> BoxStream<'static, FieldResult<i32>> {
|
||||
stream::once(future::ready(Ok(context.0)))
|
||||
.chain(
|
||||
tokio::time::delay_for(Duration::from_secs(10000))
|
||||
tokio::time::sleep(Duration::from_secs(10000))
|
||||
.map(|_| unreachable!())
|
||||
.into_stream(),
|
||||
)
|
||||
|
@ -682,7 +682,7 @@ mod test {
|
|||
Value::null(),
|
||||
))))
|
||||
.chain(
|
||||
tokio::time::delay_for(Duration::from_secs(10000))
|
||||
tokio::time::sleep(Duration::from_secs(10000))
|
||||
.map(|_| unreachable!())
|
||||
.into_stream(),
|
||||
)
|
||||
|
|
|
@ -11,13 +11,13 @@ repository = "https://github.com/graphql-rust/juniper"
|
|||
[dependencies]
|
||||
futures = "0.3.1"
|
||||
juniper = { version = "0.15.6", path = "../juniper", default-features = false }
|
||||
hyper = "0.13"
|
||||
hyper = {version = "0.14", features = ["server", "runtime"]}
|
||||
serde_json = "1.0"
|
||||
tokio = "0.2"
|
||||
tokio = "1"
|
||||
url = "2"
|
||||
|
||||
[dev-dependencies]
|
||||
juniper = { version = "0.15.6", path = "../juniper", features = ["expose-test-schema"] }
|
||||
pretty_env_logger = "0.4"
|
||||
reqwest = { version = "0.11", features = ["blocking", "rustls-tls"] }
|
||||
tokio = { version = "0.2", features = ["macros"] }
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use std::{convert::Infallible, sync::Arc};
|
||||
|
||||
use hyper::{
|
||||
server::Server,
|
||||
service::{make_service_fn, service_fn},
|
||||
Body, Method, Response, Server, StatusCode,
|
||||
Body, Method, Response, StatusCode,
|
||||
};
|
||||
use juniper::{
|
||||
tests::fixtures::starwars::schema::{Database, Query},
|
||||
|
|
|
@ -312,8 +312,9 @@ impl Error for GraphQLRequestError {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use hyper::{
|
||||
server::Server,
|
||||
service::{make_service_fn, service_fn},
|
||||
Body, Method, Response, Server, StatusCode,
|
||||
Body, Method, Response, StatusCode,
|
||||
};
|
||||
use juniper::{
|
||||
http::tests as http_tests,
|
||||
|
@ -421,7 +422,7 @@ mod tests {
|
|||
});
|
||||
|
||||
let (shutdown_fut, shutdown) = futures::future::abortable(async {
|
||||
tokio::time::delay_for(Duration::from_secs(60)).await;
|
||||
tokio::time::sleep(Duration::from_secs(60)).await;
|
||||
});
|
||||
|
||||
let server = Server::bind(&addr)
|
||||
|
|
|
@ -13,7 +13,7 @@ repository = "https://github.com/graphql-rust/juniper"
|
|||
|
||||
[dependencies]
|
||||
juniper = { version = "0.15.6", path = "../juniper", default-features = false}
|
||||
rocket = { version = "0.4.9", default-features = false }
|
||||
rocket = { version = "0.4.10", default-features = false }
|
||||
serde_json = "1.0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -14,4 +14,4 @@ juniper = { version = "0.15.6", path = "../juniper", default-features = false }
|
|||
|
||||
[dev-dependencies]
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "0.2", features = ["macros", "rt-core"] }
|
||||
tokio = { version = "1", features = ["macros", "rt"] }
|
||||
|
|
|
@ -13,20 +13,19 @@ subscriptions = ["juniper_graphql_ws"]
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
bytes = "0.5"
|
||||
futures = "0.3.1"
|
||||
juniper = { version = "0.15.6", path = "../juniper", default-features = false }
|
||||
juniper_graphql_ws = { version = "0.2.5", path = "../juniper_graphql_ws", optional = true }
|
||||
serde = { version = "1.0.75", features = ["derive"] }
|
||||
serde_json = "1.0.24"
|
||||
thiserror = "1.0"
|
||||
tokio = { version = "0.2", features = ["blocking", "rt-core"] }
|
||||
warp = "0.2"
|
||||
tokio = { version = "1", features = ["rt-multi-thread"] }
|
||||
warp = "0.3"
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.8"
|
||||
juniper = { version = "0.15.6", path = "../juniper", features = ["expose-test-schema"] }
|
||||
log = "0.4"
|
||||
percent-encoding = "2.1"
|
||||
tokio = { version = "0.2", features = ["blocking", "macros", "rt-core"] }
|
||||
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||
url = "2"
|
||||
|
|
|
@ -41,7 +41,6 @@ Check the LICENSE file for details.
|
|||
#![doc(html_root_url = "https://docs.rs/juniper_warp/0.2.0")]
|
||||
|
||||
use anyhow::anyhow;
|
||||
use bytes::Bytes;
|
||||
use futures::{FutureExt as _, TryFutureExt};
|
||||
use juniper::{
|
||||
http::{GraphQLBatchRequest, GraphQLRequest},
|
||||
|
@ -49,7 +48,7 @@ use juniper::{
|
|||
};
|
||||
use std::{collections::HashMap, str, sync::Arc};
|
||||
use tokio::task;
|
||||
use warp::{body, filters::BoxedFilter, http, query, Filter};
|
||||
use warp::{body, filters::BoxedFilter, http, hyper::body::Bytes, query, Filter};
|
||||
|
||||
/// Make a filter for graphql queries/mutations.
|
||||
///
|
||||
|
@ -717,7 +716,7 @@ mod tests_http_harness {
|
|||
}
|
||||
|
||||
fn make_request(&self, req: warp::test::RequestBuilder) -> TestResponse {
|
||||
let mut rt = tokio::runtime::Runtime::new().expect("Failed to create tokio::Runtime");
|
||||
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio::Runtime");
|
||||
make_test_response(rt.block_on(async move {
|
||||
req.filter(&self.filter).await.unwrap_or_else(|rejection| {
|
||||
let code = if rejection.is_not_found() {
|
||||
|
|
Loading…
Reference in a new issue