nest
nest copied to clipboard
No way to inject context in gRPC method in NestJS
trafficstars
Is there an existing issue that is already proposing this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe it
Hey, as long as I have searched, I don't think there is a way to inject context in gRPC method. You can do it in GraphQL resolver, and Http Controller using decorator.
Describe the solution you'd like
I recommend decorator in nest/microservice package.
Teachability, documentation, adoption, migration strategy
import { GrpcContext } from '@nestjs/microservices';
async me(@GrpcContext() context: ExecutionContext): Promise<UserResponse> {
return context?.user;
}
What is the motivation / use case for changing the behavior?
Let's say in gRPC method, user info can be save in context of ExecutionContext, but can't be injected in gRPC method.
It will be very good to be implemented.