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.

http request called more than once when biding to view with `async` Pipe

See original GitHub issue

Running watchQuery with a query, and use the observable returned from the request this way, inside a component:

const obs = this.apollo.watchQuery(...);
this.c$ = obs.map(data => data.a.b.c);
this.d$ = obs.map(data => data.a.b.d);

Then, in the template, I am using:

<div>
C Value: {{ $c | async }}
D Values: {{ $d | async }}
</div>

And it causing the apollo-client to execute the http request of the query twice.

I found a temporary workaround:

const obs = this.apollo.watchQuery(...).publishCount(1).refCount();

@Urigo @eitanfr @tomermoshe @kamilkisiela

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
eitanfrcommented, Sep 14, 2017

@dotansimha I also think that the best thing is to call publish() or share() yourself, this way you give the user the freedom to what ever he wants with his RxObserver

0reactions
kamilkisielacommented, Aug 30, 2018

Okay, I discussed the issue with @darkbasic and it seems like it has been fixed since then.

Reproduction:

If some of you can create a test or even a simple reproduction please @mention me here so I reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular - Observable with async pipe used multiple times in ...
Using the async pipe makes handling subscriptions much easier. It automatically handles unsubscribing unlike subscribing in the component.
Read more >
http request called more than once when biding to view with ...
Running watchQuery with a query, and use the observable returned from the request this way, inside a component: const obs = this.apollo.
Read more >
How to avoid multiple async pipes in Angular | by Yury Katkov
Use ngIf trick for observable expansion and combine it with grouping the observable into a single object.
Read more >
Angular pitfall: Multiple HTTP requests with RxJS and ...
Each async pipe triggers a new HTTP request, because each result$ | async creates a new subscription/stream to the result$ Observable.
Read more >
AsyncPipe - Angular
The async pipe subscribes to an Observable or Promise and returns the latest value it has emitted. When a new value is emitted,...
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