ts-protoc-gen icon indicating copy to clipboard operation
ts-protoc-gen copied to clipboard

Service Client generated doesn't support Promise response

Open chin2km opened this issue 4 years ago • 10 comments

The generated service client doesn't give a Promise response, instead, it requires callbacks for handling the response from the server.

Versions of relevant software used latest

What happened This is a sample generated client code. https://github.com/improbable-eng/ts-protoc-gen/blob/master/examples/generated-grpc-web/proto/examplecom/simple_service_pb_service.d.ts

From the types you can see the when you execute a generated client, you need to pass the request object and a callback as a second parameter to handle the response.

What you expected to happen

Expects that when you execute a service client, it give a promise response instead

chin2km avatar Aug 19 '20 08:08 chin2km

To add to this,

There is an old issue in the tracker as #59 which is stated that it will not be fixed. Mainly because willingness not to break compatibility with official node.

And,

Since recently official client added support for client_type=PromiseClient. See https://github.com/grpc/grpc-web/pull/354 And this is now part of official node release.

So would it be possible to reconsider #59 and possibly provide something similar here?

Thank you,

auzhva avatar Aug 23 '20 07:08 auzhva

+1 Promise-based client would be very nice. For example, it could be used with Redux and redux-promise-middleware with no need to wrap original methods (which is really nasty, since they need to be bound to client).

roboslone avatar Oct 12 '20 16:10 roboslone

Adding another +1 here; promises would be much, much nicer

mieubrisse avatar Aug 04 '21 23:08 mieubrisse

+1

The problem faced: Was trying to convert a grpc binding method that had a callback into a promise using util.Promisfy(...), but util.Promisfy(...) was not able to recognize the method signature of my grpc binding method. The reason why this is happening is because the outputted grpc binding method (..._grpc_pb.d.ts) is an overloaded function.

This issue is talked about in further detail here: https://github.com/microsoft/TypeScript/issues/26048

Solution I am following right now as a substitute is to manually construct promises like done here: https://medium.com/expedia-group-tech/the-weird-world-of-grpc-tooling-for-node-js-part-3-d994de02bedc#a-dynamic-client OR here: https://stackoverflow.com/questions/62220154/gprc-client-async-response-nodejs.

GoodMorningA1i avatar Aug 05 '21 18:08 GoodMorningA1i

+1. We've got quite complicated logic and currently, there's a choice between callback hell and much more complicated logic spread between a number of functions.

agnislav avatar Nov 29 '21 21:11 agnislav

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 17 '22 07:04 stale[bot]

It's still relevant.

roboslone avatar Apr 17 '22 08:04 roboslone

So what is the current approach? For every generated method make a wrapper?

OnkelTem avatar Aug 19 '22 09:08 OnkelTem

this is really a problem, any progress?

Goldziher avatar Sep 06 '23 09:09 Goldziher