strawberry-graphql

strawberry-django is a Django integration for Strawberry GraphQL that auto-generates GraphQL types, queries, and mutations from Django models, with filtering, pagination, and query optimization built in.

0.93.0
Published at
18d ago
504
Stars
24
Download
Synced at
8d ago

Latest release

0.93.0Oct 10, 2026, 02:28 PM
Downloads slow? Switch the source anytime above

README

Project Overview

strawberry-django is a Django extension of the Strawberry GraphQL framework, providing a complete GraphQL integration for Django projects. It generates type-safe GraphQL types, queries, mutations, and resolvers directly from Django models, with filtering, ordering, pagination, and permissions built in. Its query optimizer rewrites database queries automatically to avoid N+1 problems.

Item Value
Language Python
Base frameworks Django, Strawberry
Type GraphQL integration extension
License MIT

Turns Django models into GraphQL APIs via type annotations, halving the boilerplate.

Key Features

  • Automatic type generation: GraphQL types from Django models with full type safety
  • Advanced filtering: a filtering system with lookups like contains, exact, and in
  • Pagination: built-in offset and Relay cursor pagination
  • Ordering: sort results by any field with automatic ordering arguments
  • CRUD mutations: auto-generated create, update, and delete mutations with validation
  • Query optimizer: automatic select_related and prefetch_related to prevent N+1 queries
  • Auth and permissions: Django auth integration with flexible permission rules
  • Debug tooling: GraphiQL plus Django Debug Toolbar integration for query inspection

Target Audience

  • Django developers adopting GraphQL
  • Teams that need strongly typed API layers
  • Projects migrating to or coexisting with GraphQL from Django REST
  • Backend engineers focused on query performance

Quick Start

  1. Install the extension: pip install strawberry-graphql-django
  2. Declare GraphQL types with decorators
import strawberry_django
from strawberry import auto
from . import models

@strawberry_django.type(models.Fruit)
class Fruit:
    id: auto
    name: auto
  1. Define the query and build the schema with the optimizer
import strawberry
import strawberry_django
from strawberry_django.optimizer import DjangoOptimizerExtension

@strawberry.type
class Query:
    fruits: list[Fruit] = strawberry_django.field()

schema = strawberry.Schema(query=Query, extensions=[DjangoOptimizerExtension])
  1. Mount the view in urls.py: path('graphql/', AsyncGraphQLView.as_view(schema=schema))
  2. Open http://localhost:8000/graphql/ to debug in GraphiQL

Core Advantages

  • Less boilerplate: model-to-type mapping is automatic, shrinking API layer code
  • Better query performance: the optimizer trims SQL per requested field, avoiding N+1
  • Type safe: consistent with Strawberry types and friendly to mypy checks
  • Native to Django: reuses Django auth, permissions, and validation as-is

System Requirements

Item Requirement
Language Python 3
Framework Django
Dependency strawberry-graphql

Notes

  • Version pairing: keep versions in sync with the strawberry-graphql core package
  • Enable the optimizer explicitly: DjangoOptimizerExtension must be added to schema extensions to take effect

Release history

Sort