Skip to content

django-graphex Documentation

Codecov PyPI - Python Version Django Versions PyPI PyPI - License Downloads Ruff

django-graphex builds on graphql-core and Pydantic to make Django GraphQL APIs easy, without Relay:

  1. Allow pagination and filtering on Queries
  2. Allow defining Pydantic-backed Mutations directly from Django models
  3. Allow using Directives on Queries and Fragments
  4. Optional GraphQL Subscriptions over Django Channels 4

Upgrading to 3.1

Start with the 3.0 β†’ 3.1 upgrade guide for the cache and permission changes, then read the published 3.1.0 changelog for the complete 24-finding traceability table.

Subscription Support

GraphQL subscriptions now live here as the optional django-graphex[subscriptions] extra (built on Django Channels 4). The standalone graphene-django-subscriptions package is now a deprecated compatibility shim that re-exports from here.

Key Features

πŸ” Fields

  • DjangoObjectField - Single object queries with automatic ID filtering
  • DjangoFilterListField - List queries with filtering
  • DjangoFilterPaginateListField - List queries with filtering and pagination
  • DjangoListObjectField - Recommended for Queries

🧬 Types

  • DjangoListObjectType - Recommended for Types
  • DjangoInputObjectType - Input types for mutations
  • DjangoModelType - Recommended for quick setup

⚑ Mutations

  • DjangoModelMutation - Recommended for Mutations

πŸ“„ Pagination

  • LimitOffsetGraphqlPagination - Offset-based pagination
  • PageGraphqlPagination - Page-based pagination
  • CursorGraphqlPagination - Keyset (cursor) pagination with pageInfo

🎯 Directives

  • String formatting - Case transformation, encoding, manipulation
  • Number formatting - Currency, mathematical operations
  • Date formatting - Custom date formats with python-dateutil
  • List operations - Shuffle, sample operations

Quick Example

Basic Usage
from django.contrib.auth import get_user_model
from django.urls import path
from django_graphex.fields import DjangoObjectField
from django_graphex.core import ObjectType
from django_graphex.schema import DjangoGraphQLSchema
from django_graphex.types import DjangoObjectType
from django_graphex.views import AuthenticatedGraphQLView

User = get_user_model()

class UserType(DjangoObjectType):
    class Meta:
        model = User
        only_fields = ("id", "username", "first_name", "last_name")

class Query(ObjectType):
    user = DjangoObjectField(UserType)

schema = DjangoGraphQLSchema(query=Query)
urlpatterns = [
    path("graphql/", AuthenticatedGraphQLView.as_view(schema=schema)),
]

Disable response caching on this authenticated, session-aware path:

settings.py
DJANGO_GRAPHEX = {"CACHE_ACTIVE": False}

The account example is intentionally read-only. Registration belongs in a separate mutation that accepts only ordinary account data and calls User.objects.create_user(username=..., password=...); never expose staff, superuser, group or permission inputs. The Quick Start provides the executable version. Use generated CRUD for ordinary application models.

Getting Started

Ready to dive in? Check out our Installation Guide to get started, or jump straight to the Quick Start for a hands-on tutorial.

Community & Support

License

django-graphex is open source under the MIT License β€” free to use, modify and distribute, provided the original copyright notice (Β© Ernesto PΓ©rez Amigo) is preserved in all copies.