From 3a45e340289b351b0f33ef0000dcf55055e32791 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 30 Apr 2018 17:51:37 -0700 Subject: [PATCH] Update Node examples to use new @grpc/proto-loader package --- examples/node/dynamic_codegen/greeter_client.js | 11 ++++++++++- examples/node/dynamic_codegen/greeter_server.js | 11 ++++++++++- .../dynamic_codegen/route_guide/route_guide_client.js | 11 ++++++++++- .../dynamic_codegen/route_guide/route_guide_server.js | 11 ++++++++++- examples/node/package.json | 3 ++- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/examples/node/dynamic_codegen/greeter_client.js b/examples/node/dynamic_codegen/greeter_client.js index 9fd1f88f4fb..c289f501ee1 100644 --- a/examples/node/dynamic_codegen/greeter_client.js +++ b/examples/node/dynamic_codegen/greeter_client.js @@ -19,7 +19,16 @@ var PROTO_PATH = __dirname + '/../../protos/helloworld.proto'; var grpc = require('grpc'); -var hello_proto = grpc.load(PROTO_PATH).helloworld; +var protoLoader = require('@grpc/proto-loader'); +var packageDefinition = protoLoader.loadSync( + PROTO_PATH, + {keepCase: true, + longs: String, + enums: String, + defaults: true, + oneofs: true + }); +var hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld; function main() { var client = new hello_proto.Greeter('localhost:50051', diff --git a/examples/node/dynamic_codegen/greeter_server.js b/examples/node/dynamic_codegen/greeter_server.js index 180f96c28b8..023257ecf08 100644 --- a/examples/node/dynamic_codegen/greeter_server.js +++ b/examples/node/dynamic_codegen/greeter_server.js @@ -19,7 +19,16 @@ var PROTO_PATH = __dirname + '/../../protos/helloworld.proto'; var grpc = require('grpc'); -var hello_proto = grpc.load(PROTO_PATH).helloworld; +var protoLoader = require('@grpc/proto-loader'); +var packageDefinition = protoLoader.loadSync( + PROTO_PATH, + {keepCase: true, + longs: String, + enums: String, + defaults: true, + oneofs: true + }); +var hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld; /** * Implements the SayHello RPC method. diff --git a/examples/node/dynamic_codegen/route_guide/route_guide_client.js b/examples/node/dynamic_codegen/route_guide/route_guide_client.js index 703cfd29028..34a44bd6a9e 100644 --- a/examples/node/dynamic_codegen/route_guide/route_guide_client.js +++ b/examples/node/dynamic_codegen/route_guide/route_guide_client.js @@ -24,7 +24,16 @@ var parseArgs = require('minimist'); var path = require('path'); var _ = require('lodash'); var grpc = require('grpc'); -var routeguide = grpc.load(PROTO_PATH).routeguide; +var protoLoader = require('@grpc/proto-loader'); +var packageDefinition = protoLoader.loadSync( + PROTO_PATH, + {keepCase: true, + longs: String, + enums: String, + defaults: true, + oneofs: true + }); +var routeguide = grpc.loadPackageDefinition(packageDefinition).routeguide; var client = new routeguide.RouteGuide('localhost:50051', grpc.credentials.createInsecure()); diff --git a/examples/node/dynamic_codegen/route_guide/route_guide_server.js b/examples/node/dynamic_codegen/route_guide/route_guide_server.js index 3819c092eb5..69fbc3c8840 100644 --- a/examples/node/dynamic_codegen/route_guide/route_guide_server.js +++ b/examples/node/dynamic_codegen/route_guide/route_guide_server.js @@ -23,7 +23,16 @@ var parseArgs = require('minimist'); var path = require('path'); var _ = require('lodash'); var grpc = require('grpc'); -var routeguide = grpc.load(PROTO_PATH).routeguide; +var protoLoader = require('@grpc/proto-loader'); +var packageDefinition = protoLoader.loadSync( + PROTO_PATH, + {keepCase: true, + longs: String, + enums: String, + defaults: true, + oneofs: true + }); +var routeguide = grpc.load(packageDefinition).routeguide; var COORD_FACTOR = 1e7; diff --git a/examples/node/package.json b/examples/node/package.json index 6317838295a..3af6a113fd5 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -2,9 +2,10 @@ "name": "grpc-examples", "version": "0.1.0", "dependencies": { + "@grpc/proto-loader": "^0.1.0", "async": "^1.5.2", "google-protobuf": "^3.0.0", - "grpc": "^1.0.0", + "grpc": "^1.11.0", "lodash": "^4.6.1", "minimist": "^1.2.0" }