Skip to main content
Version: 1.x

setQueryData(...)

The method enables direct access to the QueryClient cache to set the data for a specific Query. See the TanStack queryClient.setQueryData ๐ŸŒด documentation.

const data = qraft.<service>.<operation>.setQueryData(
parameters,
data,
queryClient
);

Argumentsโ€‹

  1. parameters: { path, query, header } | QueryKey
    • Required parameters to set the data in the Query Cache.
    • Instead of an object with {path, query, header}, you can pass a QueryKey as an array which is also strictly-typed โœจ
  2. data: TData
    • Required data to set in the cache
  3. queryClient: QueryClient
    • Required QueryClient instance to use

Returnsโ€‹

The data from the updater or undefined if it returns nothing, strictly-typed โœจ

Exampleโ€‹

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

qraft.pet.getPetById.setQueryData(
parameters,
{ id: 123, name: 'Rex' },
queryClient
);

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

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