Skip to main content

A collection of custom extensions for Django GraphQL

Project description

Pypi Build Status Codecov Codacy

A collection of custom extensions for Django GraphQL


  • Python ≥ 3.6
  • Django ≥ 2.0
  • Graphene-django ≥ 3.0.0b1


Install last stable version from Pypi.

pip install django-graphql-extensions


  • @login_required
  • @staff_member_required
  • @superuser_required
  • @permission_required
  • @user_passes_test

See the documentation to know the full list of decorators.

from django.contrib.auth import get_user_model

import graphene
from graphql_extensions.decorators import (
    login_required, staff_member_required,

class Query(graphene.ObjectType):
    viewer = graphene.Field(UserType)
    users = graphene.List(UserType)

    def resolve_viewer(self, info, **kwargs):
        return info.context.user

    def resolve_users(self, info, **kwargs):
        return get_user_model().objects.all()


Returning appropriate error responses and masking error messages sent to the client.

Configure your GraphQLView.

from django.urls import include, path

from graphql_extensions.views import GraphQLView

urlpatterns = [
    path('', GraphQLView.as_view(), name='index'),


from graphql_extensions import exceptions
  • exceptions.GraphQLError
  • exceptions.PermissionDenied
  • exceptions.ValidationError
  • exceptions.NotFound


  "errors": [
      "message": "You do not have permission to perform this action",
      "locations": [
          "line": 3,
          "column": 13
      "path": [
      "extensions": {
        "type": "PermissionDenied",
        "code": "permissionDenied",
        "timestamp": 1622783872,
        "data": {},
        "operation": "QUERY",
        "trace": [
          "  File \"site-packages/graphql/execution/\", line 617, in resolve_field\n    result = resolve_fn(source, info, **args)\n",
          "  File \"graphql_extensions/\", line 23, in wrapper\n    return func(info.context, *args, **kwargs)\n",
          "  File \"graphql_extensions/\", line 35, in wrapper\n    raise exc\n"
  "data": {
    "viewer": null

Writing tests

This package includes a subclass of unittest.TestCase SchemaTestCase and improve support for making GraphQL queries.

from django.contrib.auth import get_user_model

from graphql_extensions.test import SchemaTestCase

class UsersTests(SchemaTestCase):

    def test_create_user(self):
        query = '''
        mutation CreateUser($username: String!, $password: String!) {
          createUser(username: $username, password: $password) {
            user {

        response = self.client.execute(query, {
            'username': 'test',
            'password': 'dolphins',


    def test_viewer(self):
        user = get_user_model().objects.create_user(


        query = '''
          viewer {

        response = self.client.execute(query)
        data =['viewer']

        self.assertEqual(data['username'], user.username)


Custom Graphene types.

  • Email
  • Timestamp

Project details

Download files

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

Files for django-graphql-extensions, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size django_graphql_extensions-0.1.0-py2.py3-none-any.whl (10.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size django-graphql-extensions-0.1.0.tar.gz (9.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page