1---2name: strawberry-django3description: Strawberry-Django best practices — DjangoOptimizerExtension, DataLoader, type-hint-first schemas, CRUD mutations, filters/pagination/Relay, permission extensions, security hardening, async/subscriptions, and testing. Load when working with strawberry-graphql-django.4license: MIT5---67# Strawberry-Django89Strawberry-Django takes a very different shape from Graphene: it is type-hint-first, uses schema **extensions** (not middleware), ships a built-in query optimizer, generates CRUD mutations/filters/pagination from Django models, and is async-native. The references below focus on what is specific to Strawberry, not general GraphQL.1011## Query Optimization1213| Topic | Reference | Use for |14| --------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |15| DjangoOptimizerExtension | [references/optimizer.md](references/optimizer.md) | Automatic `only`/`select_related`/`prefetch_related`/`annotate` from AST, hint fields, custom resolver optimization, edge cases |16| N+1 and DataLoaders | [references/n-plus-one.md](references/n-plus-one.md) | When the optimizer cannot help, async DataLoader in `get_context`, priming, combining with the optimizer |1718## Schema Design1920| Topic | Reference | Use for |21| ----------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |22| Types and Fields | [references/types-and-fields.md](references/types-and-fields.md) | `@strawberry_django.type`, `auto`, computed fields, `get_queryset`, `model_property`, enum generation, field descriptions from `help_text` |23| Mutations | [references/mutations.md](references/mutations.md) | `mutations.create/update/delete`, `NodeInput`, partial inputs, `handle_django_errors`, custom mutations, transaction atomicity, batch operations |24| Filters, Pagination, Relay | [references/filters-pagination-relay.md](references/filters-pagination-relay.md) | `@strawberry_django.filter`, custom `filter_field`, `@strawberry_django.order`, offset vs `DjangoListConnection` vs `DjangoCursorConnection`, `relay.Node` and `GlobalID` |2526## Security2728| Topic | Reference | Use for |29| ---------------------- | --------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |30| Permissions & Security | [references/permissions-and-security.md](references/permissions-and-security.md) | `IsAuthenticated`/`IsStaff`/`HasPerm`/`HasRetvalPerm`/`HasSourcePerm`, django-guardian object-level perms, `DisableIntrospection`, `QueryDepthLimiter`, `MaxTokensLimiter`, `MaxAliasesLimiter`, error masking |3132## Async and Subscriptions3334| Topic | Reference | Use for |35| ------------------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |36| Async and Subscriptions | [references/async-and-subscriptions.md](references/async-and-subscriptions.md) | `AsyncGraphQLView`, `sync_to_async` ORM access, Channels + `AuthGraphQLProtocolTypeRouter`, broadcasting subscriptions, pitfalls mixing sync and async resolvers |3738## Testing3940| Topic | Reference | Use for |41| ------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- |42| Testing | [references/testing.md](references/testing.md) | `strawberry_django.test.client.TestClient`, `client.login()`, `assertNumQueries` for optimizer regressions, async tests, snapshot schema diffs |