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.
What is
object
from this example, the filter argument coming from the subscription like{userId: {eq: "enda"}}
? If that is the case, this will only work by using wildcards won't it? Thecreate
mutation resolver will publish the topic, and obviously this will not have the filter information available to it so it should use a wildcard in the topic path:Mutation
Subscription
need to set up a local OpenShift cluster to play with and learn about subscription topic wildcards.