You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
If I define an enum in my GraphQL schema, the generator creates the Enum subclass.
enum Status {
FIRST,
SECOND,
}
classStatus(Enum):
FIRST='FIRST'SECOND='SECOND'
That suggests that, in my Python code, the values should be converter to enums (via Status(value)) before they can be used as a field value of another type. That's fine when the field is non-nullable, but it starts to be awkward if the field is nullable. It basically means to recreate some of the validation checks that would be done automatically by pydantic.
Describe the solution you'd like
It would be great to be able to generate enums as subclasses of string via the --use-subclass-enum option. Then we could rely on pydantic to make sure that the values are valid and we could still use the enum class in the code and tests.
Describe alternatives you've considered
I tried to implement some helper functions as a workaround, but the suggested solution would produce a nicer code.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
If I define an enum in my GraphQL schema, the generator creates the
Enum
subclass.That suggests that, in my Python code, the values should be converter to enums (via
Status(value)
) before they can be used as a field value of another type. That's fine when the field is non-nullable, but it starts to be awkward if the field is nullable. It basically means to recreate some of the validation checks that would be done automatically bypydantic
.Describe the solution you'd like
It would be great to be able to generate enums as subclasses of string via the
--use-subclass-enum
option. Then we could rely onpydantic
to make sure that the values are valid and we could still use the enum class in the code and tests.Describe alternatives you've considered
I tried to implement some helper functions as a workaround, but the suggested solution would produce a nicer code.
The text was updated successfully, but these errors were encountered: