cancelQueries(...)
The method can be used to cancel outgoing queries. Refer to the TanStack queryClient.cancelQueries ๐ด and Query Cancellation ๐ด guide for more information.
- With
filters
,options
- With
filters
,options
- No
filters
,options
Cancels queries for the specified endpoint using the provided filters.
api.<service>.<operation>.cancelQueries(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?: boolean
will be used to filter infinite or normal queries, Required ifpredicate
is providedfilters.queryKey?: QueryKey
will be used for filtering queries by QueryKey instead ofparameters
filters.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 canceled
Cancels queries for the specified endpoint using the provided filters with the specified options.
api.<service>.<operation>.cancelQueries(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?: boolean
will be used to filter infinite or normal queries, Required ifpredicate
is providedfilters.queryKey?: QueryKey
will be used for filtering queries by QueryKey instead ofparameters
filters.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 canceled
options: CancelOptions
- Required CancelOptions ๐ด to be used
Cancels all normal and Infinite queries for the specified endpoint.
api.<service>.<operation>.cancelQueries()
Returnsโ
Promise<void>
: A promise that resolves once the cancellation is complete.
Examplesโ
filters
filters
predicate
queryKey
Queries cancellation with the specified parameters:
import { createAPIClient } from './api'; // generated by OpenAPI Qraft CLI
import { requestFn } from '@openapi-qraft/react';
const queryClient = new QueryClient();
const api = createAPIClient({
requestFn,
queryClient,
baseUrl: 'https://api.sandbox.monite.com/v1',
});
/**
* Will cancel the active queries with the specified parameters:
* ###
* GET /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
**/
api.entities.getEntities.cancelQueries(
{
infinite: false,
parameters: {
header: {
'x-monite-version': '2023-09-01',
},
path: {
entity_id: '3e3e-3e3e-3e3e',
},
}
}
);
To cancel all queries for a particular endpoint, you can call cancelQueries(...)
without parameters
:
import { createAPIClient } from './api'; // generated by OpenAPI Qraft CLI
import { requestFn } from '@openapi-qraft/react';
const queryClient = new QueryClient();
const api = createAPIClient({
requestFn,
queryClient,
baseUrl: 'https://api.sandbox.monite.com/v1',
});
/**
* Will cancel 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 canceled
**/
api.entities.getEntities.cancelQueries();
Cancels queries with a custom predicate(...)
function,
which will be used as a final filter on all matching queries.
See Query Filters ๐ด
for more information.
import { createAPIClient } from './api'; // generated by OpenAPI Qraft CLI
import { requestFn } from '@openapi-qraft/react';
const queryClient = new QueryClient();
const api = createAPIClient({
requestFn,
queryClient,
baseUrl: 'https://api.sandbox.monite.com/v1',
});
/**
* Will cancel queries matching the specified endpoint and predicate:
* ###
* GET /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
**/
api.entities.getEntities.cancelQueries(
{
infinite: false,
parameters, // * optional, or specific parameters, alternatively, you can use `queryKey`
predicate: (query) => {
// `queryKey`โฌ๏ธ is fully typed to `api.entities.getEntities` operation parameters
if (query.queryKey[1].path.entity_id === '4c4c-4c4c-4c4c') return false;
return true;
},
}
);
It could be useful to cancel queries using queryKey
directly:
import { createAPIClient } from './api'; // generated by OpenAPI Qraft CLI
import { requestFn } from '@openapi-qraft/react';
const queryClient = new QueryClient();
const api = createAPIClient({
requestFn,
queryClient,
baseUrl: 'https://api.sandbox.monite.com/v1',
});
/**
* Will cancel queries matching the specified endpoint:
* ###
* GET /entities/3e3e-3e3e-3e3e
* x-monite-version: 2023-09-01
**/
api.entities.getEntities.cancelQueries(
{
// `queryKey` is fully typed to `api.entities.getEntities`
queryKey: api.entities.getEntities.getQueryKey({
header: {
'x-monite-version': '2023-09-01',
},
path: {
entity_id: '3e3e-3e3e-3e3e',
},
}),
}
);