2021-11-30 05:46:23 +00:00
|
|
|
# Actix-web
|
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>,
|
2021-11-16 06:51:20 +00:00
|
|
|
request: GraphQLRequest,
|
|
|
|
) -> web::Json<GraphQLResponse> {
|
|
|
|
web::Json(schema.execute(request.into_inner()).await.into())
|
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> {
|
2021-11-16 06:51:20 +00:00
|
|
|
GraphQLSubscription::new(Schema::clone(&*schema)).start(&req, payload)
|
2020-05-09 21:56:45 +00:00
|
|
|
}
|
|
|
|
```
|
2020-10-14 01:10:06 +00:00
|
|
|
|
|
|
|
## More examples
|
|
|
|
|
2020-10-14 01:17:00 +00:00
|
|
|
[https://github.com/async-graphql/examples/tree/master/actix-web](https://github.com/async-graphql/examples/tree/master/actix-web)
|