如何调试 Django 后端的 GraphQL 订阅?

How can I debug GraphQL subscriptions of a Django backend?

我想将 GraphQL 订阅添加到后端 GraphQL API。我可以使用 graphene_django 内置 GraphiQL 调试订阅吗?

# <django-project>/settings.py

...
from graphene_django.views import GraphQLView

urlpatterns = [
    ...,
    url(r'^graphql$', GraphQLView.as_view(graphiql=True)),
    ...,
]

根据 graphene-subscriptions/issues/1 看来可以创建自定义 GraphQLCustomCoreBackend

class GraphQLCustomCoreBackend(GraphQLCoreBackend):
    def __init__(self, executor=None):
        # type: (Optional[Any]) -> None
        super().__init__(executor)
        self.execute_params['allow_subscriptions'] = True

并将其包含在

# <django-project>/urls.py

url_paths = [
    ...,
    path('graphql/', csrf_exempt(CustomGraphQLView.as_view(graphiql=True, backend=GraphQLCustomCoreBackend())), name='graphql'),
    ...,
]

覆盖默认值。但是还没有测试。