async-graphql/docs/en/src/integrations_to_actix_web.md

35 lines
915 B
Markdown
Raw Normal View History

2020-04-15 03:15:30 +00:00
# Actix-web
2020-05-09 21:56:45 +00:00
2020-09-11 15:38:18 +00:00
`Async-graphql-actix-web` provides an implementation of `actix_web::FromRequest` for `GQLRequest`.
This is actually an abstraction around `async_graphql::Request` and you can call `GQLRequest::into_inner` to
convert it into a `async_graphql::Request`.
2020-05-09 21:56:45 +00:00
2020-09-01 05:47:22 +00:00
`WSSubscription` is an Actor that supports WebSocket subscriptions.
2020-05-09 21:56:45 +00:00
## 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<Schema>,
2020-09-11 15:38:18 +00:00
request: GQLRequest,
2020-05-09 21:56:45 +00:00
) -> web::Json<GQLResponse> {
2020-09-11 15:38:18 +00:00
web::Json(GQLResponse(schema.execute(request.into_inner()).await)
2020-05-09 21:56:45 +00:00
}
```
## Subscription example
```rust
async fn index_ws(
schema: web::Data<Schema>,
req: HttpRequest,
payload: web::Payload,
) -> Result<HttpResponse> {
ws::start_with_protocols(WSSubscription::new(&schema), &["graphql-ws"], &req, payload)
}
```