setQueriesData(...)
The synchronous function that can be used to immediately update cached data of multiple queries by using filter. Only queries that match the passed QueryKey will be updated. No new cache entries will be created. See the TanStack queryClient.setQueriesData ๐ด documentation.
- Without
options - With
options
const data = qraft.<service>.<operation>.setQueriesData(
filters,
updater,
queryClient
);
Argumentsโ
filters: QueryFiltersByParameters | QueryFiltersByQueryKey- Required, represents the Query Filters ๐ด to be used, strictly-typed โจ
filters.parameters: { path, query, header }will be used for filtering queries by parametersfilters.infinite: booleanwill be used to filter infinite or normal queriesfilters.queryKey: QueryKeywill be used for filtering queries by QueryKey instead of parametersfilters.queryKeyandfilters.parametersare mutually exclusive
filters.predicate?: (query: Query) => booleanwill be used for filtering queries by custom predicate
updater: TData | (oldData: TData | undefined) => TData | undefined- Required updater to be used to set the data in the Query Cache
queryClient: QueryClient- Required
QueryClientinstance to use
- Required
const data = qraft.<service>.<operation>.setQueriesData(
filters,
updater,
options,
queryClient
);
Argumentsโ
filters: QueryFiltersByParameters | QueryFiltersByQueryKey
- Required, represents the Query Filters ๐ด to be used, strictly-typed โจ
filters.parameters: { path, query, header }will be used for filtering queries by parametersfilters.infinite: booleanwill be used to filter infinite or normal queriesfilters.queryKey: QueryKeywill be used for filtering queries by QueryKey instead of parametersfilters.queryKeyandfilters.parametersare mutually exclusive
filters.predicate?: (query: Query) => booleanwill be used for filtering queries by custom predicate
updater: TData | (oldData: TData | undefined) => TData | undefined- Required updater to be used to set the data in the Query Cache
options: SetQueryDataOptions- Required options to set the data in the cache
- See the TanStack queryClient.setQueriesData ๐ด documentation.
queryClient: QueryClient- Required
QueryClientinstance to use
- Required
Returnsโ
Array<TData | undefined> - The data that was set in the cache.
Exampleโ
- Without
options - With
options - With
QueryKey
const parameters = { path: { petId: 123 } };
qraft.pet.getPetById.setQueriesData(
{ parameters, infinite: false },
{ id: 123, name: 'Rex' },
queryClient
);
const pet = qraft.pet.getPetById.getQueryData(
parameters,
queryClient
);
expect(pet).toEqual({
id: 123,
name: 'Rex',
});
const pets = qraft.pet.getPetById.setQueriesData(
{ parameters: { path: { petId: 123 } }, infinite: false },
{ id: 123, name: 'Rex' },
{ updatedAt: Date.now() - 60_000 },
queryClient
);
It's also possible to use a QueryKey as an array instead of an object with {path, query, header}:
const pets = qraft.pet.getPetById.setQueriesData(
{
queryKey: [
{ method: 'get', url: '/pet/{petId}', infinite: false },
{ petId: 123 },
],
},
{ id: 123, name: 'Rex' },
queryClient
);