-
Notifications
You must be signed in to change notification settings - Fork 838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: grpc-js example #1362
fix: grpc-js example #1362
Conversation
Signed-off-by: reggiemcdonald <[email protected]>
Signed-off-by: reggiemcdonald <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #1362 +/- ##
=======================================
Coverage 93.18% 93.18%
=======================================
Files 149 149
Lines 4228 4228
Branches 869 869
=======================================
Hits 3940 3940
Misses 288 288 |
if (!(arg instanceof helloworld_pb.HelloReply)) { | ||
throw new Error('Expected argument of type HelloReply'); | ||
throw new Error('Expected argument of type helloworld.HelloReply'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error('Expected argument of type helloworld.HelloReply'); | |
throw new Error('Expected argument of type helloworld_pb.HelloReply'); |
// The greeting service definition. | ||
const GreeterService = (exports.GreeterService = { | ||
var GreeterService = exports.GreeterService = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make this a var
?
'use strict'; | ||
var grpc = require('@grpc/grpc-js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the changes to this file appear to be unrelated to the purpose of the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the recompiled output from protoc. Would you prefer me to manually edit the file to make it work? There would be a much smaller diff if I make the edits manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize this was generated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea both the grpc and grpc-js repos use generated code from protoc, using a proto file from a grpc example on github.com/grpc/grpc
const writer = new jspb.BinaryWriter(); | ||
this.serializeBinaryToWriter(writer); | ||
proto.helloworld.HelloReply.prototype.serializeBinary = function() { | ||
var writer = new jspb.BinaryWriter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many places where const
rewritten to var
. Any reason for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the commonjs flag to protoc. Maybe theres a different flag to get let
and const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not overly familiar with protoc so I'm not sure.
would it be possible to use |
The proto file used in this example is from github.com/grpc/grpc. So we would need to commit that file to the repository for the To keep the diff down, I could edit the existing file manually - you can see what that would look like here. It works, and it's much smaller. It just isn't what the protobuf compiler would output. |
I have been in the same place recently when I was adding support for proto for collector exporter. Started with generated files, but it turned out I can simply load the proto files and then use the package without the need to generate the files. Much easier to maintain, less errors and code. |
I don't think it's an issue to check in the proto file to this example. The manually edited version also looks ok to me, so for me either is fine. |
+1 to switching these examples over to protoloading the sample The only reason the old grpc examples had the codegen example at all is because that grpc module supported several different ways of setting up a client. For grpc-js, all are deprecated except for |
Why don't I use the manually edited version for this issue to get the example working, and then open a new issue to move both the |
closing in favour of #1364 |
Which problem is this PR solving?
grpc
and thus incompatible withgrpc-js
. This PR will resolve these incompatibilities.Short description of the changes
# Assuming that `helloworld.proto` is at the root of the example npm install npx grpc_tools_node_protoc \ --js_out=import_style=commonjs,binary:./ \ --grpc_out=grpc_js:./ \ -I=./ helloworld.proto
grpc_tools_node_protoc
provides theprotoc
interface, but the output is compatible withgrpc-js