Is there a way to have all fields of a struct have auto-generated resolvers, as provided by #[derive(GraphQLObject)], but be able to custom-derive a few more, as can be done with graphql_object! macro?
Since the two techniques don't mix, it seems the only choice is to use graphql_object! macro, and hand-write all of the trivial resolvers along with the custom ones.
I don't believe there is. Happy to review a PR!
This is much wanted and there are multiple paths to this.
One option, merging definitions, is discussed in #182 .
My personally preferred way forward would be to apply a proc macro to a whole module to make this easy.
This is currently only possible on nightly with the proc_macro_hygiene feature.
I'd want us to have code like this and make it just work:
#[juniper::module]
mod graphql {
#[derive(GraphQLObject)]
struct MyType {
}
#[juniper::object]
impl MyType {
fn extra_resolver() -> bool { true }
....
}
}
Hi Christian,
That's great to hear there is interest in this. At the moment my macro
writing skills are not up to the task, but if that changes, I'll try to do
it. Incidentally, I did also try to write another unrelated macro, but
noticed that it doesn't work when called from within the graphql_object!()
call.
Cheers,
Henry
On Mon, Jun 24, 2019 at 7:38 PM Christian Legnitto notifications@github.com
wrote:
I don't believe there is. Happy to review a PR!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/graphql-rust/juniper/issues/377?email_source=notifications&email_token=ABI3OFWVJM3IAKV7RFFPCGLP4GAI3A5CNFSM4H2K3QJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYOZNJY#issuecomment-505255591,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABI3OFUKRLQ3H6DG6HU65Z3P4GAI3ANCNFSM4H2K3QJQ
.
@theduke I like the module idea. Can we leverage the new(ish) "extends" keyword here?
Let's track this in #182 .
Most helpful comment
This is much wanted and there are multiple paths to this.
One option, merging definitions, is discussed in #182 .
My personally preferred way forward would be to apply a proc macro to a whole module to make this easy.
This is currently only possible on nightly with the
proc_macro_hygienefeature.I'd want us to have code like this and make it just work: