Resolver instance (this) is not available in subscription filter/resolver methods
See original GitHub issueI’m submitting a…
[ ] Regression
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I have:
(...)
export class CommentResolver {
constructor(
private readonly commentsDataLoader: CommentsDataLoader, // request-scoped
private readonly commentService: CommentService,
private readonly pubSub: PubSubService,
(...)
) {}
(...)
@Subscription(returns => CommentType, {
filter(this: CommentResolver, payload, variables) {
// filter by the correct parent
return this.commentService.belongsToParent({
commentId: payload.newComment,
parentId: variables.parentId,
});
},
resolve(this: CommentResolver, payload) {
return this.commentService.findOneById(payload.newComment);
},
})
async newComment(
@Args('parentId') parentId: string,
): Promise<AsyncIterator<CommentType>> {
return this.pubSub.asyncIterator<CommentEntity>('newComment');
}
(...)
(newComment
is only an ID string in the pubSub payload)
I am getting this response from the subscription:
{
"error": {
"name": "TypeError",
"message": "Cannot read property 'belongsToParent' of undefined"
}
}
Expected behavior
commentService
should be instantiated inside the filter method of the @Subscription
decorator. It is when used in a resolver method.
Minimal reproduction of the problem with instructions
ˆˆˆ
What is the motivation / use case for changing the behavior?
It’s not working as described in the docs.
Environment
Nest version: 6.8.2
"@nestjs/common": "6.8.2",
"@nestjs/core": "6.8.2",
"@nestjs/graphql": "^6.5.3",
"@nestjs/jwt": "^6.1.1",
"@nestjs/passport": "^6.1.0",
"@nestjs/platform-express": "6.8.2",
"@nestjs/typeorm": "^6.2.0",
For Tooling issues:
- Node version: 10.15.0
- Platform: Mac
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Enhanced subscription filtering - AWS AppSync
Filters defined in the subscription resolver (enhanced filtering) take precedence over filtering based only on subscription arguments (basic filtering). For ...
Read more >Subscriptions - Apollo GraphQL Docs
Subscriptions are long-lasting GraphQL read operations that can update their result whenever a particular server-side event occurs.
Read more >AWS AppSync Subscription Arguments - Stack Overflow
The subscription I've set up responds to comments in all channels instead. Is there any way to 'filter' the data coming through the...
Read more >Up and Running with GraphQL Using AWS AppSync
It can be seen that the resolver `operation` type is `Scan`, as it looks through the data source, and filters the data according...
Read more >Lessons learned: AWS AppSync Subscriptions
In this case the subscription doesn't get fired because the mutation is not requesting fieldA which is used for filtering in the subscription...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please, provide a minimal repository which reproduces your issue.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.