T
TanStack4y ago
sensitive-blue

How to update segments of cache with related queries (or graphQL like)

Hey! I'm curious about how to update cache when different queries update the same resource. 2 quick examples: - i have getTodos() and get Todo(id) => how to make them update each other? For example if i just loaded todo #13, if i go to the list of todos no need to query it again - I query nested entities, for example Book>Author. And then lets say i query Author in a different query. ideally i would love to tell react query to check the ids of the objects, and update them accordingly
3 Replies
grubby-red
grubby-red4y ago
You need to do it manually with setQueryData, or just invalidate and let it refetch
sensitive-blue
sensitive-blueOP4y ago
I see. so for example onSuccess of the Todo(id) query, i run setQueryData of the getAllTodos()'s key to update that one. Am i right? Or on success, invalidate the impacted queries?
grubby-red
grubby-red4y ago
Yes

Did you find this page helpful?