-
Notifications
You must be signed in to change notification settings - Fork 434
Ability to create a snake_case field with the graphql_object! macro #201
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
Comments
Yup we should probably allow snake case fields even though they are against the convention. |
the source of the problem come from constructions like this $reg.field_convert::<$t, _, Self::Context>(
&$crate::to_camel_case(stringify!($name)), $info)
.deprecated($reason), https://github.com/graphql-rust/juniper/blob/master/juniper/src/macros/object.rs#L280 but being not fluent enough in rust, I don't know how to modify the macro to allow snake_case call instead of |
We will need to add some kind of attribute that disables to to_camel_case conversion. Maybe
|
I disagree that the current behavior should be changed. Juniper should keep the current behavior (names are coerced into camel case). Many new users create fields using While field names are always coerced to strings, and can be handled arbitrarily because of that, other parts of the Example: graphql_interface!(<'a> &'a Character: () as "Character" |&self| {
field myCamelCaseField() -> &str { self.id() }
field myOtherCamelCaseField() -> &str { self.id() }
instance_resolvers: |_| { // <--- not a field
&Human => self.as_human(),
&Droid => self.as_droid(),
}
}); As an additional note, the documentation currently uses To get the behavior you want, where schema names have non-standard GraphQL names, I'd instead recommend one of the patterns like: /// Option Foo
#[juniper(rename = "Appears_In")]
field appears_in() -> Vec<Episode> {
vec![Episode::NewHope, Episode::Jedi]
}
}
/// Option Bar
field appears_in() rename "Appears_In" -> Vec<Episode> {
vec![Episode::NewHope, Episode::Jedi]
}
} The first option has the benefit of being similar to serde's macros and so should be easier to learn and more familiar for the majority of rustaceans. Post Script 1. - If anything I'd strongly recommend removing support for non-snakecase field identifiers in the macros (or adding a lint, and have them |
@kestred no one suggested changing the default behaviour. All this is about is a option to disable the automatic camel case conversion if you really need it, which might be neccessary in some cases. |
@z0mbie42 Why not to query like this query {
human(id: "1234") {
id
appears_in: appearsIn
}
} and not introduce extra complexity in this crate? |
I think the current behaviour is fine and this is a pretty edge use case. renaming fields is a relatively small manual step if you really need it. |
Uh oh!
There was an error while loading. Please reload this page.
Hi, as I wasn't able to find any way to do this I open this issue:
a way to create snake_case fields should be provided.
Now we can create an object
which results in
but we can't create the following object due to the automatic field transformation
indeed
will results in
The text was updated successfully, but these errors were encountered: