mirumee / ariadne

Python library for implementing GraphQL servers using schema-first approach.
https://ariadnegraphql.org
BSD 3-Clause "New" or "Revised" License
2.19k stars 179 forks source link

convert_names_case inconsistent with numbers. #1190

Open mdp-chris opened 1 month ago

mdp-chris commented 1 month ago

if you have a field fooBar19 then setting convert_names_case to True will convert that to foo_bar_19. Awesome But if the name is foobar19 then it doesn't get converted. Not awesome.

The problem is that both convert_names_in_schema_args and convert_names_in_schema_input only convert if field_name.lower() == field_name is true. So it only does a conversion if there is an uppercase character. But the conversion will add underscores before and after numbers. But if there are no uppercase characters, then names with numbers won't be converted.

I'm not sure what the correct resolution here is. Either skip the uppercase check, and always convert, or check to see if it has uppercase or numbers.

DamianCzajkowski commented 1 week ago

Hi, from what I know, when transforming from camelCase to snake_case, numbers are typically not included in the conversion, at least that's how all the converters I'm familiar with work. However, considering that we already add an underscore before a number in camelCase, I believe we should standardize the solution by always adding an underscore before a number during name conversion.