订阅时出现石墨烯返回NoneType错误



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

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

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

最新更新