【发布时间】:2022-04-05 12:11:57
【问题描述】:
我正在尝试过滤订阅以确保每个客户端只接收他们需要的数据。但是,当我使用此实现时出现错误
/**
* Relevant packages and their versions
* "apollo-server-core": "^3.6.2",
* "apollo-server-koa": "^3.6.2",
* "graphql": "^16.3.0",
* "graphql-request": "^3.7.0",
* "graphql-subscriptions": "^2.0.0",
*
*
*/
const Subscription = {
agentLocation: {
type: AgentLocationType,
args: {
id: { type: GraphQLID },
},
resolve: (payload) => {
console.log(payload, ' is the payload')
return payload.agentLocation
},
subscribe: withFilter(
() => pubsub.asyncIterator('LOCATION_UPDATED'),
(payload, variables) => {
return payload.agentLocation.id === variables.id
}
),
},
}
我做错了什么?
【问题讨论】:
-
我使用
withFilter遇到了完全相同的问题,但使用的是 graphql-yoga。你找到解决办法了吗? -
@Scott,检查我给出的答案是否有帮助
标签: graphql apollo-server graphql-subscriptions