Replies: 2 comments
-
|
Implementation submitted in #10540. |
Beta Was this translation helpful? Give feedback.
-
|
A query generally doesn’t have information about what triggered the fetch, we don’t store that. Adding this to Listening to the low-level query events is a pretty advanced use-case so I’m not willing to add that much to the lib just for this case, sorry. The events we emit are primarily for the devtools, but it’s great that you find them useful as well. Also, You’re also mixing up a bunch of things, like:
This feels hallucinated, as I’m gonna close the PR for those reasons. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
queryCache.subscribeexposes what happened to the cache — but never why or from where. When an{ type: 'updated', action: { type: 'invalidate' } }event fires, all caller context has been discarded. Every subscriber sees the same opaque signal regardless of what triggered the invalidation.This makes it impossible to build composable cache observers without external bookkeeping.
Proposed API
Add an optional
metafield to the second argument ofinvalidateQueries— distinct fromfilters.meta, which already means "filter queries by their meta":The value would flow through to the action seen in
queryCache.subscribe:Use Cases
1. Observability and structured logging
Applications that log cache activity today can only record that a query was invalidated — not what caused it. With
meta, a single cache subscriber can produce structured logs attributing each invalidation to a mutation, a WebSocket event, a polling tick, or a user action, without any out-of-band coordination.2. Real-time sync — suppressing echoes
When invalidations are broadcast across tabs or clients (BroadcastChannel, WebSocket, MQTT), a subscriber that re-broadcasts cache events must distinguish locally-originated invalidations from remotely-received ones. Without
metaon the action, there is no clean way to make that distinction at the subscriber — the two cases are indistinguishable from the event alone.Backwards Compatibility
Fully additive.
metais optional and defaults toundefined. TheInvalidateActionshape becomes{ type: 'invalidate', meta?: QueryMeta }. No existing call site or subscriber is affected.Implementation
Thread
options.metafrominvalidateQueriesintoquery.invalidate(meta)and dispatch{ type: 'invalidate', meta }. The same pattern could be extended toresetQueriesandrefetchQueriesin a follow-up.Beta Was this translation helpful? Give feedback.
All reactions