improve async detection

This commit is contained in:
Josh Warwick 2023-05-09 22:58:15 +01:00
parent 791209f557
commit b69476f50f
2 changed files with 9 additions and 6 deletions

View File

@ -80,7 +80,9 @@ class DjangoSyncRequiredMiddleware:
if hasattr(parent_type, "graphene_type") and hasattr(
parent_type.graphene_type._meta, "model"
):
if not inspect.iscoroutinefunction(next):
if not inspect.iscoroutinefunction(next) and not inspect.isasyncgenfunction(
next
):
return sync_to_async(next)(root, info, **args)
## In addition, if we're resolving to a DjangoObject type
@ -88,7 +90,9 @@ class DjangoSyncRequiredMiddleware:
if hasattr(info.return_type, "graphene_type") and hasattr(
info.return_type.graphene_type._meta, "model"
):
if not info.is_awaitable(next):
if not inspect.iscoroutinefunction(next) and not inspect.isasyncgenfunction(
next
):
return sync_to_async(next)(root, info, **args)
return next(root, info, **args)

View File

@ -266,11 +266,10 @@ class DjangoConnectionField(ConnectionField):
iterable = await iterable
if iterable is None:
iterable = default_manager
## This could also be async
iterable = queryset_resolver(connection, iterable, info, args)
if info.is_awaitable(iterable):
iterable = await iterable
iterable = await sync_to_async(queryset_resolver)(
connection, iterable, info, args
)
return await sync_to_async(cls.resolve_connection)(
connection, args, iterable, max_limit=max_limit