Open History to see the last commit
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?` | `"idle"` \| `"fetching"` \| `"paused"` | `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```