From 23170cf1c81cc66c1f4aa848d1e52cf6e92c17f6 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Sat, 29 Jan 2022 01:15:49 +0100 Subject: [PATCH] fix(microservices): generate service method in lower and uppercase RPC methods in protobuf are commonly declare in PascalCase, but they were generated lowercase by ClientGrpcProxy.getService method. Protobuf and gRPC have tools to generate interface and message in Typescript directly from protobuf. It's a powerful feature that's helping to maintain only one source of truth. But with that lowercase method generation, developers were forced to define their own interface which can be painful to maintain. This commit fix that issue by generating methods both in lowercase and in uppercase. Solves #9047 Signed-off-by: Vasek - Tom C --- integration/microservices/e2e/sum-grpc.spec.ts | 9 +++++++-- integration/microservices/src/grpc/grpc.controller.ts | 8 ++++++++ packages/microservices/client/client-grpc.ts | 3 +-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/integration/microservices/e2e/sum-grpc.spec.ts b/integration/microservices/e2e/sum-grpc.spec.ts index d292c3c2100..cc4dbe45a14 100644 --- a/integration/microservices/e2e/sum-grpc.spec.ts +++ b/integration/microservices/e2e/sum-grpc.spec.ts @@ -48,11 +48,16 @@ describe('GRPC transport', () => { ); }); - it(`GRPC Sending and Receiving HTTP POST`, () => { - return request(server) + it(`GRPC Sending and Receiving HTTP POST`, async () => { + await request(server) .post('/sum') .send([1, 2, 3, 4, 5]) .expect(200, { result: 15 }); + + await request(server) + .post('/upperMethod/sum') + .send([1, 2, 3, 4, 5]) + .expect(200, { result: 15 }); }); it(`GRPC Sending and Receiving HTTP POST (multiple proto)`, async () => { diff --git a/integration/microservices/src/grpc/grpc.controller.ts b/integration/microservices/src/grpc/grpc.controller.ts index e99d8d6c632..94b7c4f75d3 100644 --- a/integration/microservices/src/grpc/grpc.controller.ts +++ b/integration/microservices/src/grpc/grpc.controller.ts @@ -40,6 +40,14 @@ export class GrpcController { return svc.sum({ data }); } + // Test that getService generate both lower and uppercase method + @Post('upperMethod/sum') + @HttpCode(200) + callWithOptions(@Body() data: number[]): Observable { + const svc = this.client.getService('Math'); + return svc.Sum({ data }); + } + @GrpcMethod('Math') async sum({ data }: { data: number[] }): Promise { return of({ diff --git a/packages/microservices/client/client-grpc.ts b/packages/microservices/client/client-grpc.ts index 298a9e1524c..008bee4fa83 100644 --- a/packages/microservices/client/client-grpc.ts +++ b/packages/microservices/client/client-grpc.ts @@ -53,8 +53,7 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc { const grpcService = {} as T; protoMethods.forEach(m => { - const key = m[0].toLowerCase() + m.slice(1, m.length); - grpcService[key] = this.createServiceMethod(grpcClient, m); + grpcService[m] = this.createServiceMethod(grpcClient, m); }); return grpcService; }