From 5b1dfbdff2025b200a535a0fe34ba2fbdf7f90e8 Mon Sep 17 00:00:00 2001 From: Kamil Mysliwiec Date: Wed, 4 Sep 2019 15:18:19 +0200 Subject: [PATCH] Update subscriptions.md --- content/graphql/subscriptions.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/content/graphql/subscriptions.md b/content/graphql/subscriptions.md index 58f3dec1cf..f78e440525 100644 --- a/content/graphql/subscriptions.md +++ b/content/graphql/subscriptions.md @@ -67,6 +67,33 @@ commentAdded() { } ``` +If you need to access some of the injected providers (e.g. use external service to validate the data), you can use the following construction: + +```typescript +@Subscription('commentAdded', { + resolve(this: AuthorResolver, value) { + // "this" refers to an instance of "AuthorResolver" + return value; + } +}) +commentAdded() { + return pubSub.asyncIterator('commentAdded'); +} +``` + +Likewise with filters. + +```typescript +@Subscription('commentAdded', { + filter(this: AuthorResolver, payload, variables) { + return payload.commentAdded.repositoryName === variables.repoFullName; + } +}) +commentAdded() { + return pubSub.asyncIterator('commentAdded'); +} +``` + #### Type definitions The last step is to update type definitions file.