From c27dd6c732d5e1b923a67763ede6af5eef02a10c Mon Sep 17 00:00:00 2001 From: Josh Warwick Date: Tue, 16 May 2023 17:03:24 +0100 Subject: [PATCH] cleanup middleware --- graphene_django/debug/middleware.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/graphene_django/debug/middleware.py b/graphene_django/debug/middleware.py index 3e66a8f..1e7bcf6 100644 --- a/graphene_django/debug/middleware.py +++ b/graphene_django/debug/middleware.py @@ -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)