mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-27 03:53:43 +03:00
Resolve DjangoObjectType getNode when in an async context
This commit is contained in:
parent
8540a9332c
commit
6a5b28d09f
|
@ -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)),
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user