strawberry-graphql / strawberry-django

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

Relay: Wrap resolve_model_node with django_resolver #402

Open SafaAlfulaij opened 1 year ago

SafaAlfulaij commented 1 year ago

Currently: https://github.com/strawberry-graphql/strawberry-graphql-django/blob/8f82b84141c182980b5001b4f0f562c787fe2dda/strawberry_django/relay.py#L395

Only the actual get/first methods are being wrapped for async safety.

There are cases where I need to access data not fetched yet in the custom get_queryset resolver (permissions, system settings, etc) defined up: https://github.com/strawberry-graphql/strawberry-graphql-django/blob/8f82b84141c182980b5001b4f0f562c787fe2dda/strawberry_django/relay.py#L380-L382

I went ahead and just wrapped the whole resolve_model_node resolver with django_resolver and didn't notice any difference.

I found this while trying to customize how a node is being resolved:

    node: relay.Node = relay.node()

Upvote & Fund

Fund with Polar

bellini666 commented 1 year ago

Hi @SafaAlfulaij ,

Indeed the current get_queryset is not async safe.

Maybe we could wrap everything from that line to the end inside django_resolver? If so, it would make sense to do the same for non relay access as well

SafaAlfulaij commented 1 year ago

@bellini666 Yeah, that should be sufficient.

bellini666 commented 1 year ago

@bellini666 Yeah, that should be sufficient.

@SafaAlfulaij do you want to try to open a PR for that? Otherwise I'll try to take a look at the end of this week