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

Method fetchQuery

packages/query-core/src/queryClient.ts:392–421  ·  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

390 * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.
391 */
392 fetchQuery<
393 TQueryFnData,
394 TError = DefaultError,
395 TData = TQueryFnData,
396 TQueryKey extends QueryKey = QueryKey,
397 TPageParam = never,
398 >(
399 options: FetchQueryOptions<
400 TQueryFnData,
401 TError,
402 TData,
403 TQueryKey,
404 TPageParam
405 >,
406 ): Promise<TData> {
407 const defaultedOptions = this.defaultQueryOptions(options)
408
409 // https://github.com/tannerlinsley/react-query/issues/652
410 if (defaultedOptions.retry === undefined) {
411 defaultedOptions.retry = false
412 }
413
414 const query = this.#queryCache.build(this, defaultedOptions)
415
416 return query.isStaleByTime(
417 resolveStaleTime(defaultedOptions.staleTime, query),
418 )
419 ? query.fetch(defaultedOptions)
420 : Promise.resolve(query.state.data as TData)
421 }
422
423 /**
424 * @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
resolveStaleTimeFunction · 0.90
isStaleByTimeMethod · 0.80
buildMethod · 0.45
fetchMethod · 0.45

Tested by

no test coverage detected