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

Service Client generated doesn't support Promise response #243

Open
chin2km opened this issue Aug 19, 2020 · 10 comments
Open

Service Client generated doesn't support Promise response #243

chin2km opened this issue Aug 19, 2020 · 10 comments

Comments

@chin2km
Copy link

chin2km commented Aug 19, 2020

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

@auzhva
Copy link

auzhva commented Aug 23, 2020

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 grpc/grpc-web#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,

@roboslone
Copy link

+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).

@mieubrisse
Copy link

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

@GoodMorningA1i
Copy link

GoodMorningA1i commented Aug 5, 2021

+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: microsoft/TypeScript#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.

@agnislav
Copy link

+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.

@stale
Copy link

stale bot commented Apr 17, 2022

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 stale bot added the wontfix label Apr 17, 2022
@roboslone
Copy link

It's still relevant.

@stale stale bot removed the wontfix label Apr 17, 2022
@OnkelTem
Copy link

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

@Goldziher
Copy link

this is really a problem, any progress?

@reececomo
Copy link

reececomo commented Jun 5, 2024

grpc-web implements a pretty good Promise-based client: grpc_generator.cc#L742

edit: to clarify, just as a point of reference. It uses XMLHttpRequest so not suitable for node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants