如何调试Django后端的GraphQL订阅

如何调试Django后端的GraphQL订阅

本文介绍了如何调试Django后端的GraphQL订阅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to add GraphQL subscriptions to a backend GraphQL API. Can I debug subscriptions with the graphene_django builtin 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

According to graphene-subscriptions/issues/1 it seems like it's possible to create a custom 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'),
    ...,
]

覆盖默认值.但是尚未测试.

to override the default one. However not tested yet.

这篇关于如何调试Django后端的GraphQL订阅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 03:18