[][src]Function async_graphql_warp::graphql

pub fn graphql<Query, Mutation, Subscription>(
    schema: Schema<Query, Mutation, Subscription>
) -> impl Filter<Extract = ((Schema<Query, Mutation, Subscription>, Request),), Error = Rejection> + Clone where
    Query: ObjectType + Send + Sync + 'static,
    Mutation: ObjectType + Send + Sync + 'static,
    Subscription: SubscriptionType + Send + Sync + 'static, 

GraphQL request filter

It outputs a tuple containing the async_graphql::Schema and async_graphql::Request.

Examples

Full Example


use async_graphql::*;
use async_graphql_warp::*;
use warp::Filter;
use std::convert::Infallible;

struct QueryRoot;

#[Object]
impl QueryRoot {
    async fn value(&self, ctx: &Context<'_>) -> i32 {
        unimplemented!()
    }
}

type MySchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;

#[tokio::main]
async fn main() {
    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::Response::from(schema.execute(request).await))
    });
    warp::serve(filter).run(([0, 0, 0, 0], 8000)).await;
}