Open
Description
Feature Request
docs for reference.
It would be useful to have the queryKey
or mutationKey
added to the request in order to identify which query is triggering that request.
export const getTodoByIdQueryOptions = ... {
const queryKey = queryOptions?.queryKey ?? getTodoByIdQueryKey(todoId, params);
// add queryKey param
const queryFn: QueryFunction<Awaited<ReturnType<typeof getTodoById>>> = ({ signal }) => getTodoById(key, params, signal, queryKey);
...
}
export const getTodoById = (
todoId: string,
params?: GetTodoByIdParams,
signal?: AbortSignal,
// add queryKey param
queryKey: QueryKey,
) => {
return customInstance<TodoResponse>(
{
url: `/todos/${encodeURIComponent(String(todoId))}`,
method: 'GET',
params,
signal,
// include queryKey to the request.
queryKey
});
}
since queryKey
can be either set, when using useTodoByIdQuery
or when undefined
it uses getTodoByIdQueryKey
to set it.
it would make a lot easier if the "actual" queryKey
used was passed to the request.
this would allow to correlate request / query by queryKey
, making easier to update cache, logging, notification etc, without the need to customize the query itself in a wrapper.
ideally, allowing that for mutation as well, by including mutationKey
to the request.
there could be a config allowing turning this on/off.
Thanks