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` .
2020-09-11 15:38:18 +00:00
The `graphql` filter is used for execution `Query` and `Mutation` requests. It always asks for the POST method and outputs a `async_graphql::Schema` and `async_graphql::Request` .
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;
```