0

我正在尝试使用channels_graphql_ws在 graphene-django 和频道上设置订阅。尝试运行订阅查询时出现以下错误:

An error occurred while resolving field Subscription.onNewComment
Traceback (most recent call last):
  File "/Users/noroozim/.pyenv/versions/nexus37/lib/python3.7/site-packages/graphql/execution/executor.py", line 450, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "/Users/noroozim/.pyenv/versions/nexus37/lib/python3.7/site-packages/graphql/execution/executors/sync.py", line 16, in execute
    return fn(*args, **kwargs)
  File "/Users/noroozim/.pyenv/versions/nexus37/lib/python3.7/site-packages/channels_graphql_ws/subscription.py", line 371, in _subscribe
    register_subscription = root.register_subscription
AttributeError: 'NoneType' object has no attribute 'register_subscription'

这是我的设置中的内容:


# /subscription.py/

class OnNewComment(channels_graphql_ws.Subscription):

    comment = Field(types.UserCommentNode)

    class Arguments:
        content_type = String(required=False)

    def subscribe(root, info, content_type):
        return [content_type] if content_type is not None else None

    def publish(self, info, content_type=None):
        new_comment_content_type = self["content_type"]
        new_comment = self["comment"]
        return OnNewComment(
            content_type=content_type, comment=new_comment
        )

    @classmethod
    def new_comment(cls, content_type, comment):
        cls.broadcast(
            # group=content_type,
            payload={"comment": comment},
        )

我不确定这是一个错误还是我遗漏了什么。

4

1 回答 1

1

我发现 graphne 的 graphiql 模板不附带 websocket 支持,我不得不修改我的graphene/graphiql.html文件以合并 websocket 以使其工作。

于 2019-11-15T18:06:51.377 回答