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

[Microservices] the gRPC DTO is undefined if a param decorator is used #4851

Closed
twister21 opened this issue May 28, 2020 · 5 comments
Closed
Labels
needs triage This issue has not been looked into

Comments

@twister21
Copy link

twister21 commented May 28, 2020

Bug Report

Current behavior

If a param decorator is applied to a parameter of a gRPC route handler, the DTO is always undefined, but the parameter the custom decorator is applied to gets populated properly.

Input Code

// controller

@GrpcMethod('ReportService')
createReport(createReportDto: CreateReportDto, @AuthUser() user: User): Promise<Report> {
  console.log(createReportDto); // undefined
  console.log(user) // {id: 1, role: 2}

  return this.reportService.createOne(createReportDto, user.id);
}
// param decorator

export const AuthUser = createParamDecorator(
  (data: any, context: ExecutionContext) => {
    const metadata = context.switchToRpc().getContext();
    return metadata.user; // the user is attached to the context in a guard
  },
);

Expected behavior

Both the DTO and the parameter that the decorator is applied to, should be populated properly.

Environment


Nest version: 7.1.0

@twister21 twister21 added the needs triage This issue has not been looked into label May 28, 2020
@twister21 twister21 changed the title [Microservices] the gRPC data object is undefined if a param decorator is used [Microservices] the gRPC DTO is undefined if a param decorator is used May 28, 2020
@kamilmysliwiec
Copy link
Member

Have you tried using @Payload() createReportDto: CreateReportDto?

@twister21
Copy link
Author

That works. I did not see that there is a separate param decorator for a gRPC handler.

However, it seems that the @Body() decorator also works for the gRPC handler, since I'm trying to use the same handler for HTTP + gRPC.

Is this the intended behavior?

@kamilmysliwiec
Copy link
Member

I'm glad it fixed your issue!

However, it seems that the @Body() decorator also works for the gRPC handler, since I'm trying to use the same handler for HTTP + gRPC.

This is due to the backward compatibility.

We gotta improve the documentation. Sorry for the inconvenience!

@danias
Copy link

danias commented Mar 21, 2023

What about metadata and call? When I use a decorator, data shows up when I use @payload() but I don't know what to use for metadata and call.

@MaksymShuldiner
Copy link

@kamilmysliwiec @danias agree, what argument should be used for metadata and call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

4 participants