Skip to content

Commit

Permalink
handle observable for handleMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
zgid123 committed Apr 19, 2023
1 parent 4bd49aa commit 8b78d2b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/nestjs/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grpc.ts/nestjs-server",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"directories": {
"lib": "lib"
Expand Down Expand Up @@ -38,7 +38,8 @@
},
"dependencies": {
"@grpc.ts/core": "workspace:*",
"@nestjs/common": "^9.4.0"
"@nestjs/common": "^9.4.0",
"rxjs": "^7.8.0"
},
"devDependencies": {
"@grpc.ts/server-commons": "workspace:^"
Expand Down
2 changes: 1 addition & 1 deletion packages/nestjs/server/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import typescript from '@rollup/plugin-typescript';
export default defineConfig({
input: 'src/index.ts',
plugins: [json(), resolve(), commonjs(), typescript()],
external: ['@nestjs/common', '@grpc.ts/core'],
external: ['@nestjs/common', '@grpc.ts/core', 'rxjs'],
output: [
{
file: './lib/index.cjs',
Expand Down
11 changes: 9 additions & 2 deletions packages/nestjs/server/src/GrpcServer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Logger } from '@nestjs/common';
import { lastValueFrom, isObservable } from 'rxjs';
import { createServers } from '@grpc.ts/server-commons';

import type { Metadata, ServerUnaryCall } from '@grpc.ts/core';
Expand Down Expand Up @@ -81,8 +82,14 @@ export class GrpcServer {
server.addUnaryHandler(
serviceName,
rpcName,
(request, metadata, call) => {
return handleMessage(request, metadata, call, pattern);
async (request, metadata, call) => {
const message = await handleMessage(request, metadata, call, pattern);

if (isObservable(message)) {
return lastValueFrom(message);
}

return message;
},
options,
);
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b78d2b

Please sign in to comment.