Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ptheofan/nestjs-subscription-filter-issue
https://github.com/ptheofan/nestjs-subscription-filter-issue
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ptheofan/nestjs-subscription-filter-issue
- Owner: ptheofan
- Created: 2023-10-21T07:30:04.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-21T14:08:20.000Z (about 1 year ago)
- Last Synced: 2023-10-22T08:26:37.464Z (about 1 year ago)
- Language: TypeScript
- Size: 108 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Code First Subscriptions in nestjs
==================================1. In the resolver function add the `@Subscription` decorator
```ts
@Subscription(() => Vote, {
nullable: true,
filter: (payload, variables: { id: string }) => {
console.log('FILTER:', payload, variables);
return payload.voteUpdate.id === variables.id;
},
})
```in the function add the `@Args` you want the schema to have which will become available via the `variables`.
```ts
voteUpdate(@Args('id') id: string) {
return pubSub.asyncIterator('voteUpdate');
}
```Get rid of the warning for unused variables by adding the following comment
```ts
// eslint-disable-next-line @typescript-eslint/no-unused-vars
```The final correct code looks like this
```ts
@Subscription(() => Vote, {
nullable: true,
filter: (payload, variables: { id: string }) => {
console.log('FILTER:', payload, variables);
return payload.voteUpdate.id === variables.id;
},
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
voteUpdate(@Args('id') id: string): AsyncIterator {
return pubSub.asyncIterator('voteUpdate');
}
```