Skip to content

Add the ability to include queryKey / mutationKey to the RequestConfig #2059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
matheus-oliveira-unity opened this issue Apr 23, 2025 · 0 comments
Labels
enhancement New feature or request tanstack-query TanStack Query related issue

Comments

@matheus-oliveira-unity
Copy link

matheus-oliveira-unity commented Apr 23, 2025

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

@AllieJonsson AllieJonsson added enhancement New feature or request tanstack-query TanStack Query related issue labels Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tanstack-query TanStack Query related issue
Projects
None yet
Development

No branches or pull requests

2 participants