0

Using async-graphql and the below code (from their docs):

use async_graphql::{
    extensions::Tracing, EmptyMutation, EmptySubscription, MergedObject, Object, Schema,
};

pub type GraphqlSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;

pub fn create_schema() -> GraphqlSchema {
    Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
        .extension(Tracing)
        .finish()
}

#[derive(MergedObject, Default)]
struct QueryRoot(UserQuery, MovieQuery);

#[derive(Default)]
struct UserQuery;

#[Object]
impl UserQuery {
    async fn users(&self) -> Vec<u64> {
        todo!()
    }
}

#[derive(Default)]
struct MovieQuery;

#[Object]
impl MovieQuery {
    async fn movies(&self) -> Vec<u64> {
        todo!()
    }
}

I don't understand this error:

error[E0277]: the trait bound `fn(UserQuery, MovieQuery) -> QueryRoot {QueryRoot}: async_graphql::ObjectType` is not satisfied
   --> src\graphql\src\lib.rs:8:19
    |
8   |     Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
    |     ------------- ^^^^^^^^^ the trait `async_graphql::ObjectType` is not implemented for `fn(UserQuery, MovieQuery) -> QueryRoot {QueryRoot}`
    |     |
    |     required by a bound introduced by this call
    |
    = help: the following other types implement trait `async_graphql::ObjectType`:
              &'impl0 T
              Arc<T>
              Box<T>
              Connection<Cursor, Node, ConnectionFields, EdgeFields, Name, EdgeName>
              Edge<Cursor, Node, EdgeFields, Name>
              EmptyFields
              EmptyMutation
              MergedObjectTail
            and 12 others
note: required by a bound in `async_graphql::Schema::<Query, Mutation, Subscription>::build`
   --> C:\Users\Fred\.cargo\registry\src\github.com-1ecc6299db9ec823\async-graphql-4.0.13\src\schema.rs:315:12
    |
315 |     Query: ObjectType + 'static,
    |            ^^^^^^^^^^ required by this bound in `async_graphql::Schema::<Query, Mutation, Subscription>::build`

error[E0308]: mismatched types
  --> src\internal\graphql\src\lib.rs:8:5
   |
7  |   pub fn create_schema() -> GraphqlSchema {
   |                             ------------- expected `async_graphql::Schema<QueryRoot, EmptyMutation, EmptySubscription>` because of return type
8  | /     Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
9  | |         .extension(Tracing)
10 | |         .finish()
   | |_________________^ expected struct `QueryRoot`, found fn item
   |
   = note: expected struct `async_graphql::Schema<QueryRoot, _, _>`
              found struct `async_graphql::Schema<fn(UserQuery, MovieQuery) -> QueryRoot {QueryRoot}, _, _>`

Some errors have detailed explanations: E0277, E0308.
async-graphql = { version = "4.0.13", default-features = false, features = [
  "tracing",
] }
Chayim Friedman
  • 47,971
  • 5
  • 48
  • 77
Fred Hors
  • 3,258
  • 3
  • 25
  • 71

0 Answers0