You can use
middleware to affect the evaluation of fields in your schema.
A middleware is any object that responds to
Inside that method, it should either:
resolveto the next middleware to continue the evaluation; or
- Return a value to end the evaluation early.
resolve is invoked with several arguments:
nextrepresents the execution chain. Call
nextto continue evalution.
rootis the root value object passed throughout the query.
infois the resolver info.
argsis the hash of arguments passed to the field.
This middleware only continues evaluation if the
field_name is not
class AuthorizationMiddleware(object): def resolve(self, next, root, info, **args): if info.field_name == 'user': return None return next(root, info, **args)
And then execute it with:
result = schema.execute('THE QUERY', middleware=[AuthorizationMiddleware()])