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

Method cancelQueries

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

* Cancels outgoing fetches for queries matching the given filters. Most useful when performing * optimistic updates, since any outgoing refetch that resolves afterwards would otherwise * overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is * reverted to

(
    filters?: QueryFilters<TTaggedQueryKey>,
    cancelOptions: CancelOptions = {},
  )

Source from the content-addressed store, hash-verified

460 * ```
461 */
462 cancelQueries<TTaggedQueryKey extends QueryKey = QueryKey>(
463 filters?: QueryFilters<TTaggedQueryKey>,
464 cancelOptions: CancelOptions = {},
465 ): Promise<void> {
466 const defaultedCancelOptions = { revert: true, ...cancelOptions }
467
468 const promises = notifyManager.batch(() =>
469 this.#queryCache
470 .findAll(filters)
471 .map((query) => query.cancel(defaultedCancelOptions)),
472 )
473
474 return Promise.all(promises).then(noop).catch(noop)
475 }
476
477 /**
478 * Marks queries matching the given filters as invalidated. Unlike

Callers 15

WithKnownParametersFunction · 0.45
WithIdentifiersFunction · 0.45
WithKnownParametersFunction · 0.45
WithIdentifiersFunction · 0.45
ExampleWithUnknownKeyFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45
ExamplesFunction · 0.45

Calls 2

cancelMethod · 0.80
findAllMethod · 0.45

Tested by

no test coverage detected