ts-protoc-gen
ts-protoc-gen copied to clipboard
Service Client generated doesn't support Promise response
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
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,
+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).
Adding another +1 here; promises would be much, much nicer
+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.
+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.
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.
It's still relevant.
So what is the current approach? For every generated method make a wrapper?
this is really a problem, any progress?