rapini icon indicating copy to clipboard operation
rapini copied to clipboard

Mutation Generator Enhancement

Open dstone1983 opened this issue 1 year ago • 1 comments

When generating mutations allow for an option in the generator to make url parameters not part of the initial use mutation hook that is created, and instead have it be part of the options passed when calling the mutation.

We have many api calls that the posts are {url}/partofroute/{dynamicVariable}/part2ofroute/{dynamicVariable}

The current setup has it where you have to pass these variables directly into the use mutation hook and not the actual api call of mutate. This makes it difficult to make multiple dynamic calls of potentially unknown contents. To expand a bit here is a more detailed URL:

{base}/callsomePostRoute/{customerId/serviceName/{userId}

CustomerId in this instance is singular for the current login. We could though potentially need to make multiple post calls via the userId. Assuming api does not have a bulk submission, but UI needs to do a bulk action, in the current format this is not possible.

I found a generic work around by making a list of users, iterating over that list and creating a new array of generated results of the mutations.{useApiCall} and passing in the parameters. Then to perform the action, I iterate over that list. I could minimize some of these items I am iterating and technically I should not be utilizing these hook calls inside a function like this.

So instead of calling:

mutation.useApiMutation(var1, var2, var3)

I could do something more like this:

Const {mutation} = mutation.useApiMutation(); Mutation(var1, var2, var3) //or some variance of this

dstone1983 avatar Jul 30 '24 17:07 dstone1983

Yes definitely. Thanks for opening the issue. I won't have much time to address this but PR's are always welcome!

rametta avatar Jul 30 '24 21:07 rametta