Skip to content

Params are missing in mutationKey #2100

Open
@adityaa72

Description

@adityaa72

openapi-react-query version

0.2.9

Description

MutationKey don't include params as can be seen in this code

useMutation(
        {
          mutationKey: [method, path],
          mutationFn: async (init) => {
            const mth = method.toUpperCase() as Uppercase<typeof method>;
            const fn = client[mth] as ClientMethod<Paths, typeof method, Media>;
            const { data, error } = await fn(path, init as InitWithUnknowns<typeof init>);
            if (error) {
              throw error;
            }

            return data as Exclude<typeof data, undefined>;
          },
          ...options,
        },
        queryClient,
      )

Use case

I wanna check if a mutation with a specific id is mutating or not.
Here id should be used for creating mutation key

Also there is a request to add createQueryKey function in your package

import { createQueryKey } from "@/client/utils";
import { useIsMutating } from "@tanstack/react-query";

export const usePayoutWalletState = (id: string) => {
  const isMutating = useIsMutating({
    mutationKey: createQueryKey("put", "/payout-wallets/{id}/set-default"),
  });
  return {
    isMutating,
  };
};

Reproduction

This issue is not related to any browser or specific conditions.

Expected result

I expected that mutationKey should include params same as used in queryOptions

const queryOptions: QueryOptionsFunction<Paths, Media> = (method, path, ...[init, options]) => ({
    queryKey: [method, path, init as InitWithUnknowns<typeof init>] as const,
    queryFn,
    ...options,
  });

Extra

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueStraightforward problem, solvable for first-time contributors without deep knowledge of the projectopenapi-react-queryRelevant to openapi-react-query

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions