Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Coverage status Python versions Software license Black PyPI Downloads

This package adds some extra functionalities to graphene-django to facilitate the graphql use without Relay:

  1. Allow pagination and filtering on Queries

  2. Allow defining DjangoRestFramework serializers based on Mutations.

  3. 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.

Metadata

Release files for graphene-django-extras 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphene-django-extras 1.1.0
File Size Uploaded
graphene_django_extras-1.1.0.tar.gz 36.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for graphene-django-extras 1.1.0
File Interpreter ABI Platform
graphene_django_extras-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 80.9 kB

Release files / graphene_django_extras-1.1.0.tar.gz

Download URL graphene_django_extras-1.1.0.tar.gz
Size 36.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a35f598dec4406b426bdbae409034d1dd1d15605c9ffe61252fc29c62291519f
BLAKE2b-256 checksum
How to use checksums
31facd812a9751f03640f22db6d1ad6cc15d9562da4ad9edc5a3a868f5f67bb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.12 Linux/6.11.0-1018-azure

Release files / graphene_django_extras-1.1.0-py3-none-any.whl

Download URL graphene_django_extras-1.1.0-py3-none-any.whl
Size 44.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37315bbcb9f8d5181032fceb0586f1c97479bf8cf2ce00008d729f86c0ce3e07
BLAKE2b-256 checksum
How to use checksums
13c8d2514030726f850572ac1123a7b1a62770e00f0e97e0146b638cf29d1ed2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.12 Linux/6.11.0-1018-azure

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page