Warm tip: This article is reproduced from serverfault.com, please click

How to send different subscription response based on condition in GraphQL (NestJS)?

发布于 2020-12-16 19:02:25

I would like to send to clients different subscription response, based on some condition. withFilter filter and send response only when condition is met. I want to send two different response based on some condition - map response, based on condition. Is there any withMap or something like that?

Questioner
vicodin
Viewed
0
Jay McDoniel 2020-12-17 05:12:22

Looks like you could use the resolve property and map the rsponse from within that.

Example from the docs:

@Subscription(returns => Comment, {
  resolve(this: AuthorResolver, value) {
    // "this" refers to an instance of "AuthorResolver"
    return value;
  }
})
commentAdded() {
  return pubSub.asyncIterator('commentAdded');
}