apollographql / apollo-kotlin

:rocket:  A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.
https://www.apollographql.com/docs/kotlin
MIT License
3.75k stars 650 forks source link

Debugging why an observed query is refetched #2397

Open lwasyl opened 4 years ago

lwasyl commented 4 years ago

In UI tests we're enqueueing responses for the network requests that we expect. However, sometimes Apollo makes additional requests that we don't expect (e.g. because a query doesn't fetch ID). What's the best way to monitor why Apollo is considering a query stale and in need for a network request to refetch it? I'm looking for something where I can e.g. log that a certain query is being observed and Apollo will now make a request for it, because some specific event happened/cache keys got modified

eyalw commented 3 years ago

So how can one debug this? I have this problem...

martinbonnin commented 3 years ago

Hi @eyalw 👋 that's unfortunately not easy and definitely something we want to improve.

There's some information there: https://www.apollographql.com/docs/android/essentials/normalized-cache/#troubleshooting

Also latest version (2.4.5) included https://github.com/apollographql/apollo-android/pull/2751. I'm not sure this would be reachable from apolloClient.query but you can try to read the cache directly with your query (apolloClient.apolloStore.read) and get the missing key from the exception.

If nothing helps, feel free to open a separate issue with your schema and queries and we investigate together.