Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed Dec 4, 2020
1 parent 71d7318 commit b51536f
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 51 deletions.
8 changes: 1 addition & 7 deletions actix-web/subscription/src/main.rs
@@ -1,5 +1,4 @@
use actix_web::{guard, web, App, HttpRequest, HttpResponse, HttpServer, Result};
use actix_web_actors::ws;
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::Schema;
use async_graphql_actix_web::{Request, Response, WSSubscription};
Expand All @@ -22,12 +21,7 @@ async fn index_ws(
req: HttpRequest,
payload: web::Payload,
) -> Result<HttpResponse> {
ws::start_with_protocols(
WSSubscription::new(Schema::clone(&*schema)),
&["graphql-ws"],
&req,
payload,
)
WSSubscription::start(Schema::clone(&*schema), &req, payload)
}

#[actix_rt::main]
Expand Down
32 changes: 13 additions & 19 deletions actix-web/token-from-header/src/main.rs
@@ -1,5 +1,4 @@
use actix_web::{guard, web, App, HttpRequest, HttpResponse, HttpServer, Result};
use actix_web_actors::ws;
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{Context, Data, EmptyMutation, Object, Schema, Subscription};
use async_graphql_actix_web::{Request, Response, WSSubscription};
Expand Down Expand Up @@ -55,25 +54,20 @@ async fn index_ws(
req: HttpRequest,
payload: web::Payload,
) -> Result<HttpResponse> {
ws::start_with_protocols(
WSSubscription::new(Schema::clone(&*schema)).initializer(|value| {
#[derive(serde_derive::Deserialize)]
struct Payload {
token: String,
}
WSSubscription::start_with_initializer(Schema::clone(&*schema), &req, payload, |value| {
#[derive(serde_derive::Deserialize)]
struct Payload {
token: String,
}

if let Ok(payload) = serde_json::from_value::<Payload>(value) {
let mut data = Data::default();
data.insert(MyToken(payload.token));
Ok(data)
} else {
Err("Token is required".into())
}
}),
&["graphql-ws"],
&req,
payload,
)
if let Ok(payload) = serde_json::from_value::<Payload>(value) {
let mut data = Data::default();
data.insert(MyToken(payload.token));
Ok(data)
} else {
Err("Token is required".into())
}
})
}

#[actix_rt::main]
Expand Down
4 changes: 2 additions & 2 deletions federation/federation-accounts/Cargo.toml
Expand Up @@ -7,6 +7,6 @@ edition = "2018"
[dependencies]
async-graphql = { path = "../../.." }
async-graphql-warp = { path = "../../../integrations/warp" }
tokio = { version = "0.3.0", features = ["macros", "rt-multi-thread"] }
tokio-compat-02 = "0.1.2"
tokio = { version = "0.2.0", features = ["macros", "rt-threaded"] }
warp = "0.2"

2 changes: 0 additions & 2 deletions federation/federation-accounts/src/main.rs
@@ -1,7 +1,6 @@
use async_graphql::{EmptyMutation, EmptySubscription, Object, Schema, SimpleObject, ID};
use async_graphql_warp::graphql;
use std::convert::Infallible;
use tokio_compat_02::FutureExt;
use warp::{Filter, Reply};

#[derive(SimpleObject)]
Expand Down Expand Up @@ -45,6 +44,5 @@ async fn main() {
},
))
.run(([0, 0, 0, 0], 4001))
.compat()
.await;
}
3 changes: 1 addition & 2 deletions federation/federation-products/Cargo.toml
Expand Up @@ -7,6 +7,5 @@ edition = "2018"
[dependencies]
async-graphql = { path = "../../.." }
async-graphql-warp = { path = "../../../integrations/warp" }
tokio = { version = "0.3.0", features = ["macros", "rt-multi-thread"] }
tokio-compat-02 = "0.1.2"
tokio = { version = "0.2.0", features = ["macros", "rt-threaded"] }

This comment has been minimized.

Copy link
@phungleson

phungleson Dec 12, 2020

Hey @sunli829 sorry wonder if there is any particular reasons that you moved all example back to tokio 0.2.0?

This comment has been minimized.

Copy link
@sunli829

sunli829 Dec 12, 2020

Author Collaborator

Because warp and actix-web have not yet been upgraded to tokio 0.3, a compatibility layer needs to be added to be able to use them normally. In order to avoid unnecessary misunderstandings, it is temporarily downgraded to tokio 0.2.

This comment has been minimized.

Copy link
@phungleson

phungleson Dec 12, 2020

Alright thanks, I am pretty new to this, are you aware of any performance or ergonomic benefits of tokio 0.3 thanks in advance.

This comment has been minimized.

Copy link
@sunli829

sunli829 Dec 12, 2020

Author Collaborator

As far as I know, the difference is not that big.

This comment has been minimized.

Copy link
@phungleson

phungleson Dec 12, 2020

Cool thanks a lot for your prompt response @sunli829

warp = "0.2"
2 changes: 0 additions & 2 deletions federation/federation-products/src/main.rs
@@ -1,7 +1,6 @@
use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema, SimpleObject};
use async_graphql_warp::graphql;
use std::convert::Infallible;
use tokio_compat_02::FutureExt;
use warp::{Filter, Reply};

