Skip to content
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

@grpc/grpc-js Support #226

Closed
moloch-- opened this issue May 9, 2020 · 7 comments
Closed

@grpc/grpc-js Support #226

moloch-- opened this issue May 9, 2020 · 7 comments

Comments

@moloch--
Copy link

moloch-- commented May 9, 2020

Feature Request

Support generation of code that works with @grpc/grpc-js instead of grpc-node as the developers have indicated they plan to deprecate grpc-node: https://grpc.io/blog/grpc-js-1.0/

Simply replacing the imports does not seem to work with the newly generated code/library.

@117sparta
Copy link

I guess you can modify the code and meet your need.

@117sparta
Copy link

image
The only thing you need to do is to modify one line of code in grpcnode.ts file.

@117sparta
Copy link

117sparta commented May 29, 2020

Find the code below and change "import * as grpc from 'grpc" to "import * as grpc from '@grpc/grpc-js'"

// Import statements.
  serviceDescriptor.imports
    .forEach(importDescriptor => {
      printer.printLn(`import * as ${importDescriptor.namespace} from "${importDescriptor.path}";`);
    });
  printer.printLn(`import * as grpc from "grpc";`);

after that, run 'npm run instal'l and 'npm run build' on terminal.
Then include the bin folder and lib folder which is generated after run the "npm run build" command into your project. Modify the executable path of the shell command below to the bin folder.

# Path to this plugin, Note this must be an abolsute path on Windows (see #15)
PROTOC_GEN_TS_PATH="the bin folder path"

# Path to the grpc_node_plugin
PROTOC_GEN_GRPC_PATH="./node_modules/.bin/grpc_tools_node_protoc_plugin"

# Directory to write generated code to (.js and .d.ts files)
OUT_DIR="./generated"

protoc \
    --plugin="protoc-gen-ts=${PROTOC_GEN_TS_PATH}" \
    --plugin=protoc-gen-grpc=${PROTOC_GEN_GRPC_PATH} \
    --js_out="import_style=commonjs,binary:${OUT_DIR}" \
    --ts_out="service=grpc-node:${OUT_DIR}" \
    --grpc_out="${OUT_DIR}" \
    users.proto base.proto

Oh, don't forget to install 'google-protobuf' if you are not.

@zetaron
Copy link

zetaron commented Jun 4, 2020

Reference #234

@badsyntax
Copy link
Contributor

I've submitted a PR that introduces a mode param allowing you to opt-in to using @grpc/grpc-js instead of grpc, for example:

--ts_out=service=grpc-node,mode=grpc-js

@stale
Copy link

stale bot commented Sep 14, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 14, 2020
@MarcusLongmuir
Copy link
Contributor

Fixed in #236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants