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