Unable to use google.protobuf.Struct with @grpc/grpc-js
- Dominant language
- TypeScript
- Stars
- 4.8k
- Forks
- 716
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 10
Description
### Problem description
When trying to respond with a `google.protobuf.Struct`, the call errors with status 13 INTERNAL `Error serializing response: Expected argument of type google.protobuf.Struct`.
### Reproduction steps
Use this proto file:
```proto
syntax = "proto3";
import "google/protobuf/struct.proto";
package test;
message Empty {}
service Test {
rpc getStruct(Empty) returns (google.protobuf.Struct) {}
}
```
Compile it with:
```sh
node_modules/.bin/grpc_tools_node_protoc \
--grpc_out="grpc_js:./" \
--js_out="import_style=commonjs,binary:./" \
test.proto
```
Then create the following server:
```js
const grpc = require('@grpc/grpc-js');
const { Struct } = require('google-protobuf/google/protobuf/struct_pb');
const { TestService } = require('./test_grpc_pb');
const server = new grpc.Server();
server.addService(TestService, {
getStruct: (call, callback) => {
callback(null, Struct.fromJavaScript({ test: 1, b: 'c' }));
},
});
server.bindAsync('0.0.0.0:4000', grpc.ServerCredentials.createInsecure());
```
Run it, and try to call `getStruct` (using Postman, for example).
The server replies with an error: `Error serializing response: Expected argument of type google.protobuf.Struct`
I also tried with a plain object:
```js
callback(null, {
fields: {
test: { kind: 'numberValue', numberValue: 1 },
b: { kind: 'stringValue', stringValue: 'c' }
}
});
```
I get the same error.
Maybe I'm missing something obvious, but I've been trying a lot of things for the past hours and I still can't figure how to send a Struct...
### Environment
- OS name, version and architecture: Arch Linux x64
- Node version: 20.12.2
- Node installation method: nvm
- Package name and version: @grpc/grpc-js@1.10.7
Contributor guide
Assessment
This issue has not been assessed yet.