strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
416 stars 121 forks source link

strawberry-graphql>=0.10.0 get_queryset not being called #281

Closed djstein closed 1 year ago

djstein commented 1 year ago

Hey team. Thanks a lot for all the hard work merging strawberry-django-plus into strawberry-graphql-django!

I've been going through the upgrade and I've found that no calls to get_queryset are working anymore from within relay.Node.

All instances of def get_queryset and async def get_queryset calls worked prior to the update. async and sync variants are still not being called. I have checked on the parent get_queryset call and my debuggers are also not being called nor am I seeing print statements.

I am seeing that filters based on the @strawberry_django.filters.filter and @strawberry_django.ordering.order are also being ignored when get_queryset is overwritten.

System Information

Additional Context

An example type would be here where I want to filter all AuthenticationTokens by the currently logged in user. types.py

import strawberry
import strawberry_django
from authentication.models import AuthenticationToken

@strawberry.django.type(AuthenticationToken, pagination=True)
class AuthenticationTokenReadOnly(strawberry.relay.Node):
    key_name: strawberry.auto
    key_slug: strawberry.auto
    created_at: strawberry.auto
    updated_at: strawberry.auto

    @classmethod
    async def get_queryset(cls, queryset, info):
        user = await info.context.request.auser()
        if user.is_anonymous:
            return queryset.none()
        return queryset.filter(user=user)

This would then be used in the schema such as: schema.py

import strawberry
import strawberry_django

@strawberry.type
class Query:
    authentication_tokens: strawberry_django.relay.ListConnectionWithTotalCount[
        AuthenticationTokenReadOnly
    ] = strawberry_django.connection()

Note: the request.auser() is a custom field based on an upstream of Django 4+ that has not been released. it adds an async accessible user. my entire Django app is async, no calls to sync are done.

Upvote & Fund

Fund with Polar

djstein commented 1 year ago

also, more than happy to jump on a call with anyone who wants to review this together. please reach out here or on my Twitter at @d_j_stein

bellini666 commented 1 year ago

@djstein I marked it as resolved on v0.10.3, but I just noticed that you are using an async get_queryset, which I'm not sure if it was even supported before (if it is not, I can take a look at supporting it)