graphene icon indicating copy to clipboard operation
graphene copied to clipboard

Create Either Argument decorator

Open Ian-Gabaraev opened this issue 4 years ago • 0 comments

Adds a decorator for handling situations when a query expects different arguments, but can only work with one. For instance:

A query named userByAttr can retrieve a user by their email or username, but not both. In this case, we define the query as follows:

from graphene.utils.decorators import either

@either(["username", "email"])
def resolve_user_by_attr(root, info, username=None, email=None):
        ...

If both arguments were passed, the query will raise TooManyArgs. If no expected argument was passed, the query will raise TooFewArgs

Ian-Gabaraev avatar Jun 20 '21 18:06 Ian-Gabaraev