question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolver instance (this) is not available in subscription filter/resolver methods

See original GitHub issue

I’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 @Subscriptiondecorator. 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:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilmysliwieccommented, Oct 10, 2019

Please, provide a minimal repository which reproduces your issue.

0reactions
lock[bot]commented, Apr 25, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found