DEV Community

Discussion on: Building Powerful GraphQL Servers with Rust

Collapse
 
jacobmgevans profile image
Jacob Evans

I ran across an issue with Actix with how the Response was structured inside of the web::block() moving the Response and Error construction outside resolved this for me. I found an issue related as well in their GH (github.com/actix/actix-web/issues/857)

Code Snippet of Changes

fn graphql(
    st: web::Data<Arc<Schema>>,
    data: web::Json<GraphQLRequest>,) -> impl Future<Item = HttpResponse , Error = error::Error>{
        web::block(move || {
            let res = data.execute(&st, &());
            Ok::<_,serde_json::error::Error>(serde_json::to_string(&res)?)
        }).map_err(Error::from)
        .and_then(|user| {
            Ok(HttpResponse::Ok()
        .content_type("application/json")
        .body(user))
        })
}