Juniper: How to use new `object` macro when its subject gets derived

Created on 20 May 2019  路  2Comments  路  Source: graphql-rust/juniper

Trying to figure out how to use new object macro when its subject gets derived as a part of another struct:

struct Person {
  name: String,
}

#[juniper::object]
impl Person {
  fn name(&self) -> &str {
    self.name.as_str()
  }
}

#[derive(GraphQLObject)]
struct Derived {
  person: Person,
}

Error is on the line #[derive(GraphQLObject)]:

the trait bound `user::Person: juniper::GraphQLType<__S>` is not satisfied

the trait `juniper::GraphQLType<__S>` is not implemented for `user::Person`

help: consider adding a `where user::Person: juniper::GraphQLType<__S>` bound
bug

Most helpful comment

This is an unfortunate interaction of generics.

I'm working on a fix, but for now you can do this:

#[derive(GraphQLObject)]
#[graphql(Scalar = juniper::DefaultScalarValue)]
struct Derived {
  person: Person,
}

All 2 comments

This is an unfortunate interaction of generics.

I'm working on a fix, but for now you can do this:

#[derive(GraphQLObject)]
#[graphql(Scalar = juniper::DefaultScalarValue)]
struct Derived {
  person: Person,
}

It works, thanks!

Was this page helpful?
0 / 5 - 0 ratings