Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename or union enum types #628

Closed
chanind opened this issue Dec 14, 2017 · 1 comment
Closed

Rename or union enum types #628

chanind opened this issue Dec 14, 2017 · 1 comment

Comments

@chanind
Copy link

chanind commented Dec 14, 2017

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))
@jkimbo
Copy link
Member

jkimbo commented Feb 25, 2018

@chanind Unions can only be used with ObjectTypes: http://facebook.github.io/graphql/October2016/#sec-Unions

So in your example the best thing to do would be to add a new input to the mutation and deprecate the old status input argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants