nest icon indicating copy to clipboard operation
nest copied to clipboard

No way to inject context in gRPC method in NestJS

Open uranuslucky opened this issue 1 year ago • 0 comments
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.

uranuslucky avatar Oct 19 '24 02:10 uranuslucky