Closed taobojlen closed 6 months ago
Note: this is a draft PR! I am testing this out on our code, but I figured I'd open this draft so you're aware :)
Let me know once it is ready to be reviewed :)
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 88.63%. Comparing base (
ff50d0a
) to head (973c687
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
apologies for the delay here @bellini666 ! this is now ready for review :)
Description
The strawberry-django optimizer can automatically add
select_related
andonly
clauses to a queryset. However, it currently fails if you enable theonly
optimization while using querysets that already haveselect_related
s on them.We use strawberry at work, and have a model like:
This causes issues with the optimizer if you try to execute a graphQL query that doesn't include
foo
: you get errors likeField cannot be both deferred and traversed using select_related at the same time
. We've actually been running without theonly
optimization for a long time for this reason.This PR adds some code to the optimizer that inspects the queryset for any existing
select_related
s, and includes them in the.only()
call.Types of Changes
Issues Fixed or Closed by This PR
N/A, there's no issue for this, though it related to this old message in the Strawberry Discord.
Checklist