-
Notifications
You must be signed in to change notification settings - Fork 766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DjangoObjectType.fields ignores select_related #1375
Comments
I can confirm this is also happening for me using graphene-django 3.0.0 and graphene 3.2.1. Before the upgrade @lufte Were you ever able to find a more global fix? I can certainly explicitly add attributes to all of my types but it would be simpler to fix this in one spot. |
@grantmcconnaughey unfortunately no, I just added the fields explicitly and forgot all about it. |
Hi @firaskafri. I ran a quick test using my current project (I thought it would be faster than creating a minimal reproducible example, turned out that it isn't) but I still see the behavior. If you need a demo to properly reproduce the issue let me know and I can write one. |
@lufte looks like there was a typo in @firaskafri's comment above. Can you try again on 3.0.2, the latest release? (That's where the graphene-django/graphene_django/tests/test_fields.py Lines 509 to 649 in 72a3700
|
@sjdemartini Yes, that was it! I've re-tested with 3.0.2 and now I see no difference between using |
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 previousselect_related
, but the first case always executes an additional query ignoring theselect_related
.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 bothfields
and an explicit attribute likechild = graphene.NonNull('schema.ChildType')
, and count the queries using both strategies.The
select_related
field should be honored in both cases.Please tell us about your environment:
The text was updated successfully, but these errors were encountered: