django-graphex Documentation¶
django-graphex builds on graphql-core and Pydantic to make Django GraphQL APIs easy, without Relay:
- Allow pagination and filtering on Queries
- Allow defining Pydantic-backed Mutations directly from Django models
- Allow using Directives on Queries and Fragments
- 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¶
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:
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¶
- GitHub Issues: Report a bug or request a feature
- PyPI Package: Install from PyPI
- Source Code: View on GitHub
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.