MCPcopy Create free account
hub / github.com/TanStack/query / matchMutation

Function matchMutation

packages/query-core/src/utils.ts:269–296  ·  view source on GitHub ↗
(
  filters: MutationFilters,
  mutation: Mutation<any, any>,
)

Source from the content-addressed store, hash-verified

267 * ```
268 */
269export function matchMutation(
270 filters: MutationFilters,
271 mutation: Mutation<any, any>,
272): boolean {
273 const { exact, status, predicate, mutationKey } = filters
274 if (mutationKey) {
275 if (!mutation.options.mutationKey) {
276 return false
277 }
278 if (exact) {
279 if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) {
280 return false
281 }
282 } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {
283 return false
284 }
285 }
286
287 if (status && mutation.state.status !== status) {
288 return false
289 }
290
291 if (predicate && !predicate(mutation)) {
292 return false
293 }
294
295 return true
296}
297
298/**
299 * Hashes a query key with the query's `queryKeyHashFn` option, falling back to {@link hashKey}.

Callers 4

findMethod · 0.90
findAllMethod · 0.90
utils.test-d.tsxFile · 0.90
utils.test.tsxFile · 0.90

Calls 3

hashKeyFunction · 0.85
partialMatchKeyFunction · 0.85
predicateFunction · 0.50

Tested by

no test coverage detected