Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generated query key functions don't allow for granular query invalidation, especially with pagination #174

Open
@mmurto

Description

I'm using the generated query key functions with an API that has paginated queries. Here's an example of one generated query key function from our project:

export type SecretsServiceGetSecretsByOrganizationIdQueryResult<
 TData = SecretsServiceGetSecretsByOrganizationIdDefaultResponse,
 TError = unknown,
> = UseQueryResult<TData, TError>;
export const useSecretsServiceGetSecretsByOrganizationIdKey =
 'SecretsServiceGetSecretsByOrganizationId';
export const UseSecretsServiceGetSecretsByOrganizationIdKeyFn = (
 {
 limit,
 offset,
 organizationId,
 sort,
 }: {
 limit?: number;
 offset?: number;
 organizationId: number;
 sort?: string;
 },
 queryKey?: Array<unknown>
) => [
 useSecretsServiceGetSecretsByOrganizationIdKey,
 ...(queryKey ?? [{ limit, offset, organizationId, sort }]),
];

As seen above, the query key generated by the functions is an array with two items like ['SecretsServiceGetSecretsByOrganizationId', { limit: 10, offset, 2, organizationId: 7 }].

The situation where this is unwanted is where I often want to invalidate queries using one of the parameters and disregarding all pagination parameters. With the generated query key function, I can't do that as the parameter I want to use for cache invalidation (organizationId) is in the same object as the pagination parameters.

Best format for generated query key for me would be something where the pagination parameters are separated from rest, which for the above query would be something like ['SecretsServiceGetSecretsByOrganizationId', 7, { limit: 10, offset, 2 }]. I believe this would require knowledge of the names of pagination parameters at generation time, so a flat list without objects would also work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /