订阅时石墨烯返回NoneType错误

时间:2019-11-15 13:32:09

标签: django django-channels graphene-django

我正在尝试使用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},
        )

我不确定这是一个错误还是缺少某些东西。

1 个答案:

答案 0 :(得分:0)

我发现graphne的graphiql模板没有websocket支持,因此我不得不修改graphene/graphiql.html文件以合并websocket才能使其正常工作。