Skip to content

Latest commit

 

History

History
44 lines (36 loc) · 1.95 KB

File metadata and controls

44 lines (36 loc) · 1.95 KB
sidebar_label ensureQueryData()

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, body } | QueryKey | void
      • Required, OpenAPI request parameters for the query, strictly-typed ✨
      • parameters will be used to generate the QueryKey
      • For operations generated with --queryable-write-operations, query parameters may also include body
      • In that mode, body is part of the query key and cache identity for query-client methods
      • Mutation calls keep body as a separate top-level argument
      • requestFn?: RequestFn
        • Optional, a function that will be used to execute the request
      • revalidateIfStale?: boolean
        • Optional, defaults to false. If true, stale data will be revalidated in the background while returning cached data immediately
      • baseUrl?: string
        • Optional, the base URL of the API
      • ...fetchQueryOptions?: FetchQueryOptions
        • Optional, represents the rest options of the fetchQuery(...) 🌴 method
        • queryOptions.queryFn could be provided instead of requestFn
        • queryOptions.queryKey could be provided instead of parameters

Returns

result: Promise<TData> - The result of the query execution