isFetching(...)
This method returns an integer representing how many queries, if any, in the cache are currently fetching. Refer to the TanStack queryClient.isFetching ๐ด guide for more information.
- With
filters
- Without
filters
Checks if any queries are fetching with the specified parameters.
qraft.<service>.<operation>.isFetching(
filters,
queryClient,
)
Argumentsโ
filters: QueryFiltersByParameters | QueryFiltersByQueryKey
- Required, represents the Query Filters ๐ด to be used, strictly-typed โจ
filters.parameters: { path, query, header }
will be used for filtering queries by parametersfilters.infinite: boolean
will be used to filter infinite or normal queriesfilters.queryKey: QueryKey
will be used for filtering queries by QueryKey instead of parametersfilters.queryKey
andfilters.parameters
are mutually exclusive
filters.predicate?: (query: Query) => boolean
will be used for filtering queries by custom predicate- If not provided
- All queries for the specified endpoint will be checked
queryClient: QueryClient
- Required QueryClient ๐ด to be used
Check all normal and Infinite queries for the specified endpoint.
qraft.<service>.<operation>.isFetching(
queryClient,
)
Argumentsโ
queryClient: QueryClient
- Required QueryClient ๐ด to be used
Returnsโ
number
: Number of queries fetching.
Examplesโ
filters
filters
Check if any queries are fetching with the specified parameters:
/**
* Will check if the query with the specified parameters is fetching:
* ###
* GET /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
**/
const numberOfFetchingEntities = qraft.entities.getEntities.isFetching(
{
infinite: false,
parameters: {
header: {
'x-monite-version': '2023-09-01',
},
path: {
entity_id: '3e3e-3e3e-3e3e',
},
},
},
queryClient
);
expect(numberOfFetchingEntities).toEqual(1);
To check all normal queries for a particular endpoint, you can call isFetching(...)
without parameters
:
/**
* Will check queries matching the specified endpoint:
* ###
* GET /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
* ###
* GET /entities/4c4c-4c4c-4c4c
* x-monite-version: 2023-09-01
* ###
* โฌ๏ธ All queries for the specified endpoint will be used
**/
const numberOfFetchingEntities = qraft.entities.getEntities.isFetching(queryClient);
expect(numberOfFetchingEntities).toEqual(2);