【问题标题】:Graphiql does not display incoming data for subscriptionsGraphiql 不显示订阅的传入数据
【发布时间】:2020-11-12 00:51:15
【问题描述】:

我使用 graphql-java 实现了一个 graphql 服务器,它通过 websockets 提供订阅。

当我使用 websocket CL 工具 wscat 订阅时,一切都按预期工作。

这是服务器发布的数据的外观 (

$wscat -c "ws://localhost:9876/subscriptions"
> { "query" : "subscription{resourceSubscription(hasTypes : []){id}}" }
< {"type":"subscription_success"}   
< {"payload":{"data":{"resourceSubscription":{"id":"..."}}},"id":"1","type":"subscription_data"} (*1)

JSON 响应格式复制自 this 教程。我还尝试只发送没有“有效负载”包装器的“数据”块。

对于 graphiql,我使用 graphiql-spring-boot-starter v7.1.0 包。当我从 graphiql 发起订阅时,显示显示:

“您的订阅数据将在服务器发布后出现在此处!”

graphiql 将查询发送到 websocket 端点:

{"type":"connection_init","payload":{}}

{"id":"1","type":"start","payload":{"query":"subscription[...]","variables":null}}

在服务器上创建一个websocket,新的数据实际上是发布到已建立的websocket(如*1),但是,它没有显示在graphiql中,传入的数据完全被忽略提示仍然存在。

有人知道为什么会这样吗? JSON 响应是否格式不正确?

【问题讨论】:

    标签: graphql graphql-java graphiql


    【解决方案1】:

    必要的响应类型是: {"type": "data",...} 而不是 {"type" : "subscription_data",...}

    【讨论】:

      猜你喜欢
      • 2018-08-30
      • 1970-01-01
      • 2017-12-31
      • 2018-02-15
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      • 2017-10-07
      • 2014-12-26
      相关资源
      最近更新 更多