ensureQueryData(...)
The ensureQueryData method retrieves cached data for a given query or fetches it if the data is not already available
in the cache. This ensures that data is prepared and cached ahead of time, improving efficiency and performance.
To understand how ensureQueryData works, refer to the TanStack
queryClient.ensureQueryData 🌴 documentation.
const result = api.<service>.<operation>.ensureQueryData({
parameters,
requestFn,
baseUrl,
revalidateIfStale: false,
...fetchQueryOptions,
});
Arguments​
-
parameters: { path, query, header } | QueryKey | void- Required, OpenAPI request parameters for the query, strictly-typed ✨
parameterswill be used to generate theQueryKeyrequestFn?: RequestFn- Optional, a function that will be used to execute the request
revalidateIfStale?: boolean- Optional, defaults to
false. Iftrue, stale data will be revalidated in the background while returning cached data immediately
- Optional, defaults to
baseUrl?: string- Optional, the base URL of the API
...fetchQueryOptions?: FetchQueryOptions- Optional, represents the rest options of the fetchQuery(...) 🌴 method
queryOptions.queryFncould be provided instead ofrequestFnqueryOptions.queryKeycould be provided instead ofparameters
Returns​
result: Promise<TData> - The result of the query execution