grpc-node icon indicating copy to clipboard operation
grpc-node copied to clipboard

grpc loader.defauts does not work to control the response value

Open rawbin- opened this issue 8 months ago • 4 comments

Current behavior

we want to get such response from grpc api

{
    "code": 0,
    "statusCode": 1,
    "data": {
        "nullValue": null,
        "zeroValue": 0,
        "message": "great"
    }
}

so we overwrite the options.loader.defaults to get the zero value code item as follows:

app.connectMicroservice(
    {
      transport: Transport.GRPC,
      options: {
        url: '0.0.0.0:6000', // gRPC 服务的地址和端口
        package: 'hello', // proto 文件中的 package 名称
        protoPath: join(__dirname, '../proto/hello.proto'), // proto 文件路径
        loader: {
          defaults: true, // expected to get the zero value code in response
          arrays: true,
          objects: true,
          json: true,
        },
      },
    },

but we when I tested the result, I get confused because the result are not the same rule.

  • with Postman we always get the zero value code in response whether loader.defaults is true
  • with GRPC Client code we always get the zero value code in response whether loader.defaults is true
  • with grpcurl we always cannot get the zero value code in response whether loader.defaults is true
  • with Jetbrains HTTPClient we always cannot get the zero value code in response whether loader.defaults is true

Minimum reproduction code

https://github.com/rawbin-/nest-grpc-test/tree/main/appx

Steps to reproduce

pnpm i
pnpm start:dev

test with any grpc client tool

Expected behavior

loader.defaults can control the result

Packages versions

"@grpc/grpc-js": "^1.13.3",
    "@grpc/proto-loader": "^0.7.15",
    "@nestjs/common": "^10.0.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/microservices": "^11.1.0",
    "@nestjs/platform-express": "^10.0.0",
    "grpc": "^1.24.11",
    "reflect-metadata": "^0.2.0",
    "rxjs": "^7.8.1"

Node.js version

v18.20.7

In which operating systems have you tested?

  • [x] macOS
  • [ ] Windows
  • [ ] Linux

rawbin- avatar Apr 28 '25 12:04 rawbin-

In your reproduction link, the code in your main.ts says defaults: false.

murgatroid99 avatar Apr 28 '25 16:04 murgatroid99

In your reproduction link, the code in your main.ts says defaults: false.

when it's true and it does not change anything

rawbin- avatar Apr 29 '25 14:04 rawbin-

The API you are using directly is a Nest API. I suggest asking them.

murgatroid99 avatar Apr 29 '25 16:04 murgatroid99

The API you are using directly is a Nest API. I suggest asking them.

Yes, I asked both because the nest api called the grpc package here

rawbin- avatar Apr 30 '25 05:04 rawbin-