Skip to main content
Version: 2.x

getMutationCache()

This method returns a MutationCache object that provides access to mutation cache operations for the specific endpoint. The returned object has find() and findAll() methods to search for mutations in the cache.

const mutationCache = qraft.<service>.<operation>.getMutationCache()

MutationCache.find(...)โ€‹

Finds the first mutation that matches the specified filters.

const mutation = qraft.<service>.<operation>.getMutationCache().find(
filters
)

Argumentsโ€‹

  1. filters: MutationFilters,
    • Optional, represents the Mutation Filters ๐ŸŒด to be used, strictly-typed โœจ
    • filters.parameters: { path, query, header } will be used for filtering mutations by parameters
    • filters.mutationKey: MutationKey will be used for filtering mutations by MutationKey instead of parameters
      • filters.mutationKey and filters.parameters are mutually exclusive
    • filters.predicate?: (mutation: Mutation) => boolean will be used for filtering mutations by custom predicate
    • filters.exact?: boolean will be used for exact or partial matching of parameters (default: true)
    • Note: When no filters are provided, the method uses the base mutation key for <service>.<operation> and automatically sets exact: false to match all mutations for the endpoint

Returnsโ€‹

mutation: Mutation | undefined: The first mutation that matches the filters, or undefined if no match is found

MutationCache.findAll(...)โ€‹

Finds all mutations that match the specified filters.

Finds all mutations with the specified filters.

const mutations = qraft.<service>.<operation>.getMutationCache().findAll(
filters
)

Argumentsโ€‹

  1. filters: MutationFilters,
    • Optional, represents the Mutation Filters ๐ŸŒด to be used, strictly-typed โœจ
    • filters.parameters: { path, query, header } will be used for filtering mutations by parameters
    • filters.mutationKey: MutationKey will be used for filtering mutations by MutationKey instead of parameters
      • filters.mutationKey and filters.parameters are mutually exclusive
    • filters.predicate?: (mutation: Mutation) => boolean will be used for filtering mutations by custom predicate
    • filters.exact?: boolean will be used for exact or partial matching of parameters (default: true)
    • Note: When no filters are provided, the method uses the base mutation key for <service>.<operation> and automatically sets exact: false to match all mutations for the endpoint

Returnsโ€‹

mutations: Mutation[]: Array of all mutations that match the filters

Examplesโ€‹

Find a mutation with specific parameters:

/**
* Find the mutation with the specified parameters:
* ###
* POST /entities/3e3e-3e3e-3e3e/documents
* x-version: 2023-09-01
**/
const mutationCache = qraft.entities.postEntitiesIdDocuments.getMutationCache();
const mutation = mutationCache.find({
parameters: {
header: {
'x-version': '2023-09-01',
},
path: {
entity_id: '3e3e-3e3e-3e3e',
},
},
});

if (mutation) {
console.log('Mutation found:', mutation.state.data);
}