Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

matchQuery.md

58 lines1.9 KB

1---
2id: matchQuery
3title: matchQuery
4---
5​
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7​
8```ts
9function matchQuery(filters: QueryFilters, query: Query<any, any, any, any>): boolean;
10```
11​
12Defined in: [packages/query-core/src/utils.ts:205](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L205)
13​
14Checks whether a query matches the given [QueryFilters](../interfaces/QueryFilters.md).
15Every filter that is specified must match; filters that are left unspecified are ignored.
16​
17## Parameters
18​
19### filters
20​
21[`QueryFilters`](../interfaces/QueryFilters.md)
22​
23The filters to check the query against.
24​
25<a id="filters-properties"></a>
26​
27#### `filters` properties
28​
29| Property | Type | Default value | Description |
30| ------ | ------ | ------ | ------ |
31| <a id="filters-property-exact"></a> `exact?` | `boolean` | `undefined` | Match query key exactly |
32| <a id="filters-property-fetchstatus"></a> `fetchStatus?` | `"fetching"` \| `"paused"` \| `"idle"` | `undefined` | Include queries matching their fetchStatus |
33| <a id="filters-property-predicate"></a> `predicate?` | (`query`: [`Query`](../classes/Query.md)) => `boolean` | `undefined` | Include queries matching this predicate function |
34| <a id="filters-property-querykey"></a> `queryKey?` | `TQueryKey` \| `TuplePrefixes`\<`TQueryKey`\> | `undefined` | Include queries matching this query key |
35| <a id="filters-property-stale"></a> `stale?` | `boolean` | `undefined` | Include or exclude stale queries |
36| <a id="filters-property-type"></a> `type?` | `QueryTypeFilter` | `'all'` | Filter to active queries, inactive queries or all queries |
37​
38### query
39​
40[`Query`](../classes/Query.md)\<`any`, `any`, `any`, `any`\>
41​
42The query to check.
43​
44## Returns
45​
46`boolean`
47​
48`true` if the query matches every specified filter.
49​
50## Example
51​
52```ts
53const queryCache = queryClient.getQueryCache()
54​
55const matchingQueries = queryCache
56 .getAll()
57 .filter((query) => matchQuery({ queryKey: ['posts'] }, query))
58```