Automatically optimizes SQL queries in Graphene-Django schemas by using Django's prefetch_related and select_related based on the GraphQL query. Version 0.10.15, actively maintained, monthly releases.
pip install graphene-django-query-optimizerNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Define a type using OptimizedDjangoObjectType and add the middleware to Graphene settings. The resolver returns a queryset; optimization is automatic.
Ensure 'GRAPHENE' in settings.py includes: 'MIDDLEWARE': ['graphene_django_optimizer.GQLOptimizerMiddleware']
Use OptimizedDjangoObjectType for model types; for other fields, you may need manual optimization or use gql_optimizer.resolver_hints.
Test with complex queries; consider using .defer() or .only() explicitly if issues arise.
Upgrade Python to >=3.11 or pin version: pip install 'graphene-django-query-optimizer<0.10.0'