-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
It would be helpful to have a built-in utility that enables updating all cached query results for a given endpoint, regardless of the specific query arguments used. This pattern comes up in many applications where a change to a single resource (e.g. after a mutation) needs to be reflected across multiple cached queries β such as paginated lists, filtered views, or entity detail views.
Currently, this requires manually accessing the cache, identifying all relevant entries, and iterating through them with updateQueryData
. While possible, this approach adds boilerplate and increases the risk of inconsistencies. A built-in method (e.g. updateAllQueryData
) could simplify this common use case and help encourage consistent cache update strategies.
Boilerplate code π
mutationResult.then(({ data }) => {
cachedArgs.forEach((args) => {
dispatch(
api.util.updateQueryData('getItems', args, (draft) => {
const item = draft.items.find((i) => i.id === data.id);
if (item) {
Object.assign(item, data);
}
})
);
});
});
Hypothetical Build-in Code π
mutationResult.then(({ data }) => {
dispatch(
api.util.updateAllQueryData('getItems', (draft) => {
const item = draft.items.find((i) => i.id === data.id);
if (item) {
Object.assign(item, data);
}
})
);
});