Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2nd level interceptor not being invoked #615

Closed
vivekkatta opened this issue May 1, 2018 · 9 comments
Closed

2nd level interceptor not being invoked #615

vivekkatta opened this issue May 1, 2018 · 9 comments

Comments

@vivekkatta
Copy link

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

2nd level interceptor not being invoked.

I have a graphql resolver which has an intercepter A associated at the method level [UseInterceptors(A)]. The resolver method calls a service method which has another interceptor B associated [UseInterceptors(B)].

The interceptor A executes as expected but the interceptor B is not even invoked.

Expected behavior

Interceptor B and any other interceptor that is encountered in the lower layers must be invoked.

Minimal reproduction of the problem with instructions

https://github.com/vivekkatta/test-interceptor.git

What is the motivation / use case for changing the behavior?

Environment


Nest version: 5.0.0-RC.1

 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

@kamilmysliwiec
Copy link
Member

Hey @vivekkatta,
All decorators reflect the dynamic metadata on a chosen method/class, they don't override original methods at all, and thanks to that they might be easily unit-tested as normal classes/methods. This is an intended behavior and all of them will never affect a normal function execution because it could break too many existing codebases.

@vivekkatta
Copy link
Author

Hi @kamilmysliwiec, I think you mis-understood my question. I am not expecting original method to be overwritten at all. All I am trying to do is build 2 different logging interceptors. One for Graphql resolvers (where the logging is done in a specific way) another more generic logging interceptor for all other methods.

My issue is that the graphql logging interceptor is called but the interceptor decorating another method called by the resolver is not being invoked.

Please see the same repo I have created. The 'entering' and 'exiting' log statements for the TestService method is not coming through since the interceptor's 'intercept' method is not being called.

Hope this makes sense.

Thanks for looking into this!

Best,
Vivek

@kamilmysliwiec
Copy link
Member

This is exactly what I'm talking about @vivekkatta 🙂
This code (test.service.ts):

@UseInterceptors(VCInterceptor)
sum(): number {
  return 8;
}

won't call VCInterceptor because it is used inside the service.

@vivekkatta
Copy link
Author

Ok understood. Any suggestions how I can implement entry and exit logging on the above method sum and similar methods like that?

@kamilmysliwiec
Copy link
Member

@Use[..]() decorators don't override original methods. If you want to add logging that would affect a real method implementation, you have to create your own decorator. Perhaps, I'll provide a way to dynamically create a method based on the attached metadata in the future.

@vivekkatta
Copy link
Author

I thought about creating a custom decorator...but it isn't as convenient as an around interceptor. I'll think of something...Thanks

BTW, the library is amazing!

@kamilmysliwiec
Copy link
Member

Thank you a lot 🙂

@et
Copy link

et commented Jun 12, 2018

@use.. decorators don't override original methods. If you want to add logging that would affect a real method implementation, you have to create your own decorator. Perhaps, I'll provide a way to dynamically create a method based on the attached metadata in the future.

Hi @kamilmysliwiec - Just wanted to provide some feedback that this has tripped me up. I think there's needs to be more explicit documentation that these really only work on controllers (or at least that's how I understand them).

@lock
Copy link

lock bot commented Sep 24, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants