Skip to content
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

Any way to auto-generate struct field resolvers, and also hand-write a custom one? #377

Closed
hrbigelow opened this issue Jun 21, 2019 · 5 comments
Labels
duplicate This issue or pull request already exists

Comments

@hrbigelow
Copy link

hrbigelow commented Jun 21, 2019

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.

@hrbigelow hrbigelow added the enhancement Improvement of existing features or bugfix label Jun 21, 2019
@LegNeato
Copy link
Member

I don't believe there is. Happy to review a PR!

@theduke
Copy link
Member

theduke commented Jun 25, 2019

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 } 
    ....
  }
}

@hrbigelow
Copy link
Author

hrbigelow commented Jun 26, 2019 via email

@LegNeato
Copy link
Member

@theduke I like the module idea. Can we leverage the new(ish) "extends" keyword here?

@theduke
Copy link
Member

theduke commented Jul 22, 2019

Let's track this in #182 .

@theduke theduke closed this as completed Jul 22, 2019
@theduke theduke added duplicate This issue or pull request already exists and removed enhancement Improvement of existing features or bugfix labels Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants