Skip to content

Commit

Permalink
Update subscriptions.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec authored Sep 4, 2019
1 parent aac9231 commit 5b1dfbd
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions content/graphql/subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5b1dfbd

Please sign in to comment.