Skip to main content
Version: 2.x ๐Ÿšง

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โ€‹

  1. filters?: QueryFilters
    • Optional query filters to apply when selecting queries
    • parameters?: { path?, query?, header? }: Parameters to match against when filtering queries
      • queryKey?: QueryKey: A query key to filter the queries, could be instead of parameters
    • exact?: boolean: Whether to match the Query Key exactly
    • infinite?: boolean: Whether to retrieve infinite query data
    • predicate?: (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:

  1. The Query Key of the matched query.
  2. The data associated with that query.
[queryKey: QueryKey, data: TQueryFnData | undefined][]

Examplesโ€‹

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 }
// ],
// ]