我有一个apolloserver graphql应用程序,并使用redispubsub订阅。有没有办法让我获得一个特定的订阅,并找出所有连接的客户端以及它们使用的参数?例如,有没有一种方法让我说“给我所有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`)
)
暂无答案!
目前还没有任何答案,快来回答吧!