-
Notifications
You must be signed in to change notification settings - Fork 820
Description
From http://docs.graphene-python.org/en/latest/execution/middleware/#example:
class AuthorizationMiddleware(object):
def resolve(self, next, root, info, **args):
if info.field_name == 'user':
return None
return next(root, info, **args)
Results in:
graphql.error.located_error.GraphQLLocatedError: resolve() missing 1 required positional argument: 'info'
It was only due to stumbling across #612 that I read this:
self not being a class instance in resolver 'methods'. I don't understand the architectural reasons why this can't be the case, but in Python an instance method (like the resolver methods) is expected to take a self first argument. The documentation says that this isn't the case with Graphene (which is unexpected), but it still calls the argument self in some cases which further confuses the issue. It is mentioned that these methods act like static methods, however it's unexpected that they aren't decorated with the
@staticmethod
decorator.
Which works:
class AuthorizationMiddleware(object):
def resolve(next, root, info, **args): # remove `self` as first param
if info.field_name == 'user':
return None
return next(root, info, **args)