nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.28k stars 7.59k forks source link

Allow controller handlers for custom microservices to accept more than 1 argument #5705

Closed le0nik closed 3 years ago

le0nik commented 3 years ago

Feature Request

Problem: I have a custom microservice implementation(class MyServer extends Server implements CustomTransportStrategy and a corresponding decorator) which calls controller handlers with (call.request, call.metadata, call), but nestjs only passes call.request because

in RpcContextCreator https://github.com/nestjs/nest/blob/0d7b13ec53244f15f230e905afe3d463f6d5bf2b/packages/microservices/context/rpc-context-creator.ts#L118-L124 it calls controller handlers with just 1 argument initialArgs, because defaultCallMetadata length is 1, which is passed from ListenersController

and in ListenersController it checks for instanceof ServerGrpc to allow passing 3 arguments instead of 1, which is false in my case https://github.com/nestjs/nest/blob/a683a545af3eaee64f2b1863b79e4fd73dbdeb26/packages/microservices/listeners-controller.ts#L60-L63

As a temporary solution I had to only pass call argument, but would like to pass request and metadata separately.

Would it be fine to pass all arguments to the handler regardless of server type (get rid of those argsLenth/initialArgs) or maybe reverse the logic and pass 1 argument to known server types(except GRPC) and pass everything to the others?

Haven't seen this restriction anywhere in the docs so it wasn't easy to wrap my head around why nest would just drop some of the arguments was passing.

kamilmysliwiec commented 3 years ago

Would it be fine to pass all arguments to the handler regardless of server type (get rid of those argsLenth/initialArgs)

This would break too many features.

maybe reverse the logic and pass 1 argument known server types(except GRPC) and pass everything to the others?

Would you like to create a PR for this issue?