badsyntax / grpc-js-typescript Goto Github PK
View Code? Open in Web Editor NEWGenerate gRPC TypeScript definitions for use with gRPC (@grpc/grpc-js).
Generate gRPC TypeScript definitions for use with gRPC (@grpc/grpc-js).
example-dto.proto
filesyntax = "proto3";
package v1;
message ServerMessage {
string server_message = 1;
}
message ClientMessage {
string client_message = 1;
}
example.proto
filesyntax = "proto3";
import "proto/example-dto.proto";
package example_package;
service Example {
rpc unaryCall(v1.ClientMessage) returns (v1.ServerMessage) {}
}
run ./compile-proto.sh,
check example_pb.js
file conent
/**
* @fileoverview
* @enhanceable
* @suppress {messageConventions} JS Compiler reports an error if a variable or
* field starts with 'MSG_' and isn't a translatable message.
* @public
*/
// GENERATED CODE -- DO NOT EDIT!
var jspb = require('google-protobuf');
var goog = jspb;
var global = Function('return this')();
var example$dto_pb = require('./example-dto_pb.js');
goog.object.extend(proto, example$dto_pb);
ServerMessage and ClientMessage method is not exported by example_pb.js
The current example(also them on your github repo) are outdated. The example uses client.unaryCall but currently, what is being used is makeUnaryRequest. Could you provide us example to that please? Thanks!
Per grpc/grpc-node#1417, the it looks like the sed
commands should no longer be needed in the gen script... but I can't seem to figure out what argument is supposed to go where to make this work. Can you update this repo to provide such an example?
And by the way, THANK YOU for putting this together.
Thank you very much for your example, but I'm not sure how to implement the actual logic and a server?
I guess it should look something like that, but I struggle how to actually implement the interface?
// src/index.ts
import * as grpc from '@grpc/grpc-js'
import * as services from './proto/echo_service_grpc_pb'
class EchoService implements services.IEchoServiceService {
// ?
}
var server = new grpc.Server();
server.addService(services.EchoServiceService, new EchoService());
server.bindAsync("127.0.0.1:50051", grpc.ServerCredentials.createInsecure(), (err, port) => {
if (!err) server.start();
});
Or is there is something missing? For example in https://github.com/agreatfool/grpc_tools_node_protoc_ts/blob/b7b5e97349d3f9463214f4cc65e2ec2c9e44320a/examples/src/grpcjs/proto/book_grpc_pb.d.ts#L57-L62 there is also additional interface IBookServiceServer
defined which I guess should be used as implementation interface for servers but here it's missing?
Hey there!
Here:
https://github.com/badsyntax/grpc-js-typescript/tree/master/examples/grpc-proto-loader
You mention protobuf.js in the readme.
But this example does not use protobuf.js at all, does it?
BTW - THANKS FOR THIS REPO! Examples of Typescript + grpc are so patchy and confusing, you helped a lot!
I'm not sure if this should be in 'issue' so feel free to close. I'm hugely thankful for this repo, as I was struggling to find a working example of a simple grpc server and client.
Having put together a simple grpc repo myself, I am now struggling to come up with a way to test this setup. I'd like to be able to get the server running, then invoke the client and assert against the response on the client side.
Any resources on how I can do this please?
Hello, thanks for the effort you've been giving to this project. Its been really helpful for me.
But I couldn't generate proto files from the script you've written in windows even though bash is installed. Can you help me with that?
Hello and thanks for all the examples here on how to use gRPC with TypeScript. This is not an issue and actually a question.
I was wondering if there is a way to package the generated TS client stubs as an npm package (without using Rollup or Webpack or the like) that can later used via an npm install
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.