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

Method cancelQueries

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

432 * ```
433 */
434 cancelQueries<TTaggedQueryKey extends QueryKey = QueryKey>(
435 filters?: QueryFilters<TTaggedQueryKey>,
436 cancelOptions: CancelOptions = {},
437 ): Promise<void> {
438 const defaultedCancelOptions = { revert: true, ...cancelOptions }
439
440 const promises = notifyManager.batch(() =>
441 this.#queryCache
442 .findAll(filters)
443 .map((query) => query.cancel(defaultedCancelOptions)),
444 )
445
446 return Promise.all(promises).then(noop).catch(noop)
447 }
448
449 /**
450 * 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