Skip to content

gRPC Reflection doesn't support maps #519

@lynxtaa

Description

@lynxtaa

grpcurl errors if reflection is enabled and protobuf has map fields defined:

$ grpcurl -plaintext localhost:5000 helloworld.Greeter/SayHello

Error invoking method "helloworld.Greeter/SayHello": failed to query for service descriptor "helloworld.Greeter": proto:
message field "helloworld.HelloReply.field" is an invalid map: incorrect implicit map entry name
// helloworld.proto

syntax = "proto3";

package helloworld;

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  map<string, string> field = 1;
}
// server.mjs

import {
    Server,
    loadPackageDefinition,
    ServerCredentials,
} from '@grpc/grpc-js';
import { loadSync } from '@grpc/proto-loader';
import reflection from '@grpc/reflection';

const PROTO_PATH = './helloworld.proto';

const server = new Server();
const packageDefinition = loadSync(PROTO_PATH);
const proto = loadPackageDefinition(packageDefinition);
new reflection.ReflectionService(packageDefinition).addToServer(server);

server.addService(proto.helloworld.Greeter.service, {
    sayHello: (call, callback) => {
        callback(null, { message: 'Hello' });
    },
});

server.bindAsync('localhost:5000', ServerCredentials.createInsecure(), () => {
    server.start();
});

In Postman and Insomnia reflection works fine. Removing map field also helps

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions