diff --git a/docs/en/src/integrations.md b/docs/en/src/integrations.md index e20ec321..fd622b8e 100644 --- a/docs/en/src/integrations.md +++ b/docs/en/src/integrations.md @@ -1 +1,8 @@ # Integrations + +`Async-Graphql` supports several common Rust web servers. + +- Actix-web [async-graphql-actix-web](https://crates.io/crates/async-graphql-actix-web) +- Warp [async-graphql-warp](https://crates.io/crates/async-graphql-warp) + +**Even if the server you are currently using is not in the above list, it is quite simple to implement similar functionality yourself** \ No newline at end of file diff --git a/docs/en/src/integrations_to_actix_web.md b/docs/en/src/integrations_to_actix_web.md index efacadad..6db435fd 100644 --- a/docs/en/src/integrations_to_actix_web.md +++ b/docs/en/src/integrations_to_actix_web.md @@ -1 +1,32 @@ # Actix-web + +`Async-graphql-actix-web` provides an implementation of `actix_web::FromRequest` for `GQLRequest`. This is actually an abstraction around `QueryBuilder` and you can call `GQLRequest::into_inner` to convert it into a `QueryBuilder`。 + +`WSSubscription` is an Actor that supports WebSocket subscriptions。 + +## Request example + +When you define your `actix_web::App` you need to pass in the Schema as data. + +```rust +async fn index( + // Schema now accessible here + schema: web::Data, + gql_request: GQLRequest, +) -> web::Json { + web::Json(GQLResponse(gql_request.into_inner().execute(&schema).await)) +} + +``` + +## Subscription example + +```rust +async fn index_ws( + schema: web::Data, + req: HttpRequest, + payload: web::Payload, +) -> Result { + ws::start_with_protocols(WSSubscription::new(&schema), &["graphql-ws"], &req, payload) +} +``` diff --git a/docs/en/src/integrations_to_warp.md b/docs/en/src/integrations_to_warp.md index 0f90660e..52c95aac 100644 --- a/docs/en/src/integrations_to_warp.md +++ b/docs/en/src/integrations_to_warp.md @@ -1 +1,29 @@ # Warp + +For `Async-graphql-warp`, two `Filter` integrations are provided: `graphql` and `graphql_subscription`. + +The `graphql` filter is used for execution `Query` and `Mutation` requests. It always asks for the POST method and outputs a `Schema` via `QueryBuilder`. You can combine other filters later, or directly call `QueryBuilder::execute` to execute the query. + +`graphql_subscription` is used to implement WebSocket subscriptions. It outputs `warp::Reply`. + +## Request example + +```rust +let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription); +let filter = async_graphql_warp::graphql(schema).and_then(|(schema, builder): (_, QueryBuilder)| async move { + // Execute query + let resp = builder.execute(&schema).await; + + // Return result + Ok::<_, Infallible>(warp::reply::json(&GQLResponse(resp)).into_response()) +}); +warp::serve(filter).run(([0, 0, 0, 0], 8000)).await; +``` + +## Subscription example + +```rust +let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot); +let filter = async_graphql_warp::graphql_subscription(schema); +warp::serve(filter).run(([0, 0, 0, 0], 8000)).await; +```