Description
- What is the current behavior?
The behavior for resolving a ForeignKey field of a DjangoObjectType is not the same when adding the field to fields
versus declaring the field explicitly as an attribute of the class. In the second case, an extra query won't be made if the field has been cached by a previous select_related
, but the first case always executes an additional query ignoring the select_related
.
- If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
a github repo, https://repl.it or similar (you can use this template as a starting point: https://repl.it/@jkimbo/Graphene-Django-Example).
Create two Models with a foreign key between them, and a schema in which you can list all the parent models with their respective children, using a select_related
call in the resolver. In the parent DjangoObjectType, try declaring the child model using both fields
and an explicit attribute like child = graphene.NonNull('schema.ChildType')
, and count the queries using both strategies.
- What is the expected behavior?
The select_related
field should be honored in both cases.
-
Please tell us about your environment:
- Version: 3.0.0
- Platform: Python 3.10.8, graphene==3.1.1