On my api I have two mutations and strangely, one of them does trigger the refetch but the other doesn't and I have no clue why. Both mutations make their networks calls and changes are reflected in the server.
Here's my api definition.
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/dist/query/react";
import Sample from "core/types/Sample";
import getApiURL from "core/utils/getApiURL";
export const lithologyApi = createApi({
baseQuery: fetchBaseQuery({ baseUrl: getApiURL() }),
tagTypes: ["Samples"],
endpoints: build => ({
addSample: build.mutation<Sample, Sample>({
query: sample => ({
url: `lithology/add-sample`,
method: "POST",
body: sample,
}),
invalidatesTags: ["Samples"],
}),
getSamples: build.query<Sample[], void>({
query: () => "lithology/get-samples",
providesTags: ["Samples"],
}),
deleteSample: build.mutation<void, number>({
query: id => ({ url: `lithology/delete-sample/${id}`, method: "DELETE" }),
invalidatesTags: ["Samples"],
}),
}),
});
export const {
useAddSampleMutation,
useGetSamplesQuery,
useDeleteSampleMutation,
} = lithologyApi;
I don't know if it's relevant but the mutation that succesfully invalidates (addSample
) it's in a different component, while the one that doesn't (deleteSample
) it's in the same (I've already tried moving it to another component and it didn't work anyways).
"@reduxjs/toolkit/query/react"
but that won't solve the problem. Are all of these really in onecreateApi
call or did you simplify that for the Stackoverflow question? Also, just to make sure: the middleware is registered? – HighpriceddeleteSample
mutation callback makes the network request, it just doesn't trigger the invalidation forgetSamples
(whichaddSamples
does). – NousisError
state? I have an assumption. – Highpriced