Reputation: 947
I am facing an issue when I am trying to create a grpc client call using node js. when I use import "google/api/annotations.proto"
in proto file I get an below error. if I remove it it works file. May I know what I am missing from my client.js
Error: unresolvable extensions: 'extend google.protobuf.MethodOptions' in .google.api at Root.resolveAll (src/github.com/workspace/explorer/node_modules/protobufjs/src/root.js:255:15) at Object.loadSync (/src/github.com/workspace/explorer/node_modules/@grpc/proto-loader/build/src/index.js:224:16) at Object. (/src/github.com/workspace/explorer/server/grpc/client.js:3:37)
syntax = 'proto3';
import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
package chain;
service chain {
rpc GetHeight(HeightRequest) returns(HeightResponse) { option (google.api.http).get = "/api/height/{height}";}
}
message HeightRequest {
string hash = 1;
}
message HeightResponse {
int64 height=1;
}
client.js
var PROTO_PATH = __dirname + '/proto/chain.proto';
var parseArgs = require('minimist');
var grpc = require('@grpc/grpc-js');
var protoLoader = require('@grpc/proto-loader');
var packageDefinition = protoLoader.loadSync(
PROTO_PATH,
{
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
});
var chain_proto = grpc.loadPackageDefinition(packageDefinition).chain;
function main() {
var argv = parseArgs(process.argv.slice(2), {
string: 'target'
});
var target;
if (argv.target) {
target = argv.target;
} else {
target = 'localhost:9040';
}
var client = new chain_proto.chain(target,
grpc.credentials.createInsecure());
client.GetHeight(function (err, response) {
console.log('height:', response);
});
}
main();
Upvotes: 2
Views: 1599
Reputation: 947
I found the solution to the above error, you need to create a folder inside the project directory googleapis->google->api
then need to add an annotation.proto file from grpc-gateway GitHub like mention in this link
Grpc-gateway
Next need to add a path as shown below.
PROTO_PATH,
{
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
includeDirs: [
__dirname + '/googleapis',
]
});
Upvotes: 1