SafetyCulture / grpc-web-devtools

Chrome & Firefox Browser extension to aid gRPC-Web development
MIT License
402 stars 51 forks source link

Bug/Feature request: Message with an Any type cause errors because of missing typeRegistry #153

Open 0xR opened 1 year ago

0xR commented 1 year ago

I'm getting the following error:

cannot encode message google.protobuf.Any to JSON: "type.googleapis.com/com.company.MyType" is not in the type registry

This is caused because the typeRegistry is not provided from grpc-web-devtools.

In my own code I avoid the error by writing this:

const typeRegistry = createRegistry(MyType);

...

const myMessage = new MyMessage({
  some: 'data',
  myType: Any.pack(new MyType({})),
}).toJson({ typeRegistry });

It is caused by this code calling toJson without a type registry. https://github.com/SafetyCulture/grpc-web-devtools/blob/7b97172fcf17ffb1d8c6f5a080ace9e06d313530/public/connect-web-interceptor.js#L13-L14

It would be nice if it's possible to supply a type registry to the grpc-web-devtools.

Docs for more info in Any Docs for more info on Registries

rafaoliverce commented 10 months ago

That happens in our project, too.

Thanks for this extension! Very useful!