Open History to see the last commit
1---
2id: matchMutation
3title: matchMutation
4---
5β
6```ts
7function matchMutation(filters: MutationFilters, mutation: Mutation<any, any>): boolean;
8```
9β
10Defined in: [packages/query-core/src/utils.ts:269](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L269)
11β
12Checks whether a mutation matches the given [MutationFilters](../interfaces/MutationFilters.md).
13Every filter that is specified must match; filters that are left unspecified are ignored.
14If a `mutationKey` filter is provided but the mutation has no `mutationKey` of its own, it does not match.
15β
16## Parameters
17β
18### filters
19β
20[`MutationFilters`](../interfaces/MutationFilters.md)
21β
22The filters to check the mutation against.
23β
24<a id="filters-properties"></a>
25β
26#### `filters` properties
27β
28| Property | Type | Description |
29| ------ | ------ | ------ |
30| <a id="filters-property-exact"></a> `exact?` | `boolean` | Match mutation key exactly |
31| <a id="filters-property-mutationkey"></a> `mutationKey?` | readonly `unknown`[] | Include mutations matching this mutation key |
32| <a id="filters-property-predicate"></a> `predicate?` | (`mutation`: [`Mutation`](../classes/Mutation.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>) => `boolean` | Include mutations matching this predicate function |
33| <a id="filters-property-status"></a> `status?` | `"error"` \| `"pending"` \| `"success"` \| `"idle"` | Filter by mutation status |
34β
35### mutation
36β
37[`Mutation`](../classes/Mutation.md)\<`any`, `any`\>
38β
39The mutation to check.
40β
41## Returns
42β
43`boolean`
44β
45`true` if the mutation matches every specified filter.
46β
47## Example
48β
49```ts
50const mutationCache = queryClient.getMutationCache()
51β
52const matchingMutations = mutationCache
53 .getAll()
54 .filter((mutation) => matchMutation({ mutationKey: ['addPost'] }, mutation))
55```