Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support grpc-web services #2

Closed
stephenh opened this issue Aug 22, 2019 · 3 comments
Closed

Support grpc-web services #2

stephenh opened this issue Aug 22, 2019 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@stephenh
Copy link
Owner

stephenh commented Aug 22, 2019

Currently we only support twirp RPC services.

(This was hence been implemented for grpcjs and grpc-web.)

@stephenh stephenh added the help wanted Extra attention is needed label May 3, 2020
@stephenh
Copy link
Owner Author

stephenh commented May 3, 2020

Added "help wanted" label b/c I don't personally use grpc services right now.

@hendrikhofstadt
Copy link

I managed to make this work with grpc-web with some minor changes to methodInfo in the generated grpc-web code.

The trick is to turn this piece of the generated code:

methodInfoEcho = new grpcWeb.AbstractClientBase.MethodInfo(
    EchoResponse,
    (request: EchoRequest) => {
      return request.serializeBinary();
    },
    EchoResponse.deserializeBinary
  );

into that:

methodInfoEcho = new grpcWeb.AbstractClientBase.MethodInfo(
    EchoResponse,
    (request: EchoRequest) => {
        return EchoRequest.encode(request).finish();
    },
    (response: Uint8Array) => {
      return EchoResponse.decode(response);
    },
);

Since this library is using interfaces, there's no clean way I could imagine to make this work by just modifying ts-proto because I can't implement (de-)serialize on the interfaces. My current plan is to port some of the grpc-web codegen over to this repo so the ts-proto gen can also generate grpc-web compatible services.

@stephenh what are your thoughts on this? If you'd be ok with having some grpc service generation code (togglable between twirp and grpc) I'd try to contribute that once I have some time to spare.

@stephenh
Copy link
Owner Author

@hendrikhofstadt sorry for the really late follow up here; I hadn't / generally don't use grpc-web, so didn't have anything really useful to say. :-)

That said, I had a client request grpc-web support, so I just released v1.28.0 that adds a outputClientImpl=grpc-web flag that will a) use the improbable-eng/grpc-web runtime library but b) only use ts-proto's code generation output (i.e. doesn't require anything from the ts-protoc-gen output).

In retrospect, your serializeBinary/deserializeBinary suspicions were exactly right.

Would be great if you could check out the latest version and see if it works for your use case / setup. Would be great to get a 2nd set of eyes and users on it, I've admittedly only done a few trivial unary-only RPC calls so far.

Thanks!

@stephenh stephenh changed the title Support grpc services Support grpc-web services Aug 20, 2020
zfy0701 added a commit to sentioxyz/ts-proto that referenced this issue Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants