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.
Since the subscription topic is set in the resolver, this would be hard to do without adding some configuration to the SchemaCRUDPlugin to cater for both use cases, right?
It seems to me like a potential security concern to pass the user ID as a subscription argument.
Maybe this should come from the context instead, and the server can set this in the context with
contextCreator
.cc @machi1990