isMutating(...)
This method returns an integer representing how many mutations are currently in the loading state. Refer to the TanStack queryClient.isMutating ๐ด guide for more information.
- With
filters
- Without
filters
Checks if any mutations are fetching with the specified filters.
const mutationNumber = qraft.<service>.<operation>.isMutating(
filters,
queryClient,
)
Argumentsโ
filters: UseMutationStateFiltersByParameters | UseMutationStateFiltersByMutationKey
,- Required, represents the Mutation Filters ๐ด to be used, strictly-typed โจ
filters.parameters: { path, query, header }
will be used for filtering mutations by parametersfilters.mutationKey: MutationKey
will be used for filtering mutations by MutationKey instead of parametersfilters.mutationKey
andfilters.parameters
are mutually exclusive
filters.predicate?: (mutation: Mutation) => boolean
will be used for filtering mutations by custom predicate
queryClient?: QueryClient
- Optional QueryClient ๐ด to be used
- If not provided
QraftContext.queryClient
will be used if available- useQueryClient() ๐ด result will be used as a fallback
Returnsโ
mutationsNumber
: The number of mutations that are matching the provided filters and are in the loading state
Check all mutations for the specified endpoint.
const mutationNumber = qraft.<service>.<operation>.isMutating(
queryClient,
)
Argumentsโ
queryClient?: QueryClient
- Optional QueryClient ๐ด to be used
- If not provided
QraftContext.queryClient
will be used if available- useQueryClient() ๐ด result will be used as a fallback
Returnsโ
mutationsNumber
: The number of all mutations matching to <service>.<operation>
and are in the loading state
Examplesโ
filters
filters
Check if any mutations are pending with the specified parameters:
/**
* Checks if the mutation with the specified parameters is fetching:
* ###
* POST /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
**/
const numberOfFetchingEntities = qraft.entities.postEntities.isMutating(
{
header: {
'x-monite-version': '2023-09-01',
},
path: {
entity_id: '3e3e-3e3e-3e3e',
},
},
queryClient
);
expect(numberOfFetchingEntities).toEqual(1);
To check all mutations status for a particular endpoint, you can call isMutating(...)
without parameters
:
/**
* Checks mutations matching the specified endpoint:
* ###
* POST /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
* ###
* POST /entities/4c4c-4c4c-4c4c
* x-monite-version: 2023-09-01
* ###
* โฌ๏ธ All mutations for the specified endpoint will be used
**/
const numberOfFetchingEntities = qraft.entities.postEntities.isMutating(queryClient);
expect(numberOfFetchingEntities).toEqual(2);