Skip to main content

Graphene Field ACL

Project description


The motivation for this library is to simplify access control protection for Graphene Fields. A common approach to ACL protection is through the use of a reusable permissions validation decorator. The problem is this is cumbersome for Graphene Fields that use the standard resolver. You are forced to write an unnecessary resolver function just to annotate it with your permissions validator. The second cumbersome problem this library addresses is ACL role based resolvers. Depending on the users role you might want to perform different business logic in order to retrieve the data they requested for a Graphene Field.


$ pip install graphene-acl



The purpose of the classifier is to return a route key that will be used to determine which resolver function is used for resolving the field. The classifier function has access to all the arguments from the field resolver.


The purpose of the validator is to authorize access to the field. This validation will occurr before classification routing happens. If authorization validation is different per classification route then you should not use this validator to enforce authorization access. Instead you should authorize at the specific classifier resolver definition.


from graphene_acl import AclField
import graphene

def classifier(root, info, *args, **kwargs):
    if 'admin' in info.context.jwt.permissions:
        return 'admin'
    return None

def has_permissions(permissions):
    def validator(root, info, *args, **kwars):
        if (any([permission in info.context.jwt.permissions for permission in permissions])):
            return True
        raise AuthorizationError(f'Not authorized to query field {info.field_name}')

    return validator

class Foo(graphene.ObjectType):
    private_name = AclField(graphene.String, acl_classifier=classifier)
    restricted_name = AclField(graphene.String, acl_validator=has_permissions(['foo:name:read', 'admin']))

def resolve_private_name__admin(root, info, *args, **kwargs):

def resolve_private_name__default(root, info):
    # Alternatively, authorization handling could be done by an acl_validator
    raise Error('Not Authorized')

ACL Connection Fields

from graphene_django.filter import DjangoFilterConnectionField
from graphene_acl import acl_field_type

BarConnectionField = acl_field_type('BarConnectionField', DjangoFilterConnectionField)

class Foo(graphene.ObjectType):
    bar = BarConnectionField(MyNode, acl_permissions=has_permission('FOO'))


First time setup

  • Install Precommit hooks
  • brew install pre-commit && pre-commit install && pre-commit install --install-hooks
  • Install poetry:
  • curl -sSL | python
  • Install dependencies
  • poetry install

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
graphene-acl-1.0.4.tar.gz (5.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page