Skip to content

Commit a111ad3

Browse files
committed
Resolve DjangoObjectType getNode when in an async context
1 parent 0beb338 commit a111ad3

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

examples/cookbook/cookbook/urls.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from django.conf.urls import url
1+
from django.urls import re_path
22
from django.contrib import admin
33

44
from graphene_django.views import GraphQLView
55

6-
76
urlpatterns = [
8-
url(r"^admin/", admin.site.urls),
9-
url(r"^graphql$", GraphQLView.as_view(graphiql=True)),
7+
re_path(r"^admin/", admin.site.urls),
8+
re_path(r"^graphql$", GraphQLView.as_view(graphiql=True)),
109
]

graphene_django/types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@ def get_queryset(cls, queryset, info):
288288
def get_node(cls, info, id):
289289
queryset = cls.get_queryset(cls._meta.model.objects, info)
290290
try:
291+
try:
292+
import asyncio
293+
asyncio.get_running_loop()
294+
except RuntimeError:
295+
pass
296+
else:
297+
return queryset.aget(pk=id)
298+
291299
return queryset.get(pk=id)
292300
except cls._meta.model.DoesNotExist:
293301
return None

0 commit comments

Comments
 (0)