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

Method fetchQuery

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

* @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.

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

Source from the content-addressed store, hash-verified

607 * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.
608 */
609 fetchQuery<
610 TQueryFnData,
611 TError = DefaultError,
612 TData = TQueryFnData,
613 TQueryKey extends QueryKey = QueryKey,
614 TPageParam = never,
615 >(
616 options: FetchQueryOptions<
617 TQueryFnData,
618 TError,
619 TData,
620 TQueryKey,
621 TPageParam
622 >,
623 ): Promise<TData> {
624 const defaultedOptions = this.defaultQueryOptions(options)
625
626 // https://github.com/tannerlinsley/react-query/issues/652
627 if (defaultedOptions.retry === undefined) {
628 defaultedOptions.retry = false
629 }
630
631 const query = this.#queryCache.build(this, defaultedOptions)
632
633 return query.isStaleByTime(
634 resolveQueryValue(defaultedOptions.staleTime, query),
635 )
636 ? query.fetch(defaultedOptions)
637 : Promise.resolve(query.state.data as TData)
638 }
639
640 /**
641 * @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.

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