【问题标题】:Graphene Returning NoneType Error on Subscription石墨烯在订阅时返回 NoneType 错误
【发布时间】:2020-03-11 16:06:29
【问题描述】:

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

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

【问题讨论】:

    标签: django django-channels graphene-django


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-02-15
      • 2023-03-31
      • 2019-01-19
      • 2020-01-08
      • 2022-10-25
      • 2020-06-16
      • 2017-03-18
      • 1970-01-01
      • 2021-03-14
      相关资源
      最近更新 更多