Skip to main content
Version: 2.x

ensureInfiniteQueryData(...)

The ensureInfiniteQueryData method is designed to fetch or retrieve cached data for an infinite query. If the specified query data is not already cached, it will automatically call fetchInfiniteQuery to fetch the data and return the result.

To understand how ensureInfiniteQueryData manages infinite queries, refer to the TanStack queryClient.ensureInfiniteQueryData ๐ŸŒด documentation.

const result = api.<service>.<operation>.ensureInfiniteQueryData({
parameters,
requestFn,
baseUrl,
revalidateIfStale: false,
...fetchInfiniteQueryOptions,
});

Argumentsโ€‹

    • parameters: { path, query, header } | QueryKey | void
      • OpenAPI request parameters for the query, strictly-typed โœจ
      • parameters will be used to generate the QueryKey
    • fetchInfiniteQueryOptions?: FetchInfiniteQueryOptions
      • requestFn?: RequestFn
        • Optional, a function that will be used to execute the request
        • The function should be provided, otherwise it will throw an error if default queryFn is not set previously using QueryClient.setDefaultOptions(...) method
      • baseUrl?: string
        • Optional, the base URL of the API
      • revalidateIfStale?: boolean
        • Optional, defaults to false. If true, stale data will be revalidated in the background while returning cached data immediately.
      • ...fetchInfiniteQueryOptions?: FetchInfiniteQueryOptions
      • Optional, represents the rest options of the fetchInfiniteQuery(...) ๐ŸŒด method
        • queryOptions.queryFn could be provided instead of requestFn
        • queryOptions.queryKey could be provided instead of parameters

Returnsโ€‹

Promise<InfiniteData<T>> - A promise of the paginated data and page parameters