Closed rsomani95 closed 7 months ago
Err, turns out all I had to do was remove the custom segment_set
resolver.
Changing from this:
@strawberry_django.type(VideoAsset)
class VideoAssetType:
...
@strawberry.field
def segment_set(self, info) -> list["SegmentType"]:
segments = Segment.objects.filter(video_asset_id=self.id)
return segments
to this:
@strawberry_django.type(VideoAsset)
class VideoAssetType:
...
segment_set: list["SegmentType"]
fixed my issue, which is really cool and already a step up from what graphene-django-optimizer
offers, which is super cool.
Hello, thanks for all your work on
strawberry
. This looks like a really exciting project and I'm excited to try this as agraphene
replacement.I wanted to try strawberry to see if the optimizer would work for nested GraphQL queries. This does not seem to work out of the box; I wanted to ask if this is feasible with strawberry with some additional work on my end (by modifying how I'm setting up the resolvers, for example), or if this is simply not feasible given how I'm formulating the graphql query.
Here is a minimal reproduction of my setup:
I also set up the debug toolbar to see the SQL queries being run. Now, in the GraphIQL console, I'm trying this query:
And this is what the generated SQL looks like in the debug toolbar:
To take a step back, what I'm trying to do is fetch all my
VideoAssets
, and for each asset, fetch all theSegment
s with some/all of its attributes. Ideally, this should be two queries, something like:But this results in a N+1 query. Any ideas regarding how I could optimize this? Thanks!
Upvote & Fund