Description
Graphene offers a convenient method to convert a Python-Enum (PyEnum
) to a graphene-compatible enum (GEnum
) using the types.Enum.from_enum()
function.
However, this function creates a new type each time it is called, even when called with the same PyEnum
twice:
from enum import Enum as PyEnum
from graphene import Enum
class MyEnum(PyEnum):
A = 1
B = 2
C = 3
GEnum = Enum.from_enum(MyEnum)
GEnum2 = Enum.from_enum(MyEnum)
print(GEnum == GEnum2)
graphene-sqlalchemy
currently uses an enum registry to convert SQLAlchemy enums to corresponding graphene enums without duplication:
I propose that we backport this method to graphene
for use with all python Enum types. I don't see a use-case for having two converted enums referencing the same underlying enum. For backward compatibility, the old function could remain in code, or the use of the enum registry could be enabled/disabled using optional arguments.
This change would be helpful for the automatic conversion of python enums to graphene enums. It might prevent user confusion when two types with the same properties are created from an underlying enum.
Would work on a PR if this is desired. Let me know what you think!