Skip to content

Files

gradle-ts-protoc-gen

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 11, 2020
May 13, 2021
May 13, 2021
Sep 21, 2020
Oct 11, 2020
Sep 21, 2020
Sep 21, 2020
May 13, 2021
May 13, 2021
Oct 11, 2020
Sep 21, 2020
Sep 21, 2020
Jul 29, 2022
Jul 29, 2022
Dec 16, 2020
Sep 21, 2020
Sep 21, 2020

gradle-ts-protoc-gen example

This examples shows how to uses Gradle, the proto compiler, ts-protoc-gen & @grpc/grpc-js to build a fully typed gRPC application that runs on Node.js.

The proto compiler and ts-protoc-gen compiler plugin are used to generate JavaScript & TypeScript files from the proto definitions. The protobuf-gradle-plugin Gradle plugin is used to run the compiler from Gradle.

google-protobuf & @grpc/grpc-js are used at runtime.

App layout

Generating the Types

Install dependencies:

npm install

# Apple M1 users should install for x64 due to grpc-tools not supporting arm64
npm i --target_arch=x64

Use Gradle & ts-protoc-gen to generate the TypeScript files:

./gradlew generateProto

This is aliased as a npm script:

npm run build:proto

Running the App

This simple app demonstrates the different gRPC calls you can perform.

First generated the types and build the application files:

npm run build

Start the server:

npm run start:server

Now run the client by specifying which example you want to run:

npm run start:client -- --unary
npm run start:client -- --server-streaming
npm run start:client -- --client-streaming
npm run start:client -- --bidi-streaming