getQueryKey(...)
The method provides a standardized way to generate QueryKey
for Queries.
See TanStack Query Keys ๐ด guide for more information.
const queryKey = api.<service>.<operation>.getQueryKey(parameters);
Argumentsโ
-
parameters: { path, query, header } | void
- Optional, OpenAPI request parameters for the query, strictly-typed โจ
parameters
will be used to generate theQueryKey
Returnsโ
QueryKey
- a query key for the operation parameters
Exampleโ
- With
parameters
- Without
parameters
const queryKey = api.files.getFiles.getQueryKey({
header: { 'x-monite-version': '1.0.0' },
query: { id__in: ['1', '2'] },
});
// `queryKey` will be an array of objects
expect(queryKey).toEqual([
{ method: 'get', url: '/files', infinite: false, },
{
header: { 'x-monite-version': '1.0.0' },
query: { id__in: ['1', '2'] }
}
]);
In case all parameters are optional - you can pass nothing.
const queryKey = api.files.getFiles.getQueryKey();
// `queryKey` will be an array of objects
expect(queryKey).toEqual([
{ method: 'get', url: '/files', infinite: false, },
{}
]);