0

I am trying to filter the subscriptions to make sure each client only receives data they need. However, I get an error when I work with this implementation

/**
 * 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
      }
    ),
  },
}

Apollo studio shows this errorenter image description here

What am I doing wrong?

Sean
  • 360
  • 3
  • 17

1 Answers1

0

I cant remember what I did exactly, but what I have now that is working for me is this snippet. I am not using graphql-yoga though

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
      }
    ),
  },
}
Sean
  • 360
  • 3
  • 17