[grpc-web] RPC with google.protobuf.Empty request field

115 views
Skip to first unread message

nathan...@gmail.com

unread,
Dec 18, 2018, 5:24:12 PM12/18/18
to grpc.io
Hi,

I have a service Foo defined like so:

syntax = "proto3";

import "google/protobuf/empty.proto";

service Foo {
  rpc Ping(google.protobuf.Empty) returns (Pong);
}

message Pong {
  bool alive = 1;
}

from which I codegen the JavaScript files I need to implement a client like this:

const google_protobuf_empty_pb = require('google-protobuf/google/protobuf/empty_pb.js');
const {SubscribeRequest,Offset} = require('./foo_pb.js');
const {ProxyClient} = require('./foo_grpc_web_pb.js');

var client = new FooClient('http://' + window.location.hostname + ':9000', null, null);

client.ping(google_protobuf_empty_pb, {}, (err, resp) => {
  console.log(resp);
});

I then `npx webpack` this script to build a `./dist/main.js` served from `index.html`.

My problem though is that the Ping RPC in my main.js does not resolve the type of the `request` correctly which results in:

Uncaught TypeError: e.serializeBinary is not a function
    at module$contents$grpc$web$AbstractClientBase_AbstractClientBase.MethodInfo.requestSerializeFn (main.js:8)
    at module$contents$grpc$web$GrpcWebClientBase_GrpcWebClientBase.rpcCall (main.js:8)
    at n.FooClient.ping (main.js:8)
    at Object.<anonymous> (main.js:1)
    at o (main.js:1)
    at main.js:1
    at main.js:1
(anonymous) @ main.js:8
module$contents$grpc$web$GrpcWebClientBase_GrpcWebClientBase.rpcCall @ main.js:8
n.FooClient.ping @ main.js:8
(anonymous) @ main.js:1
o @ main.js:1
(anonymous) @ main.js:1
(anonymous) @ main.js:1

How do I use the google.protobuf.Empty type properly when making requests using grpc-web?
Reply all
Reply to author
Forward
0 new messages