Skip to main content

Advanced auto related filters for Graphene Django

Project description

Graphene Logo Django Graphene Filters (Beta)

build pypi coveralls license changelog

This package contains Advanced auto related filters for graphene-django.

This package takes inspiration from:

Installation

# pip
pip install django-graphene-filters
# uv
uv add django-graphene-filters

Development Setup

# Install uv (if not already installed)
# https://docs.astral.sh/uv/getting-started/installation/

# Clone and install
git clone https://github.com/riodw/django-graphene-filters.git
cd django-graphene-filters
uv sync
uv sync --upgrade

Running

uv run python examples/cookbook/manage.py runserver

Seeding the example database

The cookbook example dynamically discovers all Faker providers at runtime and seeds the database accordingly. The command is idempotent — it ensures at least N objects exist per provider and only creates the shortfall.

# Ensure 5 objects per provider (default)
uv run python examples/cookbook/manage.py seed_data

# Ensure 50 objects per provider
uv run python examples/cookbook/manage.py seed_data 50

# Delete the first 10 objects (and their cascading values)
uv run python examples/cookbook/manage.py delete_data 10

# Delete all objects and values
uv run python examples/cookbook/manage.py delete_data all

# Wipe all four tables
uv run python examples/cookbook/manage.py delete_data everything

Test users

Create test users with individual Django view_* permissions for exercising get_queryset permission branches. Each set creates 6 users: 1 staff, 1 regular (no perms), and 4 per-model permission users. All share password admin. Superusers are never deleted.

# Create 1 set of test users (6 users)
uv run python examples/cookbook/manage.py create_users

# Create 3 sets (18 users)
uv run python examples/cookbook/manage.py create_users 3

# Delete all non-superusers
uv run python examples/cookbook/manage.py delete_users all

# Delete the first 5 non-superusers
uv run python examples/cookbook/manage.py delete_users 5

Testing

uv run coverage run -m pytest
uv run coverage report --fail-under=99
uv run coverage report --show-missing
# run on a single test file
uv run coverage run -m pytest tests/test_input_data_factories.py && uv run coverage report -m django_graphene_filters/input_data_factories.py
# Run Full Test Pipeline
https://github.com/riodw/django-graphene-filters/actions/workflows/django.yml

Formatting and Linting:

# pyproject.toml [tool.black]
uv run black .
# pyproject.toml [tool.ruff]
uv run ruff check --fix .

Updating Version:

  • pyproject.toml:4
  • django_graphene_filters/__init__.py:22
  • tests/test_django_graphene_filters.py:8

Build

uv lock
rm dist/*
uv build

Publish

uv publish --token PASSWORD

Updating:

# Show outdated packages
uv pip list --outdated

# Add a dev dependency
uv add --group dev <package>

# Remove the virtual environment
rm -rf .venv

Local usage

  1. go to the project you want to install the package
  2. add django-graphene-filters to your pyproject.toml dependencies
  3. point it at your local checkout:
# In your project's pyproject.toml
[tool.uv.sources]
django-graphene-filters = { path = "../django-graphene-filters", editable = true }

Then run:

uv sync

Permissions & Cascade Visibility

When a node's get_queryset hides rows (e.g. is_private=False for non-staff), FK fields pointing to hidden targets would normally cause "Cannot return null for non-nullable field" errors.

AdvancedDjangoObjectType solves this with sentinel nodes — redacted instances (pk=0) returned by get_node when the real row is hidden. Every node exposes an isRedacted: Boolean! field so clients can detect them.

Use apply_cascade_permissions inside get_queryset to proactively exclude rows whose FK targets are hidden:

from django_graphene_filters import AdvancedDjangoObjectType, apply_cascade_permissions

class ObjectNode(AdvancedDjangoObjectType):
    class Meta:
        model = Object
        interfaces = (Node,)
        fields = "__all__"

    @classmethod
    def get_queryset(cls, queryset, info):
        user = getattr(info.context, "user", None)
        if user and user.is_staff:
            return queryset
        return apply_cascade_permissions(cls, queryset.filter(is_private=False), info)

See the CHANGELOG for full details on the 0.4.0 permissions system.

Project details


Download files

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

Source Distribution

django_graphene_filters-0.7.3.tar.gz (243.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_graphene_filters-0.7.3-py3-none-any.whl (57.6 kB view details)

Uploaded Python 3

File details

Details for the file django_graphene_filters-0.7.3.tar.gz.

File metadata

  • Download URL: django_graphene_filters-0.7.3.tar.gz
  • Upload date:
  • Size: 243.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for django_graphene_filters-0.7.3.tar.gz
Algorithm Hash digest
SHA256 e0d7c4e83ac9d193ead9d64dd1a20dc930831c013c9d1a2f078534ab4541791b
MD5 fb272899921faf9ca530af9fbc0a9c0b
BLAKE2b-256 4fa15bad8bb7c9cfccc796377cf5c99ea5e8b670f57f7fac3f5b34c1a35c45d8

See more details on using hashes here.

File details

Details for the file django_graphene_filters-0.7.3-py3-none-any.whl.

File metadata

  • Download URL: django_graphene_filters-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 57.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for django_graphene_filters-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2abbb82f403a984b545d9d847c5c4d06cf8106eefee5d7a0ec68926d81e3b0a3
MD5 221ed14c31ada48f68ffa97c26121e89
BLAKE2b-256 f34937842ab39a8302048d517d00d10c62879ea481e863e4c635f5b613d817e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page