diff --git a/graphene/utils/decorators.py b/graphene/utils/decorators.py new file mode 100644 index 00000000..a478c5f6 --- /dev/null +++ b/graphene/utils/decorators.py @@ -0,0 +1,23 @@ +class TooManyArgs(Exception): + pass + + +class TooFewArgs(Exception): + pass + + +def either(expected): + def inner(func): + def wrapper(*args, **kwargs): + + arg_list = [kwargs.get(arg, None) is not None for arg in expected] + + if not any(arg_list): + raise TooFewArgs("Too few arguments, must be either of: " + ",".join(expected)) + + if all(arg_list): + raise TooManyArgs("Too many arguments, must be either of: " + ",".join(expected)) + + return func(*args, **kwargs) + return wrapper + return inner