Skip to content

Commit 6dc3bc6

Browse files
refactor(client): migrate grpc client to @grpc/grpc-js and proto-loader
1 parent 36e7a77 commit 6dc3bc6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

endpoints/getting-started-grpc/client.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,22 @@ const makeGrpcRequest = (JWT_AUTH_TOKEN, API_KEY, HOST, GREETEE) => {
2323
// const GREETEE = 'world';
2424

2525
// Import required libraries
26-
const grpc = require('grpc');
26+
const grpc = require('@grpc/grpc-js');
27+
const protoLoader = require('@grpc/proto-loader');
2728
const path = require('path');
2829

2930
// Load protobuf spec for an example API
3031
const PROTO_PATH = path.join(__dirname, '/protos/helloworld.proto');
31-
const protoObj = grpc.load(PROTO_PATH).helloworld;
32+
33+
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
34+
keepCase: true,
35+
longs: String,
36+
enums: String,
37+
defaults: true,
38+
oneofs: true,
39+
});
40+
41+
const protoObj = grpc.loadPackageDefinition(packageDefinition).helloworld;
3242

3343
// Create a client for the protobuf spec
3444
const client = new protoObj.Greeter(HOST, grpc.credentials.createInsecure());

0 commit comments

Comments
 (0)