1

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

# <django-project>/settings.py

...
from graphene_django.views import GraphQLView

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

1 回答 1

2

根据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'),
    ...,
]

覆盖默认值。不过还没有测试。

于 2020-01-28T13:02:54.313 回答