async-graphql / examples

217 stars 54 forks source link

Do you have an example of deferred for warp? #12

Closed sync closed 4 years ago

sync commented 4 years ago

I looked at this pr: https://github.com/async-graphql/async-graphql/commit/467a6119bf689c6ecf59b098f73f457fc18349a0

And here: https://github.com/async-graphql/examples/blob/ec71db917151076ced0a273eaf928a54c643cf67/actix-web/defer/src/main.rs

But i can't put the pieces back together for warp.

sync commented 4 years ago

I've tried the following

    pub async fn graphql(
        (schema, builder): (
            Schema<QueryRoot, MutationRoot, EmptySubscription>,
            QueryBuilder,
        ),
    ) -> Result<impl warp::Reply, warp::reject::Rejection> {
        let resp = builder.execute_stream(&schema).await;
        let stream: GQLResponseStream = resp.into();
        Ok(warp::reply::json(stream).into_response())
    }

obviously this isn't proper: Ok(warp::reply::json(stream).into_response())

sunli829 commented 4 years ago

GQLResponseStream implements Reply, so you should use it as follows.

let stream: GQLResponseStream = resp.into();
Ok(stream.into_response())
sync commented 4 years ago

Fantastic it worked thanks

sync commented 4 years ago

I'll try to submit an example repo this week end

sunli829 commented 4 years ago

I'll try to submit an example repo this week end

Thank you! 😁