Skip to content

Commit

Permalink
Use Poem for Federation examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed Sep 25, 2022
1 parent 8f87487 commit e7f936e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 52 deletions.
4 changes: 2 additions & 2 deletions federation/federation-accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"

[dependencies]
async-graphql = { path = "../../.." }
async-graphql-warp = { path = "../../../integrations/warp" }
async-graphql-poem = { path = "../../../integrations/poem" }
tokio = { version = "1.0.2", features = ["macros", "rt-multi-thread"] }
warp = "0.3"
poem = { version = "1.3.43" }
22 changes: 6 additions & 16 deletions federation/federation-accounts/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::convert::Infallible;

use async_graphql::{EmptyMutation, EmptySubscription, Object, Schema, SimpleObject, ID};
use async_graphql_warp::graphql;
use warp::{Filter, Reply};
use async_graphql_poem::GraphQL;
use poem::{listener::TcpListener, Route, Server};

#[derive(SimpleObject)]
struct User {
Expand Down Expand Up @@ -65,17 +63,9 @@ impl Query {
}

#[tokio::main]
async fn main() {
async fn main() -> std::io::Result<()> {
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);

warp::serve(graphql(schema).and_then(
|(schema, request): (
Schema<Query, EmptyMutation, EmptySubscription>,
async_graphql::Request,
)| async move {
Ok::<_, Infallible>(warp::reply::json(&schema.execute(request).await).into_response())
},
))
.run(([0, 0, 0, 0], 4001))
.await;
Server::new(TcpListener::bind("0.0.0.0:4001"))
.run(Route::new().at("/", GraphQL::new(schema)))
.await
}
4 changes: 2 additions & 2 deletions federation/federation-products/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"

[dependencies]
async-graphql = { path = "../../.." }
async-graphql-warp = { path = "../../../integrations/warp" }
async-graphql-poem = { path = "../../../integrations/poem" }
tokio = { version = "1.0.2", features = ["macros", "rt-multi-thread"] }
warp = "0.3"
poem = { version = "1.3.43" }
21 changes: 6 additions & 15 deletions federation/federation-products/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::convert::Infallible;

use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema, SimpleObject};
use async_graphql_warp::graphql;
use warp::{Filter, Reply};
use async_graphql_poem::GraphQL;
use poem::{listener::TcpListener, Route, Server};

#[derive(SimpleObject)]
struct Product {
Expand Down Expand Up @@ -32,7 +30,7 @@ impl Query {
}

#[tokio::main]
async fn main() {
async fn main() -> std::io::Result<()> {
let hats = vec![
Product {
upc: "top-1".to_string(),
Expand All @@ -55,14 +53,7 @@ async fn main() {
.data(hats)
.finish();

warp::serve(graphql(schema).and_then(
|(schema, request): (
Schema<Query, EmptyMutation, EmptySubscription>,
async_graphql::Request,
)| async move {
Ok::<_, Infallible>(warp::reply::json(&schema.execute(request).await).into_response())
},
))
.run(([0, 0, 0, 0], 4002))
.await;
Server::new(TcpListener::bind("0.0.0.0:4002"))
.run(Route::new().at("/", GraphQL::new(schema)))
.await
}
4 changes: 2 additions & 2 deletions federation/federation-reviews/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"

[dependencies]
async-graphql = { path = "../../.." }
async-graphql-warp = { path = "../../../integrations/warp" }
async-graphql-poem = { path = "../../../integrations/poem" }
tokio = { version = "1.0.2", features = ["macros", "rt-multi-thread"] }
warp = "0.3"
poem = { version = "1.3.43" }
21 changes: 6 additions & 15 deletions federation/federation-reviews/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::convert::Infallible;

use async_graphql::{
ComplexObject, Context, EmptyMutation, EmptySubscription, Enum, Object, Schema, SimpleObject,
ID,
};
use async_graphql_warp::graphql;
use warp::{Filter, Reply};
use async_graphql_poem::GraphQL;
use poem::{listener::TcpListener, Route, Server};

#[derive(SimpleObject)]
#[graphql(complex)]
Expand Down Expand Up @@ -157,7 +155,7 @@ fn user_by_id(id: ID, joined_timestamp: Option<u64>) -> User {
}

#[tokio::main]
async fn main() {
async fn main() -> std::io::Result<()> {
let reviews = vec![
Review {
id: "review-1".into(),
Expand Down Expand Up @@ -193,14 +191,7 @@ async fn main() {
.data(reviews)
.finish();

warp::serve(graphql(schema).and_then(
|(schema, request): (
Schema<Query, EmptyMutation, EmptySubscription>,
async_graphql::Request,
)| async move {
Ok::<_, Infallible>(warp::reply::json(&schema.execute(request).await).into_response())
},
))
.run(([0, 0, 0, 0], 4003))
.await;
Server::new(TcpListener::bind("0.0.0.0:4003"))
.run(Route::new().at("/", GraphQL::new(schema)))
.await
}

0 comments on commit e7f936e

Please sign in to comment.