graphql-subscriptions
graphql-subscriptions copied to clipboard
Documentation for subscription resolver is misleading, suggested change
Old Example
const SOMETHING_CHANGED_TOPIC = "something_changed"
export const resolvers = {
Subscription: {
somethingChanged: {
subscribe: () => pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC),
},
},
}
Replace it with:
export const resolvers = {
Subscription: {
somethingChanged: {
subscribe: (root, args, ctx, info) => pubsub.asyncIterator(args.topicName),
},
},
}
and mention that the subscription resolver gets called once per change to the subscriptions variables on the <Subscription/> component; and is responsible for returning an asyncIterator which in turn pushes messages out to subscribers.
Note that the pubsub topic name is no longer hard coded and can be some function of args, and ctx similar to all other resolvers.
I agree this would be a useful thing to document. Do you want to make a PR for it?
(Note: I also went ahead and fixed the Markdown in your issue.)