Closed baflo closed 4 years ago
When I changed to only use MessageBody, everything works as usual. However, if I add ConnectedSocket, it won't.
You must use either the decorators approach or classic approach (without ANY parameter decorator). For example, the following code:
handleEvent(client: Socket, @MessageBody() data: string): string {
return data;
}
will not work properly.
In your case, you can simply change your method signature to this:
handleEvent(@MessageBody() data: string): string {
return data;
}
If you want to bind a pipe to a single parameter, you can do it in this way:
handleEvent(@MessageBody(ValidationPipe) data: string): string {
return data;
}
Bug Report
Current behavior
Hi, I ran into an issue when I was updating nestjs from 6.7.2 to 6.11.11: my validation pipe for websocket event wouldn't work as expected anymore. I found that all parameters of an event handler are put to the validation pipe and only if all of them succeeded the validation, the handler would be called. Now, I still had the "old" pattern instead of using
ConnectedSocket
andMessageBody
:When I changed to only use
MessageBody
, everything works as usual. However, if I addConnectedSocket
, it won't.Input Code
https://github.com/baflo/nest-1/blob/connectedsocket-usepipes-bug/sample/02-gateways/src/events/events.gateway.ts
Expected behavior
I expected at least the old pattern to not change the behaviour, i.e. to not check every parameter, but only the data.
Possible Solution
Maybe I can put the ValidationPipe to just one parameter?
Environment