async-graphql / examples

217 stars 54 forks source link

Schema execute trait bounds error #43

Closed kennetpostigo closed 2 years ago

kennetpostigo commented 2 years ago

Hi, i'm working on getting a new graphql server up using the actix-web v4 branch(async-graphql-actix-web = { git = "https://github.com/async-graphql/async-graphql", branch = "actix-web-v4-beta" }) and i'm running into a few trait bounds issues that i'm unsure of how to fix. Here is the base code:

#[post("/graphql")]
async fn graphql(
  schema: web::Data<Schema<Query, Mutation, EmptySubscription>>,
  req: Request,
) -> Response {
  let span = tracing::info_span!("root");

  schema
    .execute(req.into_inner())
    .instrument(span)
    .await
    .into()
}

#[get("/playground")]
async fn playground() -> HttpResponse {
  HttpResponse::Ok()
    .content_type("text/html; charset=utf-8")
    .body(playground_source(GraphQLPlaygroundConfig::new("/graphql")))
}

pub fn init(pg: Pool<Postgres>) -> Box<dyn Fn(&mut web::ServiceConfig)> {
  let schema = Schema::build(Query::default(), Mutation::default(), EmptySubscription)
    .data(pg)
    .finish();

  Box::new(move |app: &mut web::ServiceConfig| {
    app
      .app_data(web::Data::new(schema.clone()))
      .service(graphql)
      .service(playground);
  })
}

This will throw:

the trait bound `std::string::String: std::convert::From<async_graphql::request::Request>` is not satisfied
the following implementations were found:
  <std::string::String as std::convert::From<&mut str>>
  <std::string::String as std::convert::From<&std::string::String>>
  <std::string::String as std::convert::From<&str>>
  <std::string::String as std::convert::From<async_graphql::ID>>
and 5 others
required because of the requirements on the impl of `std::convert::Into<std::string::String>` for `async_graphql::request::Request`
required because of the requirements on the impl of `std::convert::From<async_graphql::request::Request>` for `async_graphql::Request`
1 redundant requirement hidden
required because of the requirements on the impl of `std::convert::Into<async_graphql::Request>` for `async_graphql::request::Request`

and:

the trait bound `async_graphql_actix_web::Response: std::convert::From<async_graphql::Response>` is not satisfied
the following implementations were found:
  <async_graphql_actix_web::Response as std::convert::From<async_graphql::response::BatchResponse>>
  <async_graphql_actix_web::Response as std::convert::From<async_graphql::response::Response>>
required because of the requirements on the impl of `std::convert::Into<async_graphql_actix_web::Response>` for `async_graphql::Response`

Is this issue present only because of the branch i'm working off of?