Open nrbnlulu opened 11 months ago
That's actually a general strawberry issue. Subscriptions doesn't support field extensions currently :(
Just ran some tests, I think it is supported with raw strawberry. Based on what do you say that?
i.e
class FooExt(FieldExtension):
async def resolve_async(
self, next_: AsyncExtensionResolver, source: Any, info: Info, **kwargs: Any
) -> Any:
async for res in next_(source, info, **kwargs):
yield res + 20
@strawberry.type
class Subscription:
@strawberry.subscription(extensions=[FooExt()])
async def subscribe_requires_auth(self) -> AsyncGenerator[int, None]:
for i in range(5):
yield i
await asyncio.sleep(0.01)
Hrm, I remember it not being supported, but maybe that changed? =P
Will take a look at the PR you opened
I think you are right resolve_async
must return a coroutine and for subscriptions you need to return an async generator.
I'll need to dig dipper to tell.
I think you are right
resolve_async
must return a coroutine and for subscriptions you need to return an async generator. I'll need to dig dipper to tell.
The extension can probably check the "before" permissions (i.e. the global and root permissions), but the "after" ones (i.e. retval) are more complicated because there isn't a single return value for those.
On Channels requests the context is a
dict
so you'll get anAttributeError
. https://github.com/strawberry-graphql/strawberry-graphql-django/blob/3a3a66e236acbc54ad7079ecfa2b92508f3ad60c/strawberry_django/permissions.py#L330Upvote & Fund