Skip to content

Support for multiple .proto files #6

Open
@teone

Description

@teone

Hi @emzeq,
and first of all thanks for this tool!

I am trying to generate a graphql schema starting from protobuf, and it works fine as long as the .proto file does not contain any import.

I have a situation similar to this one:

// api/v1/a.proto
import "api/v1/b.proto";
message A {
  repeated b.B foo = 1;
}

// api/v1/b.proto
message B {
  string bar = 1;
}

If I run the compiler on b.proto I get the expected output, if I run it on a.proto I get this message:

proto2graphql --input api/v1/a.proto 
/usr/local/lib/node_modules/proto2graphql/node_modules/protobufjs/src/namespace.js:411
        throw Error("no such Type or Enum '" + path + "' in " + this);
        ^

Error: no such Type or Enum 'b.B' in Type .a.A

Is there any plan to support local imports in the future?

I suspect that it might be something happening in

// Provide resolver for protobuf's well-known types
root.resolvePath = function(origin, target) {
if (target.startsWith("google/protobuf/")) {
return path.join(protosDir, target);
}
return defaultResolver(origin, target);
};
but I'm not very familiar with protobuf in Javascript.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions