kamilkisiela / apollo-angular

A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
https://apollo-angular.com
MIT License
1.5k stars 309 forks source link

`fetch` and `watch` for the same query at the same time produce unexpected results #1820

Closed diesieben07 closed 1 week ago

diesieben07 commented 1 year ago

Describe the bug

If a watch subscription for a query is active, a fetch on the same query cannot complete until the watch completes. This is, because ApolloClient will use the same underlying "Concast" (their multicasting observable implementation) for both queries. fetch will then wait for this Concast's promise, which will not complete until the whole Concast is complete, which cannot happen until the watch is complete. I am not sure if it is worth working around this or if this should just be documented. But one of the two should be done. I just spent the past two hours digging through the source and the debugger trying to figure out why my Observable did not trigger.

To Reproduce Steps to reproduce the behavior:

  1. Subscribe to watch().valueChanges on a Apollo.Query.
  2. At the same time, subscribe to fetch() on the same Apollo.Query
  3. Observe the 2nd subscription never triggering.

Expected behavior

A fetch should trigger, even if a watch is active for the same query at the same time.

Environment:

β”œβ”€β”€ @angular/cli@14.0.7
β”œβ”€β”€ @angular/core@14.2.4
β”œβ”€β”€ @apollo/client@3.6.10
β”œβ”€β”€ apollo-angular@4.0.1
β”œβ”€β”€ graphql@16.6.0
└── typescript@4.7.4
PowerKiKi commented 1 week ago

This seems like an issue in the underlying lib @apollo/client. Please file an issue over there.