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

Automatically generate an input name with a suffix #1117

Open
ClementNerma opened this issue Oct 24, 2022 · 3 comments
Open

Automatically generate an input name with a suffix #1117

ClementNerma opened this issue Oct 24, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@ClementNerma
Copy link

Hi!

Would it be possible, when using both SimpleObject and InputObject on the same struct, or both Union and OneofObject, to make the input type automatically suffixed?

For instance, the following code:

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

Would now compile just like we wrote:

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

This would be immensely helpful in macros, especially as #[graphql(input_name = "...")] doesn't accept variables.

What do you think of this?

@sunli829
Copy link
Collaborator

This is definitely a good idea, but now that we already have an input_name attribute, adding an input_name_suffix attribute is a bit redundant. 🙂

@ClementNerma
Copy link
Author

This is definitely a good idea, but now that we already have an input_name attribute, adding an input_name_suffix attribute is a bit redundant. 🙂

The problem is that input_name can't be used in macros, due to the unability to concatenate strings in it.

If I do:

// ...
#[derive(SimpleObject, InputObject)]
#[graphql(input_name = concat!($name, "Input")]
pub struct $name {
  // ...
}

This will not compile as input_name is expecting a literal.

ClementNerma added a commit to ClementNerma/async-graphql-fork that referenced this issue Oct 24, 2022
@ClementNerma
Copy link
Author

I opened a PR to add this change, it ended up being really trivial: #1119

ClementNerma added a commit to ClementNerma/async-graphql-fork that referenced this issue Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants