我正在关注DGS 订阅的文档,我没有收到任何错误,但也没有取回任何数据。
设置非常简单。在 schema.graphqls 文件中,我定义了订阅:
type Subscription {
ratings: Rating
}
type Rating {
stars: Int
}
Java代码如下:
@DgsComponent
public class SubscriptionDataFetcher {
@DgsData(parentType = "Subscription", field = "ratings")
public Publisher<Rating> ratings() {
return Flux.interval(Duration.ofSeconds(1)).map(t -> new Rating(4));
}
}
如果我现在将 websocket 连接到我的后端,它连接得很好,但没有按预期取回任何数据(不管我怎么做,也尝试使用 JavaScript,也连接得很好,但没有得到任何数据)。
例如使用 curl 连接(但使用 JavaScript 结果是一样的,连接但没有数据):
curl -o - --http1.1 \
--include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: localhost:8443" \
--header "Origin: https://localhost:8443" \
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
--header "Sec-WebSocket-Version: 13" \
https://localhost:8443/subscriptions\?query\=ewoicXVlcnkiOiAic3Vic2NyaXB0aW9uIHsgIHN0b2NrcyB7bmFtZX0gfSIKfQ==
我也尝试过通过 Graphiql 界面进行连接,但出现错误:
subscription {
ratings {
stars
}
}
错误信息:
{
"message": "response is not defined",
"stack": "ReferenceError: response is not defined\n at https://localhost:8443/graphiql:46:35\n at async Object.onRun (https://unpkg.com/graphiql/graphiql.min.js:1:540500)"
}
从链接中的示例中我不清楚的另一件事是如何实际管理订阅。因此,例如,假设我想在发生突变时发布通知。任何使用 Netflix DGS 框架如何完成的指针也将不胜感激。