Skip to content

N+1 #33

Closed Locked Answered by MrThearMan
elyas-hedayat asked this question in Q&A
N+1 #33
Dec 18, 2023 · 4 comments · 3 replies
Discussion options

You must be logged in to vote

Ok, I had a crack at this, and the initial idea I had didn't work, but I came up with a much cleaner one which doesn't need any additional queries.

Essentially, you can now define a classmethod filter_queryset on the ObjectType, which the optimizer will find and call when optimizing, whether the object type is the top level model, or a child prefetched model.

class ExampleType(DjangoObjectType):
    @classmethod
    def filter_queryset(cls, queryset: QuerySet, info: GQLInfo) -> QuerySet:
        return queryset.filter(...)

Released this in 0.0.9

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by MrThearMan
Comment options

You must be logged in to vote
1 reply
@MrThearMan
Comment options

Comment options

You must be logged in to vote
2 replies
@MrThearMan
Comment options

@MrThearMan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants