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

Pipe not working with @RabbitPayload decorator #645

Closed
nolawnchairs opened this issue Sep 9, 2023 · 1 comment · Fixed by #648
Closed

Pipe not working with @RabbitPayload decorator #645

nolawnchairs opened this issue Sep 9, 2023 · 1 comment · Fixed by #648

Comments

@nolawnchairs
Copy link

Hi,

The pipe I'm adding to my payload is not being executed:

protected async onBridgeRequest(
  @RabbitPayload(ParsePayloadPipe) payload: Payload) {
  console.log({ payload }) // payload is just the raw, un-transformed data
}

Pipes only execute if added with @UsePipes() at the handler, but then it applies the pipe to all deocrated arguments. I also use @RabbitHeader() to get a header value, and the pipe attempts to run on it as well (which I guess is expected):

protected async onBridgeRequest(
  @RabbitPayload(ParsePayloadPipe) payload: Payload, @RabbitHeader('foo') foo: string) {
  console.log({ payload })
}

So now I just add the pipe to the handler, and check in transform if the argument.metatype matches Payload then I execute the pipe logic, otherwise, I just send the data through as-is. It's very hacky, but the only way I can get this working as desired.

Not sure why the pipe(s) passed through that decorator don't work, as it's part of the NestJS contract with parameter decorators (first data, then pipe(s)).

@sezanzeb
Copy link
Contributor

sezanzeb commented Sep 22, 2023

you can construct the ParsePayloadPipe yourself, like @RabbitPayload(new ParsePayloadPipe()). Dependency injection is broken for @RabbitPayload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants