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

39 lines
1008 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-20 05:44:20 +00:00
`Async-graphql-actix-web` provides an implementation of `actix_web::FromRequest` for `Request`.
This is actually an abstraction around `async_graphql::Request` and you can call `Request::into_inner` to
2020-09-11 15:38:18 +00:00
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-10-14 00:03:51 +00:00
request: async_graphql_actix_web::Request,
2020-09-20 05:44:20 +00:00
) -> web::Json<Response> {
web::Json(Response(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)
}
```
2020-10-14 01:10:06 +00:00
## More examples
https://github.com/async-graphql/examples/tree/master/actix-web