react-query-swagger icon indicating copy to clipboard operation
react-query-swagger copied to clipboard

Better support of queryKeys / mutationKeys

Open russell-dot-js opened this issue 11 months ago • 1 comments

Right now the queryKeys & mutationKeys are generated from the "ActualOperationName" from nswag, and it looks like all the options to customize queries/mutations omit our ability to change the key

So, for example, something like this could be generated:

export function getAllUsersQueryKey(...params: any[]): QueryKey {
  return trimArrayEnd([
      'Client',
      'getAllUsers',
    ]);
}

While this might also get generated:

export function createUserMutationKey(): MutationKey {
  return trimArrayEnd([
      'Client',
      'createUser',
    ]);
}

We currently have no way, as far as I can tell, to control react-query's caching, and tell it that "createUser" changes the result of "getAllUsers". Attempting to change nswag's strategy e.g. /operationGenerationMode:MultipleClientsFromOperationId does not seem to make any difference (likely because of the usage of ActualOperationName.

Why not let devs pass in their own queryKeys, either in addition or instead of the generated ones?

russell-dot-js avatar Feb 29 '24 01:02 russell-dot-js

https://tanstack.com/query/v4/docs/framework/react/guides/updates-from-mutation-responses saved me - but would be great to have some control

russell-dot-js avatar Feb 29 '24 02:02 russell-dot-js