Description
I want to rename the type of an enum used for input in my API while keeping the values the same, but I need to make sure it doesn't break backwards compatibility for old clients. I tried using a graphene.Union
of the old and new enums as below, but that throws an error.
class OldStatus(graphene.Enum): # DEPRECATED NAME
VAL = 'VAL'
class NewStatus(graphene.Enum):
VAL = 'VAL'
class BackwardsCompatibleNewStatus(graphene.Union):
class Meta:
types = (OldStatus, NewStatus)
Is there a way to union 2 enum types so that I can allow the API to accept both types while the client is migrated? Or, is there a way to rewrite the requests as the come in to graphene so that whenever it sees OldStatus
it replaces it with NewStatus
so everything keeps working? Or alias OldStatus
to NewStatus
somehow? The issue is that requests come in looking like:
mutation mutateStuff($status: OldStatus) {
mutateStuff(status: $status) {
...
}
}
So even though OldStatus
and NewStatus
are identical, graphene rejects the request because the name of the enum type is OldStatus
instead of NewStatus
.
In the meantime I've hacked around the issue by extending graphene.Schema
like below, but it'd be great if there was a less hacky way to accomplish this:
class AliasableSchema(graphene.Schema):
def get_type(self, name):
aliases = {
'OldStatus': 'NewStatus',
}
return super().get_type(aliases.get(name, name))