[][src]Function async_graphql_warp::graphql

pub fn graphql<Query, Mutation, Subscription>(
    schema: Schema<Query, Mutation, Subscription>
) -> BoxedFilter<((Schema<Query, Mutation, Subscription>, Request),)> 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;

#[GQLObject]
impl QueryRoot {
    #[field]
    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>(GQLResponse::from(schema.execute(request).await))
    });
    warp::serve(filter).run(([0, 0, 0, 0], 8000)).await;
}