You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Annotations and optimizations don't work on fields created with strawberry_django.auth.current_user()
With the following code:
@strawberry.type
class Query:
user: User = strawberry_django.node(extensions=[IsAuthenticated()])
current_user: User = strawberry_django.auth.current_user()
@strawberry_django.type(UserModel)
class User(Actor, relay.Node):
friend_count: int = strawberry_django.field(annotate=Count("friends"))
friend_count will work on the user field just fine, but attempting to access it on current_user and you get this error:
annotate support still have some issues, like this case
The issue here is similar: The current_user resolver will return a user instead of a queryset containing the user, meaning the optimizer can't "annotate" it anymore.
I'm going to try to see if we can change current_user to return a queryset instead to support those cases, but for now what you can do is to define your own custom resolver like this:
annotate support still have some issues, like this case
The issue here is similar: The current_user resolver will return a user instead of a queryset containing the user, meaning the optimizer can't "annotate" it anymore.
I'm going to try to see if we can change current_user to return a queryset instead to support those cases, but for now what you can do is to define your own custom resolver like this:
Describe the Bug
Annotations and optimizations don't work on fields created with
strawberry_django.auth.current_user()
With the following code:
friend_count
will work on theuser
field just fine, but attempting to access it oncurrent_user
and you get this error:It's not just annotations, it happens for all the optimizations too.
System Information
Additional Context
There is another similar issue here. They might be related.
Upvote & Fund
The text was updated successfully, but these errors were encountered: