Metadata-Version: 2.5
Name: django-strawberry-framework
Version: 0.0.15
Summary: A DRF-inspired Django integration framework for Strawberry GraphQL — filtering, ordering, mutations, and permissions
Project-URL: Homepage, https://github.com/unaxy/django-strawberry-framework
Project-URL: Repository, https://github.com/unaxy/django-strawberry-framework
Project-URL: Issues, https://github.com/unaxy/django-strawberry-framework/issues
Author: Unaxy
License-Expression: MIT
License-File: LICENSE
License-File: LICENSE.django
License-File: LICENSE.django-filter
License-File: LICENSE.django-graphiql-debug-toolbar
License-File: LICENSE.drf
License-File: LICENSE.postgresql
License-File: LICENSE.strawberry
License-File: LICENSE.strawberry-django
Keywords: django,drf,filters,framework,graphql,strawberry
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Classifier: Framework :: Django :: 6.1
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: django-filter>=25.2
Requires-Dist: django>=5.2.16
Requires-Dist: graphql-core<3.4,>=3.3.1
Requires-Dist: strawberry-graphql>=0.328.0
Requires-Dist: typing-extensions>=4.14.0
Description-Content-Type: text/markdown

# 🦄🍓 Django Strawberry Framework

[![build][build-image]][build-url] [![coveralls][coveralls-image]][coveralls-url] [![license][license-image]][license-url] [![changelog][changelog-image]][changelog-url]

