Support grpc-js for the non generate_package_definition output
See original GitHub issueHello GRPC node team!
Currently we use the latest grpc-tools
and ts-protoc-gen
for generating js/ts code for the GRPC models/services.
We use the simple grpc-tools
output without the generate_package_definition
option. In the same way as provided here https://github.com/grpc/grpc/tree/master/examples/node/static_codegen
import { credentials } from "grpc";
import { MyServiceClient } from "my_service_grpc_pb";
import { CreateUserRequest } from "my_service_pb";
const client = new MyServiceClient("url", credentials.createInsecure());
client.createUser(new CreateUserRequest(), (error, value) => {});
one more example here https://github.com/agreatfool/grpc_tools_node_protoc_ts/blob/master/examples/src/grpc/client.ts
Pros:
- Due to
ts-protoc-gen
supports the same output it’s easier to use the typescript types. Example - https://github.com/improbable-eng/ts-protoc-gen/blob/master/examples/generated-grpc-node/proto/orphan_grpc_pb.d.ts#L16. So, you don’t need cast it manually - we also don’t need to use
makeClientConstructor
or/andloadPackageDefinition
in this case
Cons:
- this approach requires to use the “grpc” node library which will be deprecated soon
The question is there any plans to support “grpc-js” for this GRPC output option?
Also please correct me if I’m wrong, but it sounds like that PR proto-loader: Add TypeScript generator
https://github.com/grpc/grpc-node/pull/1474 doesn’t have this feature at all
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Basics tutorial | Node - gRPC
This tutorial provides a basic Node.js programmer's introduction to working with gRPC. By walking through this example you'll learn how to:.
Read more >gRPC service in Node.js: Tutorial, Examples and Best practices
It enables us to create gRPC service in the Nodejs runtime. @grpc/proto-loader: A utility package for loading .proto files for use with gRPC...
Read more >The Weird World of gRPC Tooling for Node.js, Part 1 - Medium
grpc -tools provides a plugin to protoc that allows it to generate JavaScript client stubs and server skeletons that implement a normal object ......
Read more >Tutorial: How to Build Your First Node.js gRPC API - Trend Micro
While not mandatory, JavaScript knowledge is also quite helpful. ... You create the package definitions and the gRPC object in the same way....
Read more >How to Easily use GRPC and Protocol Buffers with NodeJS
Modify the package.json file · Defining the Protocol Buffer · Creating the GRPC Server · Creating the GRPC Client · Running The Server...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
grpc-tools
library accepts the argument--grpc_js
, which should do what you are asking for.The linked PR for the
@grpc/proto-loader
library has the--grpcLib
option, which can be used for the same effect.No, I wrote that section of the README before the
--grpc_js
option was added. The--grpc_js
option only does something if you don’t use the--generate_package_definition
option.