Open dinfer opened 4 years ago
@dinfer
re: API Docs
Try accessing the docs here: https://protobufjs.github.io/protobuf.js/ or if running locally use:
npm run docs
and launch from docs/index.html
There doesn't appear to be any good documentation on this in the API Documents or README, The example in the README is for a client object. I am looking for a way to do this as well.
protobuf.Service
has no relationship to grpc.Server
. They are not compatible at all. I recommend instead using @grpc/proto-loader
, which wraps Protobuf.js.
After loading the .proto
files using that library, you would use it with code that looks something like this:
const serviceDefinition = packageObject.package.names.ServiceName.service;
const server = new grpc.Server();
server.addService(serviceDefinition, serviceImplementation);
Thank you @murgatroid99 i think that answers the original question then.
If you're using proto-loader does that mean we can't use pbts
to generate the type file? https://stackoverflow.com/questions/64530776/how-do-you-generate-typings-for-protobuf-files-for-use-with-grpc
That's right. The code generated by @grpc/proto-loader
does not use objects of the same types that are generated by pbts
. There is ongoing work in the PR grpc/grpc-node#1474 to address that issue by adding a TypeScript generator in @grpc/proto-loader
itself.
So for the time being I guess we have to work without proper types. I haven't done it for a while so I can't really remember how, but is it possible for you @murgatroid99 to provide a link to a .d.ts
file that we can use as a way to bypass the type checks even if it is a simple
interface somegrpcthingIMade {
any
}
The PR I linked has been published as a prerelease version of @grpc/proto-loader
with the tag generator-draft
. So you can try it out with npm install @grpc/proto-loader@generator-draft
.
If that doesn't work for you, I don't know what specific type check you want to bypass, but in general if a type definition isn't working for you you can just typecast it yourself.
I need to dynamically bind functions to GRPC services, but I cannot find document to describe how to do that.
The wiki page API Document link is broken. (the link) The example in the README is not used with
grpc.Server