Resolve DjangoObjectType getNode when in an async context

This commit is contained in:
Josh Warwick 2023-03-30 19:32:36 +01:00
parent 8540a9332c
commit 6a5b28d09f
2 changed files with 11 additions and 4 deletions

View File

@ -1,10 +1,9 @@
from django.conf.urls import url
from django.urls import re_path
from django.contrib import admin
from graphene_django.views import GraphQLView
urlpatterns = [
url(r"^admin/", admin.site.urls),
url(r"^graphql$", GraphQLView.as_view(graphiql=True)),
re_path(r"^admin/", admin.site.urls),
re_path(r"^graphql$", GraphQLView.as_view(graphiql=True)),
]

View File

@ -288,6 +288,14 @@ class DjangoObjectType(ObjectType):
def get_node(cls, info, id):
queryset = cls.get_queryset(cls._meta.model.objects, info)
try:
try:
import asyncio
asyncio.get_running_loop()
except RuntimeError:
pass
else:
return queryset.aget(pk=id)
return queryset.get(pk=id)
except cls._meta.model.DoesNotExist:
return None