mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-04 20:33:12 +03:00
cleanup middleware
This commit is contained in:
parent
930248f78d
commit
c27dd6c732
|
@ -86,24 +86,16 @@ class DjangoSyncRequiredMiddleware:
|
||||||
if isinstance(return_type, GraphQLNonNull):
|
if isinstance(return_type, GraphQLNonNull):
|
||||||
return_type = return_type.of_type
|
return_type = return_type.of_type
|
||||||
|
|
||||||
## Anytime the parent is a DjangoObject type
|
if any(
|
||||||
# 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(
|
hasattr(parent_type, "graphene_type")
|
||||||
parent_type.graphene_type._meta, "model"
|
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):
|
if is_sync_function(next):
|
||||||
return sync_to_async(next)(root, info, **args)
|
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)
|
return next(root, info, **args)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user