ariadne-codegen
ariadne-codegen copied to clipboard
Fix enum name processing and add uppercase flag
This PR fixes the following bugs in the processing of enum names:
- the snake_case conversion function did not properly handle names with all uppercase eg
DESC_NULLS_LAST
was being converted intoLAST
- The enum generator was not calling
process_name
and so could not be hooked into the plugin customization pipeline - The enum generator did not respect the
convert_to_snake_case
option
This PR additionally adds the convert_enums_names_to_upper_snake_case
option to convert enum members to upper snake case like:
class SomeEnum(str, Enum):
FOO_BAR = "fooBar"
BAZ_BOW = "bazBow"
TO_STATUS = "toStatus"
I think this should be a core option rather than a plugin since it is more idiomatic. It also avoid enum name conflicts. For instance I had an enum with title
and name
as members, which conflicted with the built-in enum methods of the same name. I set the flag to default False for backwards compat.
@mat-sop @rafalp Let me know how you want me to break it up/structure it and I am happy to do it, I just needed to unblock a project.
Hello, apologies for delay in tacking this:
- Valid bug
- Enum names should go through
process_name
like other names.
Name conflict with Python keywords should be solved by appending the _
to final name, eg title_
This PR additionally adds the convert_enums_names_to_upper_snake_case option to convert enum members to upper snake case like
This is odd. Are you naming your GraphQL enum members like title
or name
instead of TITLE
and NAME
? If thats the case, its schema design issue and not something codegen should handle out of the box.