Description
Issue Description
When the cache is reset any active (watched) queries will automatically be refetched.
If the watchQuery
call uses notifiyOnNetworkStatusChange: true
, the refetch will trigger it emitting with { loading: true }
. However if the refetch then returns the same data that was there before the cache reset, the Observable will not emit again, meaning it gets stuck "loading".
If returnPartialData
is set to true, this behavior is not observed.
Link to Reproduction
https://github.com/diesieben07/apollo-cache-purge-repro
Reproduction Steps
First, watch a query with notifyOnNetworkStatusChange: true
:
client.watchQuery({
query: gql`
query GetMessage {
message
}
`,
notifyOnNetworkStatusChange: true,
}).subscribe({
next: v => console.log('data', v)
});
Once it has emitted, clear the Apollo cache:
client.cache.reset()
If the query refetch returns the same data, observe how the Observable will emit a new loading notification, but fail to emit data again after that:
Server returning { data: { message: 'Hello World' } }
data { data: { message: 'Hello World' }, loading: false, networkStatus: 7 }
data { data: {}, loading: true, networkStatus: 1, partial: true }
Server returning { data: { message: 'Hello World' } }
Note that the refetch is happening and Apollo does write it into its cache, it just does not notify the query again.
@apollo/client
version
3.13.8