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

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=100
uv run coverage report --show-missing

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 .

Build

uv lock
uv build

Updating Version:

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

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.4.0.tar.gz (169.0 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.4.0-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_graphene_filters-0.4.0.tar.gz
  • Upload date:
  • Size: 169.0 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.4.0.tar.gz
Algorithm Hash digest
SHA256 3dcdbfc73c5d3d39026ef27e5234d60db697006b777cd0f94963704f808e1243
MD5 5834eb1ee741481ee04c5ce7b31592e3
BLAKE2b-256 03dfa8a8b647da3d23aa96f7f74a1ec7225b6ad2402cc0b2a5464498a4732f7d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_graphene_filters-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 40.3 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f48003f7c08a4b95215fc3ce972ed9e13ce3e6f928944d2bf5572a18d67d2660
MD5 b24454bd9d4633081dc430d13b9ea66a
BLAKE2b-256 24b723fac33eb4c3c4caa70c85c5cfc44641b43ad7bccb98236a41116a87b363

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