Async-graphql: actix-web-v4-beta doesn't compile with error: no HttpResponseBuilder in dev

Created on 28 Apr 2021  路  4Comments  路  Source: async-graphql/async-graphql

Expected Behavior

actix-web integration shoiuld compile.

Actual Behavior

Compiling actix-web-actors v4.0.0-beta.4
error[E0432]: unresolved import actix_web::dev::HttpResponseBuilder
--> /home/robert/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-actors-4.0.0-beta.4/src/ws.rs:25:5
|
25 | use actix_web::dev::HttpResponseBuilder;
| ^^^^^^^^^^^^^^^^-------------------
| | |
| | help: a similar name exists in the module: BaseHttpResponseBuilder
| no HttpResponseBuilder in dev

Steps to Reproduce the Problem

  1. Checkout branch actix-web-v4-beta
  2. cd integrations/actix-web
  3. cargo build

Specifications

  • Version: actix-web-v4-beta
  • Platform: Linux Mint 20.1
  • Subsystem: integrations/actix-web
bug

Most helpful comment

This works with [email protected]:

use async_graphql::*;
use actix_web::{post, web, HttpResponse, Responder};

struct RequestWrapper(Request);
type ActixSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;

#[post("/graphql")]
async fn web_graphql(
    schema: web::Data<ActixSchema>,
    body: web::Bytes,
) -> actix_web::Result<impl Responder> {
    let body = std::str::from_utf8(body.as_ref())?;
    let req = serde_json::from_str::<Request>(body).unwrap();
    let req = RequestWrapper { 0: req };
    let resp = schema.execute(req).await;

    Ok(HttpResponse::Ok()
        .content_type("application/json;charset=utf-8")
        .body(serde_json::to_string(&resp).unwrap()))
}

impl Into<Request> for RequestWrapper {
    fn into(self) -> Request {
        self.0
    }
}

All 4 comments

Are there any near future plans about the actix-web-v4-beta release?

Actix-web-beta API is very unstable, I will follow up soon after the official version is released.

Hi @sunli829 ,

I'm converting my project from async-std/tide -> tokio/actix-web and the actix members are recommending using the 4.0 beta because of my actix/tokio/sqlx usage. Do you know of any workarounds for being able to use actix 4.0 beta?

At the moment the only issue I actually have is for this piece of code:

use actix_web::{get, post, web, HttpResponse};
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{EmptySubscription, Schema};
use async_graphql_actix_web::{Request, Response};
use sqlx::{Pool, Postgres};

#[post("/graphql")]
async fn graphql(
  schema: web::Data<Schema<Query, Mutation, EmptySubscription>>,
  req: Request,
) -> Response {
  schema.execute(req.into_inner()).await.into()
}

Produces this error:

error[E0277]: the trait bound `fn(actix_web::web::Data<async_graphql::Schema<gql::types::Query, gql::types::Mutation, async_graphql::EmptySubscription>>, async_graphql_actix_web::Request) -> impl std::future::Future {<gql::graphql as actix_web::dev::HttpServiceFactory>::register::graphql}: actix_web::dev::Handler<_, _>` is not satisfied
  --> platform/errors/src/gql/mod.rs:11:10
   |
11 | async fn graphql(
   |          ^^^^^^^ the trait `actix_web::dev::Handler<_, _>` is not implemented for `fn(actix_web::web::Data<async_graphql::Schema<gql::types::Query, gql::types::Mutation, async_graphql::EmptySubscription>>, async_graphql_actix_web::Request) -> impl std::future::Future {<gql::graphql as actix_web::dev::HttpServiceFactory>::register::graphql}`

This works with [email protected]:

use async_graphql::*;
use actix_web::{post, web, HttpResponse, Responder};

struct RequestWrapper(Request);
type ActixSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;

#[post("/graphql")]
async fn web_graphql(
    schema: web::Data<ActixSchema>,
    body: web::Bytes,
) -> actix_web::Result<impl Responder> {
    let body = std::str::from_utf8(body.as_ref())?;
    let req = serde_json::from_str::<Request>(body).unwrap();
    let req = RequestWrapper { 0: req };
    let resp = schema.execute(req).await;

    Ok(HttpResponse::Ok()
        .content_type("application/json;charset=utf-8")
        .body(serde_json::to_string(&resp).unwrap()))
}

impl Into<Request> for RequestWrapper {
    fn into(self) -> Request {
        self.0
    }
}
Was this page helpful?
0 / 5 - 0 ratings