Shaddix / react-query-swagger

Generates react-query hooks based on Swagger API definitions
MIT License
122 stars 4 forks source link

Better support of queryKeys / mutationKeys #42

Open russell-dot-js opened 6 months ago

russell-dot-js commented 6 months ago

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 commented 6 months ago

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