refetchQueries(...)
The method can be used to refetch queries based on certain conditions. See also the TanStack queryClient.refetchQueries(...) 🌴 documentation.
- With
filters,options - With
filters,options - No
filters,options
Refetches queries for the specified endpoint using the provided filters.
qraft.<service>.<operation>.refetchQueries(
filters
)
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: booleanwill be used to filter infinite or normal queriesfilters.queryKey: QueryKeywill be used for filtering queries by QueryKey instead of parametersfilters.queryKeyandfilters.parametersare mutually exclusive
filters.predicate?: (query: Query) => booleanwill be used for filtering queries by custom predicate- If not provided
- All queries for the specified endpoint will be refetched
Refetches queries for the specified endpoint using the provided filters with the specified options.
qraft.<service>.<operation>.refetchQueries(
filters,
options
)
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: booleanwill be used to filter infinite or normal queriesfilters.queryKey: QueryKeywill be used for filtering queries by QueryKey instead of parametersfilters.queryKeyandfilters.parametersare mutually exclusive
filters.predicate?: (query: Query) => booleanwill be used for filtering queries by custom predicate- If not provided
- All queries for the specified endpoint will be refetched
options: RefetchOptions- Required, see queryClient.refetchQueries(...) 🌴 for more details to be used
Refetches all normal and Infinite queries for the specified endpoint.
qraft.<service>.<operation>.refetchQueries()
Returns​
Promise<void>: A promise that resolves once the refetching is complete.
Examples​
filtersfilterspredicatequeryKey
Queries refetching with the specified parameters:
/**
* Active queries with the specified parameters will be refetched:
* ###
* GET /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
**/
qraft.entities.getEntities.refetchQueries(
{
infinite: false,
parameters: {
header: {
'x-monite-version': '2023-09-01',
},
path: {
entity_id: '3e3e-3e3e-3e3e',
},
},
}
);
To refetch all queries for a particular endpoint, you can call refetchQueries(...) without parameters:
/**
* Refetches 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 refetched
**/
qraft.entities.getEntities.refetchQueries();
Refetches queries with a custom predicate(...) function,
which will be used as a final filter on all matching queries.
See Query Filters 🌴
for more information.
/**
* Refetches queries matching the specified endpoint and predicate:
* ###
* GET /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
**/
qraft.entities.getEntities.refetchQueries(
{
infinite: false,
parameters, // * optional, or specific parameters, alternatively, you can use `queryKey`
predicate: (query) => {
// `queryKey`⬇︎ is fully typed to `qraft.entities.getEntities` operation parameters
if (query.queryKey[1].path.entity_id === '4c4c-4c4c-4c4c') return false;
return true;
},
}
);
It could be useful to refetch queries using queryKey directly:
/**
* Refetches queries matching the specified endpoint:
* ###
* GET /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
**/
qraft.entities.getEntities.refetchQueries(
{
// `queryKey` is fully typed to `qraft.entities.getEntities`
queryKey: qraft.entities.getEntities.getQueryKey({
header: {
'x-monite-version': '2023-09-01',
},
path: {
entity_id: '3e3e-3e3e-3e3e',
},
}),
}
);