/// Actix Web GraphQL Handler for GET and POST requests
Actix Web GraphQL Handler for GET and POST requests
Actix Web GraphQL Handler for GET and POST requests
pub async fn graphql_handler<Query, Mutation, Subscription, Context, S>(
    schema: &juniper::RootNode<'static, Query, Mutation, Subscription, S>,
    context: &Context,
    req: HttpRequest,
    payload: actix_web::web::Payload,
) -> Result<HttpResponse, Error>
where
    S: ScalarValue + Send + Sync + 'static,
    Context: Send + Sync + 'static,
    Query: juniper::GraphQLTypeAsync<S, Context = Context> + Send + Sync + 'static,
    Query::TypeInfo: Send + Sync,
    Mutation: juniper::GraphQLTypeAsync<S, Context = Context> + Send + Sync + 'static,
    Mutation::TypeInfo: Send + Sync,
    Subscription: juniper::GraphQLSubscriptionType<S, Context = Context> + Send + Sync + 'static,
    Subscription::TypeInfo: Send + Sync,
{
    match *req.method() {
        Method::POST => post_graphql_handler(schema, context, req, payload).await,
        Method::GET => get_graphql_handler(schema, context, req).await,
        _ => Err(ErrorMethodNotAllowed(
            "GraphQL requests can only be sent with GET or POST",
        )),
    }
}
pub async fn graphql_handler < Query , Mutation , Subscription , Context , S > ( schema : & juniper :: RootNode < ' static , Query , Mutation , Subscription , S > , context : & Context , req : HttpRequest , payload : actix_web :: web :: Payload , ) -> Result < HttpResponse , Error > where S : ScalarValue + Send + Sync + ' static , Context : Send + Sync + ' static , Query : juniper :: GraphQLTypeAsync < S , Context = Context > + Send + Sync + ' static , Query :: TypeInfo : Send + Sync , Mutation : juniper :: GraphQLTypeAsync < S , Context = Context > + Send + Sync + ' static , Mutation :: TypeInfo : Send + Sync , Subscription : juniper :: GraphQLSubscriptionType < S , Context = Context > + Send + Sync + ' static , Subscription :: TypeInfo : Send + Sync , { match * req . method ( ) { Method :: POST => post_graphql_handler ( schema , context , req , payload ) . await , Method :: GET => get_graphql_handler ( schema , context , req ) . await , _ => Err ( ErrorMethodNotAllowed ( " " , ) ) , } }
Actix Web GraphQL Handler for GET and POST requests
Actix Web GraphQL Handler for GET and POST requests
schema
&juniper::RootNode<'static, Query, Mutation, Subscription, S>
context
&Context
req
HttpRequest
payload
actix_web::web::Payload