Closed fjsj closed 9 months ago
Would it make sense to split the annotate functionality for ModelProperty
, PrefetchInspector
and potentially types to a separate PR to avoid complexity creep here?
Regarding type support: The current field support supports also works on the type's queryset itself, correct? I can see how this might help for downstream tasks on the objects which are not explicit fields on the type.
Would it make sense to split the annotate functionality for ModelProperty, PrefetchInspector and potentially types to a separate PR to avoid complexity creep here?
IMHO, yes, as long as nothing that is expected to work in regular field actually doesn't.
Regarding type support: The current field support supports also works on the type's queryset itself, correct?
Yes, since type
already supports select_related
and prefetch_related
and pass this down to field
init, I guess we can just do the same here for annotate
.
The typing issue is due to pyright's yesterday release.
Going to merge this as is and fix the pyright issue myself, as it is not this PRs fault.
Description
Adds support for ORM annotations as fields. Looks like this:
And this:
There are some shortcomings and implementation details that I discuss more in-depth in PR comments. The main one is this only works if
DjangoOptimizerExtension
is enabled. Although that doesn't look like a major issue to me, because custom prefetches also have the same limitation (see the existingtests/test_optimizer.py::test_query_prefetch_with_callable
).~As of Sept 27 2023, this PR is still missing docs. I'll wait for feedback on implementation and field "syntax" before making the docs.~
I already added some tests, but perhaps we need more. I still also have to test manually a bit more.
--- EDIT: I found more missing stuff:
ModelProperty
(seestrawberry_django/descriptors.py
)annotate
support toPrefetchInspector
. (EDIT 2: seems this is already done viaquery.annotations
)annotate
support intype
? (seestrawberry_django/type.py
)Types of Changes
Issues Fixed or Closed by This PR
*
Checklist