getQueriesData(...)
The getQueriesData()
method enables direct access to the QueryClient
cache to retrieve data for multiple queries that match specified filters. This method is particularly useful when you need to access data from multiple related queries at once.
See the TanStack queryClient.getQueriesData ๐ด documentation for more details on the underlying implementation.
const queriesData = api.<service>.<operation>.getQueriesData(filters);
Argumentsโ
filters?: QueryFilters
- Optional query filters to apply when selecting queries
parameters?: { path?, query?, header? }
: Parameters to match against when filtering queriesqueryKey?: QueryKey
: A query key to filter the queries, could be instead ofparameters
exact?: boolean
: Whether to match the Query Key exactlyinfinite?: boolean
: Whether to retrieve infinite query datapredicate?: (query: Query) => boolean
: A function to further filter the queries- If no filters are provided,
getQueriesData()
returns data for all non-infinite queries of the specified operation
Returnsโ
Returns []
if there are no matches, or an array of tuples:
- The Query Key of the matched query.
- The data associated with that query.
[queryKey: QueryKey, data: TQueryFnData | undefined][]
Examplesโ
- Basic Usage
- Using Predicate
- Infinite Queries
const queriesData = api.approvalPolicies.getApprovalPoliciesId.getQueriesData({
parameters: {
header: {
'x-monite-version': '1.0.0'
},
path: {
approval_policy_id: '1'
},
query: {
items_order: ['asc', 'desc']
}
}
});
console.log(queriesData);
// [
// [
// [{ url: '/approval_policies/{approval_policy_id}', method: 'get', ... }, { ... }],
// { ...data }
// ],
// ]
const queriesData = api.approvalPolicies.getApprovalPoliciesId.getQueriesData({
predicate: (query) => {
return Boolean(query.queryKey?.[1]?.query?.items_order?.includes('asc'));
}
});
console.log(queriesData);
// Returns all queries where items_order includes 'asc'
const infiniteQueriesData = api.approvalPolicies.getApprovalPoliciesId.getQueriesData({
infinite: true,
parameters: {
header: {
'x-monite-version': '1.0.0'
},
path: {
approval_policy_id: '1'
}
}
});
console.log(infiniteQueriesData);
// [
// [
// [{ url: '/approval_policies/{approval_policy_id}', method: 'get', infinite: true, ... }, { ... }],
// { ...data }
// ]
// ]