我正在尝试过滤订阅,以确保每个客户端只接收他们需要的数据。但是,当我使用此实现时,会出现一个错误。
/**
* 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
}
),
},
}阿波罗演播室显示了这个错误

我做错了什么?
发布于 2022-04-05 04:11:57
我不记得我到底做了什么,但我现在拥有的是为我工作的片段。不过,我不使用图形瑜伽。
const { PubSub, withFilter } = require('graphql-subscriptions')
const { GraphQLID } = require('graphql')
const pubsub = new PubSub()
const Subscription = {
agentLocation: {
type: AgentLocationType,
args: {
id: { type: GraphQLID },
},
resolve: (payload) => {
return payload.agentLocation
},
subscribe: withFilter(
() => pubsub.asyncIterator('LOCATION_UPDATED'),
(payload, variables) => {
return payload.agentLocation.id === variables.id
}
),
},
}https://stackoverflow.com/questions/70990089
复制相似问题