Giter Site home page Giter Site logo

grpc-node-server-reflection's People

Contributors

papajuanito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

grpc-node-server-reflection's Issues

Included an unresolvable reference to "google.protobuf.Struct"

I'm trying to use the well-known google types such as google.protobuf.Struct and it appears that grpcurl is failing with the following error.

$ grpcurl -plaintext localhost:50051 describe com.example.api.v1.ExampleAPI
Failed to resolve symbol "com.example.api.v1.ExampleAPI": file "com_example_api_v1.proto" included an unresolvable reference to "google.protobuf.Struct"

I'm guessing this happens because reflection API is not resolving the google.protobuf.* types.

It does appear to work if you provide the -proto ./proto/example_api.proto argument but this kind of defeats the point of implementing the reflection API because I don't want to ship the .proto file with the client.

$ grpcurl -plaintext -proto src/proto/example_api.proto localhost:50051 describe com.example.api.v1.ExampleAPI
com.example.api.v1.ExampleAPI is a service:
service ExampleAPI {
  rpc Exec ( .com.example.api.v1.Request ) returns ( .com.example.api.v1.Response );
}

.proto file

// ./proto/example_api.proto
syntax = "proto3";

package com.example.api.v1;

import "google/protobuf/struct.proto";

message Request {
  google.protobuf.Struct body = 2;
}

message Response {
  google.protobuf.Struct body = 2;
}

service ExampleAPI {
  rpc Exec(Request) returns (Response);
}

Server code

// ./server.js
const path = require('path');
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');
const { default: wrapServerWithReflection } = require('grpc-node-server-reflection');

const server = wrapServerWithReflection(new grpc.Server());
const protoPath = path.join(__dirname, 'proto', 'example_api.proto');
const packageDefinition = protoLoader.loadSync(protoPath);
const serviceDescriptor = grpc.loadPackageDefinition(packageDefinition);
server.addService(
    serviceDescriptor.com.example.api.v1.ExampleAPI.service, {
        Exec: (call, callback) => {
            console.log(call.request);
            callback(null, {});
        }
    }
);
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
server.start();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.