mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-02-20 05:20:36 +03:00
handle async serlizer mutations
This commit is contained in:
parent
66938e9e29
commit
1b2d5e02e4
|
@ -2,6 +2,8 @@ from collections import OrderedDict
|
|||
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import serializers
|
||||
from asyncio import get_running_loop
|
||||
from asgiref.sync import sync_to_async
|
||||
|
||||
import graphene
|
||||
from graphene.relay.mutation import ClientIDMutation
|
||||
|
@ -152,6 +154,19 @@ class SerializerMutation(ClientIDMutation):
|
|||
kwargs = cls.get_serializer_kwargs(root, info, **input)
|
||||
serializer = cls._meta.serializer_class(**kwargs)
|
||||
|
||||
try:
|
||||
get_running_loop()
|
||||
except RuntimeError:
|
||||
pass
|
||||
else:
|
||||
async def perform_mutate_async():
|
||||
if await sync_to_async(serializer.is_valid)():
|
||||
return await sync_to_async(cls.perform_mutate)(serializer, info)
|
||||
else:
|
||||
errors = ErrorType.from_errors(serializer.errors)
|
||||
return cls(errors=errors)
|
||||
return perform_mutate_async()
|
||||
|
||||
if serializer.is_valid():
|
||||
return cls.perform_mutate(serializer, info)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user