2020-04-15 03:15:30 +00:00
# Warp
2020-05-09 21:56:45 +00:00
For `Async-graphql-warp` , two `Filter` integrations are provided: `graphql` and `graphql_subscription` .
2021-11-16 06:51:20 +00:00
The `graphql` filter is used for execution `Query` and `Mutation` requests. It extracts GraphQL request and outputs `async_graphql::Schema` and `async_graphql::Request` .
2020-09-11 15:38:18 +00:00
You can combine other filters later, or directly call `Schema::execute` to execute the query.
2020-05-09 21:56:45 +00:00
`graphql_subscription` is used to implement WebSocket subscriptions. It outputs `warp::Reply` .
## Request example
```rust
2020-09-11 15:38:18 +00:00
type MySchema = Schema< QueryRoot , EmptyMutation , EmptySubscription > ;
2020-05-09 21:56:45 +00:00
let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
2020-09-11 15:38:18 +00:00
let filter = async_graphql_warp::graphql(schema).and_then(|(schema, request): (MySchema, async_graphql::Request)| async move {
2020-05-09 21:56:45 +00:00
// Execute query
2020-09-11 15:38:18 +00:00
let resp = schema.execute(request).await;
2020-05-09 21:56:45 +00:00
// Return result
2020-10-14 00:03:51 +00:00
Ok::< _ , Infallible > (async_graphql_warp::Response::from(resp))
2020-05-09 21:56:45 +00:00
});
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;
```
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/warp ](https://github.com/async-graphql/examples/tree/master/warp )