diff --git a/examples/cookbook/cookbook/urls.py b/examples/cookbook/cookbook/urls.py index 6f8a302..e9e69cd 100644 --- a/examples/cookbook/cookbook/urls.py +++ b/examples/cookbook/cookbook/urls.py @@ -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)), ] diff --git a/graphene_django/types.py b/graphene_django/types.py index a6e54af..068d268 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -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