-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unions example from book doesn't compile #315
Comments
Context is per-type, so you don't need to specify the context for unions. I think this problem is related to the new custom scalar support. |
/cc @weiznich |
This works: #[macro_use]
extern crate juniper;
use juniper::{EmptyMutation, FieldResult, Variables};
struct Context;
impl juniper::Context for Context {}
struct Query;
#[derive(GraphQLObject)]
struct Human {
id: String,
home_planet: String,
}
#[derive(GraphQLObject)]
struct Droid {
id: String,
primary_function: String,
}
enum Character {
Human(Human),
Droid(Droid),
}
graphql_union!(Character: () where Scalar = <S> |&self| {
instance_resolvers: |_| {
&Human => match *self { Character::Human(ref h) => Some(h), _ => None },
&Droid => match *self { Character::Droid(ref d) => Some(d), _ => None },
}
});
fn main() {} Note the Keeping this open as we should probably synthesize that in the macro if it isn't entered? FWIW I raised this in #251 (comment) and I believed the answer in #251 (comment) was sufficient. |
I remember having issues around generic defaults in the past. |
As mentioned in the other issue, the reason why I think this is reasonable and we can leave it this way. We can somewhat improve the situation with the new proc macros though. |
I noticed the code from the section in the book about unions don't compile. Not sure what I'm doing wrong 🤔
Here is an example:
Error I'm getting
I would also expect
Character: ()
should beCharacter: Context
ingraphql_union!
. But that gives an error saying it expected()
.Juniper version is 0.11.1
The text was updated successfully, but these errors were encountered: