I am quite new to Protocol Buffers.
I noticed that the grpc proto-loader
module requires just a single proto definition file to load, so I have loaded it in my code as below:
const PROTO_PATH = `${path.resolve(__dirname, '..')}${path.sep}protos${path.sep}index.proto`;
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
});
let indexProto = grpc.loadPackageDefinition(packageDefinition).index;
Now my index.proto
file is referencing another proto file
as below:
syntax = "proto3";
package index;
import public "location_updater.proto";
And my location_updater.proto
is defined as below
syntax = "proto3";
package location_updater;
service LocationUpdater{
rpc updateLocation(Location) returns LocationUpdateResponse{}
}
message Location{
string apiKey = 1;
string updateTarget = 2;
double longitude = 3;
double latitude = 4;
}
message LocationUpdateResponse{
int32 statusCode = 1;
}
When I do the following:
let grpcServer = new grpc.Server();
grpcServer.addService(indexProto.location_updater.LocationUpdater.service, {
});
I am getting an error TypeError: Cannot read property 'LocationUpdater' of undefined
If I move the content of the location_updater.proto
into to the index.proto
file it works, but I don't want that behavior as I would be working with many different proto files for different business logic.
What am I doing wrong and what is the best way to go about this?.
Thanks in anticipation for your input.