MCPcopy Create free account
hub / github.com/TanStack/query / fetchQuery

Method fetchQuery

packages/query-core/src/queryClient.ts:651–680  ·  view source on GitHub ↗

* Fetches and caches a query, or returns its cached data if it isn't stale. Unlike in observers, * the fetch isn't retried unless `retry` is set. * @param options - The query options, including the `queryKey` and the `queryFn` used if the * query needs to fetch. * @returns A promise that

(
    options: FetchQueryOptions<
      TQueryFnData,
      TError,
      TData,
      TQueryKey,
      TPageParam
    >,
  )

Source from the content-addressed store, hash-verified

649 * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.
650 */
651 fetchQuery<
652 TQueryFnData,
653 TError = DefaultError,
654 TData = TQueryFnData,
655 TQueryKey extends QueryKey = QueryKey,
656 TPageParam = never,
657 >(
658 options: FetchQueryOptions<
659 TQueryFnData,
660 TError,
661 TData,
662 TQueryKey,
663 TPageParam
664 >,
665 ): Promise<TData> {
666 const defaultedOptions = this.defaultQueryOptions(options)
667
668 // https://github.com/tannerlinsley/react-query/issues/652
669 if (defaultedOptions.retry === undefined) {
670 defaultedOptions.retry = false
671 }
672
673 const query = this.#queryCache.build(this, defaultedOptions)
674
675 return query.isStaleByTime(
676 resolveQueryValue(defaultedOptions.staleTime, query),
677 )
678 ? query.fetch(defaultedOptions)
679 : Promise.resolve(query.state.data as TData)
680 }
681
682 /**
683 * Fetches and caches a query like {@link QueryClient#fetchQuery}, but ignores the result and any

Callers 15

ensureQueryDataMethod · 0.95
prefetchQueryMethod · 0.95
fetchInfiniteQueryMethod · 0.95
WithKnownParametersFunction · 0.45
WithIdentifiersFunction · 0.45
WithKnownParametersFunction · 0.45
WithIdentifiersFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45

Calls 5

defaultQueryOptionsMethod · 0.95
resolveQueryValueFunction · 0.90
isStaleByTimeMethod · 0.80
buildMethod · 0.45
fetchMethod · 0.45

Tested by

no test coverage detected