const SOMETHING_CHANGED_TOPIC = 'something_changed';
export const resolvers = {
Subscription: {
somethingChanged: {
subscribe: () => pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC),
},
},
}
pubsub.publish(SOMETHING_CHANGED_TOPIC, { somethingChanged: { id: "123" }})
See: https://github.com/apollographql/graphql-subscriptions
export const resolvers = {
Subscription: {
todoChanged(_parent, args, info): {
subscribe: () => pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC + "_" + hashFn(args.filter) || ""),
},
},
}
Publish:
pubsub.publish(hashFn(SOMETHING_CHANGED_TOPIC), { somethingChanged: { id: "123" }})
Ideally we need to have both approaches. hashFn is embeeded on compilation time which means we cannot handle this for cases like graphql-serve etc.
I guess a hashing function will take care of this and we could avoid situation where we'd use the raw "userId" or whatever as topics name.
I am wondering what happens if we do not have the "auth" info i.e userId?