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.ruff]
uv run ruff format .
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-1.0.0.tar.gz (298.8 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-1.0.0-py3-none-any.whl (69.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_graphene_filters-1.0.0.tar.gz
  • Upload date:
  • Size: 298.8 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-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a0c11cbc9dfb6652a9e213b0552faa9066caaeacd8cf41c8e87f6a50e425d3ae
MD5 a3875b49f9352e8e4b8d3b7164a3dee9
BLAKE2b-256 55a3917e12a438ffc12fd8b97399802b640cbd8435a729ec580e2f03f7ec18c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_graphene_filters-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 69.7 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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18eb22e79cddd7b8f189a072ca5cd6034dd773e2f102851ec338a602c677529d
MD5 912d76133e582390b0318dbc4834df14
BLAKE2b-256 b9bf8db9e5916a8e7038db2646b354c528f29f96504018865fcb905087978884

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