Skip to main content
Version: 2.x ๐Ÿšง

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.

const data = qraft.<service>.<operation>.setQueriesData(
filters,
updater
);

Argumentsโ€‹

  1. 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 parameters
    • filters.infinite: boolean will be used to filter infinite or normal queries
    • filters.queryKey: QueryKey will be used for filtering queries by QueryKey instead of parameters
      • filters.queryKey and filters.parameters are mutually exclusive
    • filters.predicate?: (query: Query) => boolean will be used for filtering queries by custom predicate
  2. updater: TData | (oldData: TData | undefined) => TData | undefined
    • Required updater to be used to set the data in the Query Cache

Returnsโ€‹

Array<TData | undefined> - The data that was set in the cache.

Exampleโ€‹

const parameters = { path: { petId: 123 } };

qraft.pet.getPetById.setQueriesData(
{ parameters, infinite: false },
{ id: 123, name: 'Rex' }
);

const pet = qraft.pet.getPetById.getQueryData(parameters);

expect(pet).toEqual({
id: 123,
name: 'Rex',
});