-
Hi. I'd like to be able to store an errored mutation in the offline cache. I have a requirement where particular failed mutation data should never be lost. It would be very convenient if i could store it in mutation cache. My first question is, is there any existing way to configure RQ to store errored mutations in persisted cache? Assuming there isn't, I'd like to be able to use the mutationCache API to do this but i'm finding it limited. Ideally I'd just like to update the state of the mutation (via So i've tried to remove the existing mutation from cache, then adding a new one with I'd like to do So i'm not sure how I can achieve this. Got any pointers? Here's an example hook demonstrating what i'd like to do. export function useFormSubmit() {
const queryClient = useQueryClient();
const mutationKey: MutationKey = [useSubmitForm.name, Date.now()];
const mutationVariables = useRef<SubmitFormVariables>();
const mutation = useSubmitForm({
mutationKey,
onError(error, variables, context) {
const mutationCache = queryClient.getMutationCache();
const existingMutationInCache = mutationCache.find({
predicate: (m) =>
m.options.mutationKey?.[0] === mutationKey[0] &&
m.options.mutationKey?.[1] === mutationKey[1],
});
if (existingMutationInCache) {
mutationCache.remove(existingMutationInCache);
// This doesn't seem to save variables in cache
mutationCache.build(
queryClient,
{
mutationKey: mutationKey,
},
{
variables: mutationVariables.current,
data: undefined,
error,
context,
status: 'error',
failureCount: DEFAULT_RETRIES,
failureReason: error,
isPaused: true,
},
);
}
},
});
const mutate: UseMutateFunction<
string,
SubmitFormError,
SubmitFormVariables,
unknown
> = (variables, ...args) => {
mutationVariables.current = variables;
return mutation.mutate(variables, ...args);
};
return {
...mutation,
mutate,
};
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
After doing some more investigation I think storing errored mutations in the offline cache is the wrong approach. RQ by design will want to retry anything that's in the cache + online. So we can't permanently store "isPaused" errors in the cache. I will store these mutations somewhere else. |
Beta Was this translation helpful? Give feedback.
After doing some more investigation I think storing errored mutations in the offline cache is the wrong approach. RQ by design will want to retry anything that's in the cache + online. So we can't permanently store "isPaused" errors in the cache. I will store these mutations somewhere else.