graphql-subscriptions icon indicating copy to clipboard operation
graphql-subscriptions copied to clipboard

Documentation for subscription resolver is misleading, suggested change

Open serle opened this issue 6 years ago • 1 comments

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.

serle avatar Aug 15 '18 13:08 serle

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.)

grantwwu avatar Sep 26 '18 20:09 grantwwu