This library adds extra functionalities to graphene-django to facilitate GraphQL use without Relay, allow paginations and filtering integration, and add extra directives.
Project description
This package adds some extra functionalities to graphene-django to facilitate the graphql use without Relay:
Allow pagination and filtering on Queries
Allow defining DjangoRestFramework serializers based on Mutations.
Allow using Directives on Queries and Fragments.
NOTE: Subscription support was moved to graphene-django-subscriptions
Requirements
Python: 3.12+ (3.13 and 3.14 supported)
Django: 4.0+ (4.2, 5.0, 5.1, 5.2, and 6.0 supported)
Graphene-Django: 3.2+
Quick Start
Installation
pip install graphene-django-extras
Basic Usage
from graphene_django_extras import DjangoListObjectType, DjangoSerializerMutation
class UserListType(DjangoListObjectType):
class Meta:
model = User
class UserMutation(DjangoSerializerMutation):
class Meta:
serializer_class = UserSerializer
Documentation
📚 Full Documentation: https://eamigo86.github.io/graphene-django-extras/
The complete documentation includes:
Installation Guide - Getting started
Quick Start - Basic setup and examples
Usage Guide - Detailed feature documentation
Directives - GraphQL directives for data formatting
API Reference - Complete API documentation
Changelog - Version history
Key Features
🔍 Fields
DjangoObjectField
DjangoFilterListField
DjangoFilterPaginateListField
DjangoListObjectField (Recommended)
🧬 Types
DjangoListObjectType (Recommended)
DjangoInputObjectType
DjangoSerializerType (Recommended)
⚡ Mutations
DjangoSerializerMutation (Recommended)
📄 Pagination
LimitOffsetGraphqlPagination
PageGraphqlPagination
🎯 Directives
String formatting (case, encoding, manipulation)
Number formatting (currency, math operations)
Date formatting (with python-dateutil)
List operations (shuffle, sample)
Configuration
You can configure global parameters for DjangoListObjectType classes in your settings.py:
GRAPHENE_DJANGO_EXTRAS = {
'DEFAULT_PAGINATION_CLASS': 'graphene_django_extras.paginations.LimitOffsetGraphqlPagination',
'DEFAULT_PAGE_SIZE': 20,
'MAX_PAGE_SIZE': 50,
'CACHE_ACTIVE': True,
'CACHE_TIMEOUT': 300 # seconds
}
Examples
Types Definition
from django.contrib.auth.models import User
from graphene_django_extras import DjangoListObjectType, DjangoSerializerType
from graphene_django_extras.paginations import LimitOffsetGraphqlPagination
class UserListType(DjangoListObjectType):
class Meta:
model = User
pagination = LimitOffsetGraphqlPagination()
filter_fields = {
"id": ("exact",),
"username": ("icontains", "iexact"),
"email": ("icontains", "iexact"),
}
Mutations Definition
from graphene_django_extras import DjangoSerializerMutation
from .serializers import UserSerializer
class UserMutation(DjangoSerializerMutation):
class Meta:
serializer_class = UserSerializer
Schema Definition
import graphene
from graphene_django_extras import DjangoObjectField, DjangoListObjectField
class Query(graphene.ObjectType):
users = DjangoListObjectField(UserListType)
user = DjangoObjectField(UserType)
class Mutation(graphene.ObjectType):
user_create = UserMutation.CreateField()
user_update = UserMutation.UpdateField()
user_delete = UserMutation.DeleteField()
schema = graphene.Schema(query=Query, mutation=Mutation)
Directives
Configure directives in your settings.py:
GRAPHENE = {
'MIDDLEWARE': [
'graphene_django_extras.ExtraGraphQLDirectiveMiddleware'
]
}
Usage example:
from graphene_django_extras import all_directives
schema = graphene.Schema(
query=Query,
mutation=Mutation,
directives=all_directives
)
Development
See our Development Guide for contributing guidelines.
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphene_django_extras-1.1.0.tar.gz.
File metadata
- Download URL: graphene_django_extras-1.1.0.tar.gz
- Upload date:
- Size: 36.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.12 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a35f598dec4406b426bdbae409034d1dd1d15605c9ffe61252fc29c62291519f
|
|
| MD5 |
2026f3b809fca61d22216620163f0868
|
|
| BLAKE2b-256 |
31facd812a9751f03640f22db6d1ad6cc15d9562da4ad9edc5a3a868f5f67bb5
|
File details
Details for the file graphene_django_extras-1.1.0-py3-none-any.whl.
File metadata
- Download URL: graphene_django_extras-1.1.0-py3-none-any.whl
- Upload date:
- Size: 44.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.12 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37315bbcb9f8d5181032fceb0586f1c97479bf8cf2ce00008d729f86c0ce3e07
|
|
| MD5 |
1368c154c6c39ac75f46399ab06916cc
|
|
| BLAKE2b-256 |
13c8d2514030726f850572ac1123a7b1a62770e00f0e97e0146b638cf29d1ed2
|