项目
在 GitHub 查看
strawberry-graphql/strawberry-django
关于
Strawberry GraphQL 的 Django 扩展
网站与应用开发可以做什么
- 🍓 Automatic Type Generation - Generate GraphQL types from Django models with full type safety
- 🔍 Advanced Filtering - Powerful filtering system with lookups (contains, exact, in, etc.)
- 📄 Pagination - Built-in offset and cursor-based (Relay) pagination
- 📊 Ordering - Sort results by any field with automatic ordering support
实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Strawberry GraphQL Django Integration
Strawberry GraphQL Django integration provides powerful tools to build GraphQL APIs with Django. Automatically generate GraphQL types, queries, mutations, and resolvers from your Django models with full type safety.
Installation
pip install strawberry-graphql-django
Features
- 🍓 Automatic Type Generation - Generate GraphQL types from Django models with full type safety
- 🔍 Advanced Filtering - Powerful filtering system with lookups (contains, exact, in, etc.)
- 📄 Pagination - Built-in offset and cursor-based (Relay) pagination
- 📊 Ordering - Sort results by any field with automatic ordering support
- 🔐 Authentication & Permissions - Django auth integration with flexible permission system
- ✨ CRUD Mutations - Auto-generated create, update, and delete mutations with validation
- ⚡ Query Optimizer - Automatic
select_relatedandprefetch_relatedto prevent N+1 queries - 🐍 Django Integration - Works with Django views (sync and async), forms, and validation
- 🐛 Debug Toolbar - GraphiQL integration with Django Debug Toolbar for query inspection
Quick Start
# models.py
from django.db import models
class Fruit(models.Model):
name = models.CharField(max_length=20)
color = models.ForeignKey("Color", on_delete=models.CASCADE, related_name="fruits")
class Color(models.Model):
name = models.CharField(max_length=20)
# types.py
import strawberry_django
from strawberry import auto
from . import models
@strawberry_django.type(models.Fruit)
class Fruit:
id: auto
name: auto
color: "Color"
@strawberry_django.type(models.Color)
class Color:
id: auto
name: auto
fruits: list[Fruit]
# schema.py
import strawberry
import strawberry_django
from strawberry_django.optimizer import DjangoOptimizerExtension
from .types import Fruit
@strawberry.type
class Query:
fruits: list[Fruit] = strawberry_django.field()
schema = strawberry.Schema(
query=Query,
extensions=[DjangoOptimizerExtension],
)
# urls.py
from django.urls import path
from strawberry.django.views import AsyncGraphQLView
from .schema import schema
urlpatterns = [
path("graphql/", AsyncGraphQLView.as_view(schema=schema)),
]
That's it! You now have a fully functional GraphQL API with:
- Automatic type inference from Django models
- Optimized database queries (no N+1 problems)
- Interactive GraphiQL interface at
/graphql/
Visit http://localhost:8000/graphql/ and try this query:
query {
fruits {
id
name
color {
name
}
}
}
Next Steps
Check out our comprehensive documentation:
- 📚 Getting Started Guide - Complete tutorial with examples
- 🎓 Example App - Full-featured e-commerce application
- 📖 Documentation - In-depth guides and API reference
- 💬 Discord Community - Get help and share your projects
Contributing
We welcome contributions! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated 😊
Quick Start:
git clone https://github.com/strawberry-graphql/strawberry-django
cd strawberry-django
pre-commit install
Then run tests with make test or make test-dist for parallel execution.
Community
- 💬 Discord - Join our community for help and discussions
- 🐛 GitHub Issues - Report bugs or request features
- 💡 GitHub Discussions - Ask questions and share ideas
License
This project is licensed under the MIT License.
探索相关项目
加载中…