问题描述
我有一个apolloServer graphql应用程序,并将订阅与RedisPubSub一起使用。有没有办法让我获得特定的订阅,并找出所有连接的客户端以及它们使用的arg?例如,有没有办法让我说“给我所有actionComplete订阅,然后从中给我每个连接的客户端的actionId”?
还有,我是否可以挂接到SubscriptionServer的'onOperation'和'onOperationComplete'生命周期事件?我使用server.installSubscriptionHandlers(httpServer)
这是我的订阅定义:
export const actionComplete = subscriptionField('actionComplete',{
type: ActionCompleteResponse,description:
'A subscription that notifies when the action is complete.',args: {
actionId: stringArg({
description: 'The id that corresponds to the action',nullable: false
})
},subscribe: withFilter(
(_root,_args,{ pubSub }) => pubSub.asyncIterator(['ACTION_COMPLETE']),(payload,args) => {
return payload.id === args.actionId
}
),resolve: payload => {
return payload
}
})
我创建服务器的方式如下:
const server = new ApolloServer({... (ommitting the details here) ... })
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
server.applyMiddleware({ app })
const httpServer = createServer(app)
server.installSubscriptionHandlers(httpServer)
httpServer.listen({ port },() =>
console.log(`Server ready at http://localhost:${port}/graphql`)
)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)