Skip to content

Path params not included in query key when useOperationIdAsQueryKey is true #2505

@semir-turkic-serapion

Description

@semir-turkic-serapion

When the useOperationIdAsQueryKey flag is set to true, path parameters are not included in the generated query key.
This leads to incorrect cache behavior and makes it impossible to properly invalidate queries that depend on unique path parameters.

Example

Generated output:

export const getGetWorkspaceQueryKey = (workspaceId?: number, params?: GetWorkspaceParams) => {
  return ["getWorkspace", ...(params ? [params] : [])] as const
}

In this case, the workspaceId path parameter is missing from the query key.

Expected behavior

Path parameters should be included in the generated query key only if they are defined, for example:

export const getGetWorkspaceQueryKey = (workspaceId?: number, params?: GetWorkspaceParams) => {
  return ["getWorkspace", ...(workspaceId !== undefined ? [workspaceId] : []), ...(params ? [params] : [])] as const
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    tanstack-queryTanStack Query related issue

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions