-
-
Notifications
You must be signed in to change notification settings - Fork 37
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.