cleanup middleware

This commit is contained in:
Josh Warwick 2023-05-16 17:03:24 +01:00
parent 930248f78d
commit c27dd6c732

View File

@ -86,24 +86,16 @@ class DjangoSyncRequiredMiddleware:
if isinstance(return_type, GraphQLNonNull):
return_type = return_type.of_type
## Anytime the parent is a DjangoObject type
# and we're resolving a sync field, we need to wrap it in a sync_to_async
if hasattr(parent_type, "graphene_type") and hasattr(
parent_type.graphene_type._meta, "model"
if any(
[
hasattr(parent_type, "graphene_type")
and hasattr(parent_type.graphene_type._meta, "model"),
hasattr(return_type, "graphene_type")
and hasattr(return_type.graphene_type._meta, "model"),
info.parent_type.name == "Mutation",
]
):
if is_sync_function(next):
return sync_to_async(next)(root, info, **args)
## In addition, if we're resolving to a DjangoObject type
# we likely need to wrap it in a sync_to_async as well
if hasattr(return_type, "graphene_type") and hasattr(
return_type.graphene_type._meta, "model"
):
if is_sync_function(next):
return sync_to_async(next)(root, info, **args)
if info.parent_type.name == "Mutation":
if is_sync_function(next):
return sync_to_async(next)(root, info, **args)
return next(root, info, **args)