#[derive(SimpleObject)]
Expand Down Expand Up @@ -63,6 +62,5 @@ async fn main() {
},
))
.run(([0, 0, 0, 0], 4002))
.compat()
.await;
}
3 changes: 1 addition & 2 deletions federation/federation-reviews/Cargo.toml
Expand Up @@ -7,6 +7,5 @@ edition = "2018"
[dependencies]
async-graphql = { path = "../../.." }
async-graphql-warp = { path = "../../../integrations/warp" }
tokio = { version = "0.3.0", features = ["macros", "rt-multi-thread"] }
tokio-compat-02 = "0.1.2"
tokio = { version = "0.2.0", features = ["macros", "rt-threaded"] }
warp = "0.2"
2 changes: 0 additions & 2 deletions federation/federation-reviews/src/main.rs
@@ -1,7 +1,6 @@
use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema, SimpleObject, ID};
use async_graphql_warp::graphql;
use std::convert::Infallible;
use tokio_compat_02::FutureExt;
use warp::{Filter, Reply};

struct User {
Expand Down Expand Up @@ -105,6 +104,5 @@ async fn main() {
},
))
.run(([0, 0, 0, 0], 4003))
.compat()
.await;
}
2 changes: 1 addition & 1 deletion models/books/Cargo.toml
Expand Up @@ -7,6 +7,6 @@ edition = "2018"
[dependencies]
async-graphql = { path = "../../.." }
slab = "0.4.2"
tokio = { version = "0.3.0", features = ["time", "stream"] }
tokio = { version = "0.2.0", features = ["time", "stream"] }
futures = "0.3.0"
once_cell = "1.0"
3 changes: 1 addition & 2 deletions warp/starwars/Cargo.toml
Expand Up @@ -7,8 +7,7 @@ edition = "2018"
[dependencies]
async-graphql = { path = "../../.." }
async-graphql-warp = { path = "../../../integrations/warp" }
tokio = { version = "0.3.0", features = ["macros", "rt-multi-thread"] }
tokio-compat-02 = "0.1.2"
tokio = { version = "0.2.0", features = ["macros", "rt-threaded"] }
warp = "0.2"
starwars = { path = "../../models/starwars" }
http = "0.2"
3 changes: 1 addition & 2 deletions warp/starwars/src/main.rs
Expand Up @@ -4,7 +4,6 @@ use async_graphql_warp::{BadRequest, Response};
use http::StatusCode;
use starwars::{QueryRoot, StarWars};
use std::convert::Infallible;
use tokio_compat_02::FutureExt;
use warp::{http::Response as HttpResponse, Filter, Rejection};

#[tokio::main]
Expand Down Expand Up @@ -44,5 +43,5 @@ async fn main() {
))
});

warp::serve(routes).run(([0, 0, 0, 0], 8000)).compat().await;
warp::serve(routes).run(([0, 0, 0, 0], 8000)).await;
}
3 changes: 1 addition & 2 deletions warp/subscription/Cargo.toml
Expand Up @@ -7,7 +7,6 @@ edition = "2018"
[dependencies]
async-graphql = { path = "../../.." }
async-graphql-warp = { path = "../../../integrations/warp" }
tokio = { version = "0.3.0", features = ["macros", "rt-multi-thread"] }
tokio-compat-02 = "0.1.2"
tokio = { version = "0.2.0", features = ["macros", "rt-threaded"] }
warp = "0.2"
books = { path = "../../models/books" }
3 changes: 1 addition & 2 deletions warp/subscription/src/main.rs
Expand Up @@ -3,7 +3,6 @@ use async_graphql::Schema;
use async_graphql_warp::{graphql_subscription, Response};
use books::{MutationRoot, QueryRoot, Storage, SubscriptionRoot};
use std::convert::Infallible;
use tokio_compat_02::FutureExt;
use warp::{http::Response as HttpResponse, Filter};

#[tokio::main]
Expand Down Expand Up @@ -32,5 +31,5 @@ async fn main() {
let routes = graphql_subscription(schema)
.or(graphql_playground)
.or(graphql_post);
warp::serve(routes).run(([0, 0, 0, 0], 8000)).compat().await;
warp::serve(routes).run(([0, 0, 0, 0], 8000)).await;
}
3 changes: 1 addition & 2 deletions warp/token-from-header/Cargo.toml
Expand Up @@ -7,8 +7,7 @@ edition = "2018"
[dependencies]
async-graphql = { path = "../../.." }
async-graphql-warp = { path = "../../../integrations/warp" }
tokio = { version = "0.3.0", features = ["macros", "rt-multi-thread"] }
tokio-compat-02 = "0.1.2"
tokio = { version = "0.2.0", features = ["macros", "rt-threaded"] }
warp = "0.2"
serde_json = "1.0"
serde_derive = "1.0"
Expand Down
3 changes: 1 addition & 2 deletions warp/token-from-header/src/main.rs
Expand Up @@ -3,7 +3,6 @@ use async_graphql::{Context, Data, EmptyMutation, Object, Schema, Subscription};
use async_graphql_warp::{graphql_subscription_with_data, Response};
use futures::{stream, Stream};
use std::convert::Infallible;
use tokio_compat_02::FutureExt;
use warp::{http::Response as HttpResponse, Filter};

struct MyToken(String);
Expand Down Expand Up @@ -78,5 +77,5 @@ async fn main() {
)
.or(graphql_playground)
.or(graphql_post);
warp::serve(routes).run(([0, 0, 0, 0], 8000)).compat().await;
warp::serve(routes).run(([0, 0, 0, 0], 8000)).await;
}

0 comments on commit b51536f

Please sign in to comment.