T
TanStack3y ago
fascinating-indigo

Refetch all the queries on mutation

I am wondering how should I make this work
const { data: employeeDetails } = api.employee.getEmployee.useQuery();
const { mutate: signOut, isSuccess } = api.user.signOut.useMutation();
const { data: offersReceived } = api.employee.getOffers.useQuery();
const { data: latestPostedJobs } = api.post.getPosts.useQuery({
latest: true,
});
const { data: jobsAppliedTo } = api.post.postsAppliedTo.useQuery();
const { data: activeJobs } = api.employee.hiredTo.useQuery();
const { data: employeeDetails } = api.employee.getEmployee.useQuery();
const { mutate: signOut, isSuccess } = api.user.signOut.useMutation();
const { data: offersReceived } = api.employee.getOffers.useQuery();
const { data: latestPostedJobs } = api.post.getPosts.useQuery({
latest: true,
});
const { data: jobsAppliedTo } = api.post.postsAppliedTo.useQuery();
const { data: activeJobs } = api.employee.hiredTo.useQuery();
I wanna basically refetch all these queries after my mutation completes (for all)
5 Replies
fascinating-indigo
fascinating-indigoOP3y ago
the only option I am seeing is refetching indiviually after success of each mutation
wise-white
wise-white3y ago
Hi. For such a usecase you should invalidate queries using the queryClient invalidateQueries method.
fascinating-indigo
fascinating-indigoOP3y ago
Mhm but wouldnt that invalidate all the queries?
wise-white
wise-white3y ago
All the queries matching the queryKey you pass to invalidateQueries
fascinating-indigo
fascinating-indigoOP3y ago
yea I guess that's the only option

Did you find this page helpful?