Currently using 0.14.1. I'm attempting to implement fields with the juniper::object macro.
#[juniper::object(
Context = Context,
Scalar = juniper::DefaultScalarValue,
)]
impl Event {
On compilation, i see the following error:
error[E0277]: the trait bound models::Event: juniper::GraphQLType<__S> is not satisfied
On this struct, I've implemented another trait that does not have the juniper::object macro.
impl TraitName for Event
I've looked through the docs and issues and have been unable to find a solution.
Thanks!
Are you able to share a minimal reproduction script? It鈥檚 a bit hard to say what鈥檚 wrong from what you posted.
I have found similar issue. Here is minimal example which fails to build.
Bump, any ideas?
Hello,
Any updates on this ?
#[derive(GraphQLObject)]
^^^^^^^^^^^^^ the trait `juniper::types::base::GraphQLType<__S>` is not implemented for `api::graphql::projects::GQLProject`
I also trying to use it as in @andy128k example
Hello,
I found a workaround, so it will compile and work as expected. The idea is that you don't use #[juniper::object] inside the #[derive(GraphQLObject)], but what you can do is define all objects as #[juniper::object]. Yes it is a little bit ugly to define all the methods, but at least it works.
So instead of:
pub struct Article {
pub title: String,
}
#[juniper::object(name = "Article")]
impl Article {
fn title(&self) -> &str { &self.title }
}
#[derive(juniper::GraphQLObject)]
pub struct Blog {
pub url: String,
pub description: Vec<String>,
pub articles: Vec<Article>,
}
You define:
pub struct Article {
pub title: String,
}
#[juniper::object(name = "Article")]
impl Article {
fn title(&self) -> &str { &self.title }
}
pub struct Blog {
pub url: String,
pub description: Vec<String>,
pub articles: Vec<Article>,
}
#[juniper::object(name = "Blog")]
impl Blog {
// ...
}
@andy128k @RyuuGan Have you tried adding the scalar attribute to derived([GraphQLObject])?
#[derive(juniper::GraphQLObject)]
#[graphql(scalar = juniper::DefaultScalarValue)]
pub struct Blog {
pub url: String,
pub description: Vec<String>,
pub articles: Vec<Article>,
}
For some reason it is required, otherwise generic will be used instead of the DefaultScalarValue:
since generic_scalar has been set to true when deriving GraphQLObject:
Not sure if this is a bug or by design. 馃
I'm running into this issue as well when trying to use juniper::graphql_union! against two object where I used #[juniper::object] on an impl.
pub struct MyObject {
id: i32,
}
#[juniper::object]
impl MyObject {
fn id(&self) -> i32 {
&self.id
}
}
enum MyUnion {
MyObject(MyObject),
}
juniper::graphql_union!(MyUnion: () where Scalar = <S> |&self| {
instance_resolvers: |_| {
&MyObject => match *self { MyUnion::MyObject(ref h) => Some(h), _ => None },
}
});
This results with
error[E0277]: the trait bound `MyObject: juniper::types::base::GraphQLType<S>` is not satisfied
--> src/my_object.rs:8:1
|
8 | / juniper::graphql_union!(MyUnion: () where Scalar = <S> |&self| {
9 | | instance_resolvers: |_| {
10 | | &MyObject => match *self { MyUnion::MyObject(ref h) => Some(h), _ => None },
12 | | }
13 | | });
| |___^ the trait `juniper::types::base::GraphQLType<S>` is not implemented for `MyObject`
@urkle I guess that's because GraphQLType implementtion for MyObject is not generic over ScalarValue, while you're trying to do so for MyUnion.
Try this:
juniper::graphql_union!(MyUnion: () where Scalar = juniper::DefaultScalarValue |&self| {
Also, cargo expand will show more why this happens.
@tyranron Awesome Thanks! That fixed the issue.
Most helpful comment
I have found similar issue. Here is minimal example which fails to build.