0
公布的对象,我使用与GraphQL订阅和订阅运输-WS的Express服务器。GraphQL-订阅:如何获得认购解析器
我已经设置了一个给定信道的订阅:
...
const subscriptionManager = new SubscriptionManager({
schema: executableSchema,
pubsub: pubsub,
setupFunctions: {
testRunChanged: (options, args) => {
return {
testRunChangedChannel: {
filter: (testRun) => {
return testRun.id === args.testRunId;
}
},
};
},
},
});
...
收到突变后的过程被启动,其中试运行的数据库条目是在服务器上更新等结束了。现在,当数据库操作的更新承诺通过时,应该通知客户端。
使用从发布订阅订阅管理发布功能,获取有关更新的测试运行的信息:
...
RunningTestDbService.setToFinished(testRun).then(updatedTestRun => {
pubsub.publish("testRunChangedChannel", updatedTestRun);
})
...
的订阅管理器后置过滤器的订阅取决于公布testRun和订阅testRunId调用订阅解析器函数。要更新客户端,我必须再次获取更新的测试运行。
我怎样才能得到订购解析函数内公布的试运行对象?
认购和解析器是这样的:
...
`testRunChanged(testRunId: ID!): TestRun!`
...
Subscription: {
testRunChanged(_, { testRunId }) {
// need to fetch the test run from database again
return TestRunDbService.getTestRunWith(testRunId);
},
},
...