Function async_graphql_warp::graphql
source · pub fn graphql<E>(
executor: E
) -> impl Filter<Extract = ((E, Request),), Error = Rejection> + Clonewhere
E: Executor,
Expand description
GraphQL request filter
It outputs a tuple containing the async_graphql::Schema
and
async_graphql::Request
.
Examples
use std::convert::Infallible;
use async_graphql::*;
use async_graphql_warp::*;
use warp::Filter;
struct QueryRoot;
#[Object]
impl QueryRoot {
async fn value(&self, ctx: &Context<'_>) -> i32 {
unimplemented!()
}
}
type MySchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;
let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
let filter = async_graphql_warp::graphql(schema).and_then(
|(schema, request): (MySchema, async_graphql::Request)| async move {
Ok::<_, Infallible>(async_graphql_warp::GraphQLResponse::from(
schema.execute(request).await,
))
},
);
warp::serve(filter).run(([0, 0, 0, 0], 8000)).await;