Query Filters

Some methods within Svelte Query accept a QueryFilters object. A query filter is an object with certain conditions to match a query with:

// Cancel all queries
await queryClient.cancelQueries()
// Remove all inactive queries
queryClient.removeQueries('posts', { inactive: true })
// Refetch all active queries
await queryClient.refetchQueries({ active: true })
// Refetch all active queries that begin with `post` in the key
await queryClient.refetchQueries('posts', { active: true })

A query filter object supports the following properties:

  • exact?: boolean
    • If you don't want to search queries inclusively by query key, you can pass the exact: true option to return only the query with the exact query key you have passed.
  • active?: boolean
    • When set to true it will match active queries.
    • When set to false it will match inactive queries.
  • inactive?: boolean
    • When set to true it will match inactive queries.
    • When set to false it will match active queries.
  • stale?: boolean
    • When set to true it will match stale queries.
    • When set to false it will match fresh queries.
  • fetching?: boolean
    • When set to true it will match queries that are currently fetching.
    • When set to false it will match queries that are not fetching.
  • predicate?: (query: Query) => boolean
    • This predicate function will be called for every single query in the cache and be expected to return truthy for queries that are found.
  • queryKey?: QueryKey
    • Set this property to define a query key to match on.
Was this page helpful?

Subscribe to our newsletter

The latest TanStack news, articles, and resources, sent to your inbox.

    I won't send you spam.

    Unsubscribe at any time.

    © 2020 Tanner Linsley. All rights reserved.