strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
MIT License
391 stars 115 forks source link

Optimizer ignores custom type querysets #562

Open aprams opened 4 days ago

aprams commented 4 days ago

Hey there, We override the get_queryset method of one of our types, yet that doesn't seem to be respected. Specifically, when I debug through the code, that seems to happen in resolve_base_manager where the _prefetched_objects_cache just contains the full queryset.

Describe the Bug

Here is an example:

@strawberry_django.type(
    models.Department, filters=DepartmentFilter, order=DepartmentOrder
)
class DepartmentType:
    id: uuid.UUID
    users: List[UserType] = strawberry_django.field()

@strawberry_django.type(models.User, filters=UserFilter, order=UserOrder)
class UserType:
    id: uuid.UUID
    name: str
    @classmethod
    def get_queryset(cls, queryset, info, **kwargs):
        return queryset.exclude(name="myexcludeduser")

Using the code above, I just get all users returned and using the debugger, the get_queryset part is never actually run.

We could use a custom resolver on the DepartmentType, but we would actually like to apply that filtering everywhere and not repeat the resolver.

System Information

strawberry-graphql[cli]==0.235.0 strawberry-graphql-django==0.44.2

Additional Context

Upvote & Fund

Fund with Polar