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

Add support for 'input_name_suffix_ in '#[graphql(...)]' (fixes #1117) #1119

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ClementNerma
Copy link

@ClementNerma ClementNerma commented Oct 24, 2022

Support for SimpleObject, InputObject, Union and Oneofobject.

Also improves refactoring:

// This:
#[derive(SimpleObject, InputObject)]
#[graphql(input_name = "TestInput")]
struct Test { /* ... */ }

// Becomes:
#[derive(SimpleObject, InputObject)]
#[graphql(input_name_suffix = "Input")]
struct Test { /* ... */ }

So when Test is renamed, the input name will be changed automatically.

@sunli829
Copy link
Collaborator

Thanks for the PR, but I don't think the input_name_suffix attribute simplifies anything, so I won't merge this. 🙂

@ClementNerma
Copy link
Author

Thanks for the PR, but I don't think the input_name_suffix attribute simplifies anything, so I won't merge this. 🙂

I strongly disagree, it enables several things:

  1. You don't have to play with concatenation in macros
  2. This avoids relying on an external dependency just for concatenation
  3. When renaming a struct, the input type will be renamed automatically as well

I think this simplifies things a lot and I'd even argue that having this argument is more important than input_name itself as it serves more use cases :)

@teenjuna
Copy link

@sunli829 are you sure? I can see why someone may want this, and the added code is quite simple. Maybe reconsider?

@sunli829 sunli829 force-pushed the master branch 3 times, most recently from 7eabbe3 to 912feb3 Compare November 11, 2022 15:53
@bramvanneerven
Copy link
Contributor

  1. When renaming a struct, the input type will be renamed automatically as well

I like the change mainly because of this.

When both input_name and input_name_suffix are used at the same time (for some reason?), I think input_name should override or an error should be thrown though.

@ClementNerma
Copy link
Author

  1. When renaming a struct, the input type will be renamed automatically as well

I like the change mainly because of this.

When both input_name and input_name_suffix are used at the same time (for some reason?), I think input_name should override or an error should be thrown though.

Not necessarily, for instance you could want to give a suffix to all of your types even with a custom name.

@ClementNerma
Copy link
Author

@sunli829 hi, I've rebased the PR to make it work with the latest 5.x versions. May you please reconsider the purpose of this add? I think it would be really useful for some people (like me) and it doesn't hurt to add it in the end for people that don't want to use it.

In my current project I constantly use my fork to have this feature which is essential.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants