grpc / grpc-node

gRPC for Node.js
https://grpc.io
Apache License 2.0
4.5k stars 651 forks source link

Support proto3 optional with grpc_tools_node_protoc_plugin #2083

Open mmatheson opened 2 years ago

mmatheson commented 2 years ago

Problem description

I'm using rules_proto_grpc to generate node targets which are consumed by typescript (ts_project from rules_nodejs). rules_proto_grpc uses grpc_tools_node_protoc_plugin from the grpc-tools package to build a js_grpc_node_library. Building a js_grpc_node_library from a file (hello.proto) with an optional field results in the following error message:

hello.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-grpc_node_plugin hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.--grpc_node_plugin_out:

Reproduction steps

Use js_grpc_node_library to compile a proto with an optional field. For example:

hello.proto:

syntax = "proto3";

package hello.proto;

message Hello {
  optional string greeting = 1;
}

BUILD:

proto_library(
    name = "hello_proto",
    srcs = glob(["*.proto"]),
)

js_grpc_node_library(
    name = "hello_js_grpc",
    protos = [":hello_proto"],
)

Environment

murgatroid99 commented 2 years ago

This should already work. This was previously reported in #1717, and I made the fix for the plugin in #1725, and then that change was published in version 1.11.1.