GraphQL for Django the way DRF taught you: `class Meta`, not decorators. Built on [Strawberry](https://github.com/strawberry-graphql/strawberry), with a cooperative N+1 optimizer in the box.

```python
from django_strawberry_framework import DjangoType, finalize_django_types

class CategoryType(DjangoType):
    class Meta:
        model = Category
        fields = ("id", "name")

class ItemType(DjangoType):
    class Meta:
        model = Item
        fields = ("id", "name", "category")

finalize_django_types()
```

That's a complete model-backed type. Relations wire themselves. Mount `DjangoOptimizerExtension` on the schema and nested selections become `select_related` / `prefetch_related` / `only()` without you touching a resolver; without the extension the types still resolve, one lazy load at a time.

## Why this package exists

Django developers think in `class Meta`, querysets, DRF, and django-filter. Strawberry's existing Django integration thinks in decorators. This package keeps Strawberry as the engine and makes `class Meta` the configuration surface, so it feels like `graphene-django` evolved onto a modern engine rather than replaced by a different one.

## What you get

**Everything hangs off one `Meta`.** Fields, Relay, filtering, ordering, all on the type:

```python
class ItemType(DjangoType):
    class Meta:
        model = Item
        fields = ("id", "name", "category", "entries")
        interfaces = (relay.Node,)
        filterset_class = ItemFilter   # a django-filter-shaped FilterSet
        orderset_class = ItemOrder     # its OrderSet twin
```

**Root fields in one line.** `DjangoConnectionField` gives Relay cursor pagination with `filter:` / `orderBy:` derived from the type above; `DjangoListField` is the plain-list alternative.

```python
@strawberry.type
class Query:
    all_items: DjangoConnection[ItemType] = DjangoConnectionField(ItemType)
    all_categories: list[CategoryType] = DjangoListField(CategoryType)
```

Every `DjangoListField` publishes nullable `offset` and `limit` arguments, and conditionally
publishes `orderBy` when the target type declares `Meta.orderset_class`. The contract is strictly
ordered-offset paging rather than stable or repeatable pagination: `offset > 0` requires a visible
active order (via `orderBy` or a still-effective model `Meta.ordering`). The skip coordinate is
always bounded by `ResourcePolicy`, and the returned-row window is too unless the field opts into
`trusted_max_rows=True`, which lets its declared `max_rows` outrank the policy. Neither bound
injects a primary-key tiebreaker or `DISTINCT`.

**Three mutation flavors, one shape.** Write against the model, a Django form, or a DRF serializer. Inputs are generated, and all three report validation through the same `FieldError` envelope.

```python
class CreateItem(DjangoMutation):
    class Meta:
        model = Item
        operation = "create"

class CreateItemViaForm(DjangoModelFormMutation):
    class Meta:
        form_class = ItemModelForm
        operation = "create"

class CreateItemViaSerializer(SerializerMutation):
    class Meta:
        serializer_class = ItemSerializer
        operation = "create"
```

**And the rest:**

- **N+1 detection.** `DjangoOptimizerExtension(strictness="raise")` turns an unplanned lazy load into an error, so N+1 fails CI instead of surprising production.
- **Visibility that cascades.** Override `get_queryset` as you already do; `apply_cascade_permissions` pushes it across FK / OneToOne edges with zero extra queries.
- **Write permissions by default.** Generated mutations deny unless `DjangoModelPermission` (Django's `add` / `change` / `delete`) or your own class says yes.
- **Production defaults.** `DjangoSchema` masks unexpected exceptions behind a `correlationId` and enforces an execution resource budget (`ResourcePolicy`: document size, depth, aliases, list rows, uploads), `DjangoGraphQLView` / `AsyncDjangoGraphQLView` cap request bodies, and file output hides the server's filesystem path by default (`Meta.filesystem_path_fields` restores it per field). Build on plain Strawberry's schema or view and you keep none of these.
- **Session auth.** Opt-in `login` / `logout` / `register` mutations and a `current_user` query.
- **Tooling.** `TestClient` for in-process GraphQL tests, `DjangoDebugExtension` for SQL in `extensions.debug`, django-debug-toolbar integration, and a Channels router for subscriptions.

## Why it's fast

Five optimizer wins over `strawberry-graphql-django`:

- **Cross-request plan cache.** Every repeat of a cacheable query is a hit from a 256-entry LRU, so its selection tree is walked once, not on every request. Plans that bake in a request-scoped `get_queryset` are deliberately uncacheable and rebuild each time.
- **N+1 detection.** Upstream is preventive only; `strictness="raise"` is a detective mode.
- **FK-id join elision.** `{ relation { id } }` reads the FK column already on the parent, no join.
- **Class-creation-time metadata.** Frozen when the type is created, not memoized on first request.
- **Postgres lateral nested pagination.** Nested connection pages via `CROSS JOIN LATERAL`, paging per parent instead of numbering every child. Opt-in; measured 6.4× on dense count-free pages in one local run (the benchmark runs the `totalCount` shape separately).

Benchmarks: [`bench_plan_cache.py`][bench-plan-cache], [`bench_optimizer_walk.py`][bench-optimizer-walk], [`bench_nested_fetch.py`][bench-nested-fetch] (needs `FAKESHOP_PG_DSN`) and [`importtime_report.py`][importtime-report]. Numbers are from one machine; run them on yours.

## Is this for you?

| | `graphene-django` | `strawberry-graphql-django` | this package |
| --- | --- | --- | --- |
| Config surface | `class Meta` | decorators + annotations | `class Meta` |
| N+1 handling | no bundled optimizer | bundled optimizer | cooperative optimizer that respects your own `select_related` / `prefetch_related` |
| N+1 detection | none | preventive only | `strictness="raise"` |
| Filtering | django-filter `FilterSet` | `filter_type` decorated classes | `FilterSet` + `Meta.filterset_class` |
| Mutations | form and serializer classes | create / update / delete decorators | model, form, and serializer on one `Meta` |
| Unregistered relation target | silently dropped | `DjangoModelType { pk }` stub | raises at `finalize_django_types()`, naming the field |

Coming from `graphene-django`: your `Meta` stays, `DjangoObjectType` becomes `DjangoType`. Coming from `strawberry-graphql-django`: keep Strawberry, lose the decorators. Coming from DRF: `model` / `fields` / `exclude` / `filterset_class` mean what you think they mean.

## Status

**`0.0.15`, alpha, single maintainer.** Good for internal tools and prototypes, not production yet; public names are stable, edge cases are still hardening. The bundled `examples/fakeshop/` is a development fixture and refuses to run with `DEBUG` off. Going to production means your own project built against the [production security profile][readme-security].

## Get started → [`docs/README.md`][readme]

Install, quick start, reading and writing data, transport, and deployment all live in [`docs/README.md`][readme].

- [`docs/GLOSSARY.md`][glossary] — every shipped / planned / deferred capability, by anchor
- [`TODAY.md`][today] — what the example project can do right now
- [`GOAL.md`][goal] — where this is going
- [`KANBAN.md`][kanban] / [`BACKLOG.md`][backlog] — roadmap and post-`1.0.0` ideas
- [`docs/TREE.md`][tree] — package layout
- [`CHANGELOG.md`][changelog] · [`CONTRIBUTING.md`][contributing] · [`SECURITY.md`][security]

## Inspired by

- <https://pypi.org/project/django-graphene-filters/>
- <https://github.com/encode/django-rest-framework>
- <https://github.com/strawberry-graphql/strawberry-graphql-django>

<!-- LINK DEFINITIONS -->

<!-- Root -->
[backlog]: https://github.com/unaxy/django-strawberry-framework/blob/main/BACKLOG.md
[changelog]: https://github.com/unaxy/django-strawberry-framework/blob/main/CHANGELOG.md
[contributing]: https://github.com/unaxy/django-strawberry-framework/blob/main/CONTRIBUTING.md
[goal]: https://github.com/unaxy/django-strawberry-framework/blob/main/GOAL.md
[kanban]: https://github.com/unaxy/django-strawberry-framework/blob/main/KANBAN.md
[security]: https://github.com/unaxy/django-strawberry-framework/blob/main/SECURITY.md
[today]: https://github.com/unaxy/django-strawberry-framework/blob/main/TODAY.md

<!-- docs/ -->
[glossary]: https://github.com/unaxy/django-strawberry-framework/blob/main/docs/GLOSSARY.md
[readme]: https://github.com/unaxy/django-strawberry-framework/blob/main/docs/README.md
[readme-security]: https://github.com/unaxy/django-strawberry-framework/blob/main/docs/README.md#production-security-profile
[tree]: https://github.com/unaxy/django-strawberry-framework/blob/main/docs/TREE.md

<!-- docs/SPECS/ -->

<!-- docs/builder/ -->

<!-- django_strawberry_framework/ -->

<!-- tests/ -->

<!-- examples/ -->

<!-- scripts/ -->
[bench-nested-fetch]: https://github.com/unaxy/django-strawberry-framework/blob/main/scripts/bench_nested_fetch.py
[bench-optimizer-walk]: https://github.com/unaxy/django-strawberry-framework/blob/main/scripts/bench_optimizer_walk.py
[bench-plan-cache]: https://github.com/unaxy/django-strawberry-framework/blob/main/scripts/bench_plan_cache.py
[importtime-report]: https://github.com/unaxy/django-strawberry-framework/blob/main/scripts/importtime_report.py

<!-- .venv/ -->

<!-- External -->
[build-image]: https://github.com/unaxy/django-strawberry-framework/actions/workflows/django.yml/badge.svg
[build-url]: https://github.com/unaxy/django-strawberry-framework/actions
[coveralls-image]: https://coveralls.io/repos/github/unaxy/django-strawberry-framework/badge.svg?branch=main
[coveralls-url]: https://coveralls.io/github/unaxy/django-strawberry-framework?branch=main
[license-image]: https://img.shields.io/github/license/unaxy/django-strawberry-framework
[license-url]: https://github.com/unaxy/django-strawberry-framework/blob/main/LICENSE
[changelog-image]: https://img.shields.io/badge/changelog-CHANGELOG.md-blue
[changelog-url]: https://github.com/unaxy/django-strawberry-framework/blob/main/CHANGELOG.md
