question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why doesn't .query() return a Promise?

See original GitHub issue

I’ve asked this here https://github.com/apollographql/apollo-client/issues/2561#event-1343477916 and I was told that apollo-client itself returns a promise on .query() - why doesn’t apollo-angular do the same as apollo-client?

Here’s the question I asked in the apollo-client repo:

Just wanted to ask for the reasen why .query() does not return a Promise

I always end up calling .toPromise() because I don’t want to unsubscribe something that is executed once anyway.

And if there’s a good reason for it, does this mean, calling toPromise() is bad practice?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilkisielacommented, Nov 16, 2017

It’s angular integration, it means there are Observable that can be chained. The whole ecosystem is built on Observables instead of Promises.

0reactions
justinmchasecommented, Dec 10, 2021

Instead of calling .subscribe() you can just call .toPromise() and then it works as expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with promises and mysql query return value
You can just return the promise itself. function query(query:string):Promise<string> { var sendrequest = (query:string):Promise<string> ...
Read more >
Why doesn't .query() return a Promise? #2561
I always end up calling .toPromise() because I don't want to unsubscribe something that is executed once anyway. And if there's a good...
Read more >
Promise.all() - JavaScript - MDN Web Docs
The Promise.all() method takes an iterable of promises as input and returns a single Promise . This returned promise fulfills when all of ......
Read more >
Mongoose v6.8.1: Promises
Mongoose queries are not promises. They have a .then() function for co and async/await as a convenience. If you need a fully-fledged promise,...
Read more >
Sync, async, and promises | Cloud Functions for Firebase
When you return a JavaScript promise to a function, that function keeps running until the promise is resolved or rejected. To indicate that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found