Skip to content

Commit 5d95f5f

Browse files
committed
fix: corrected onSuccess handling within mutationFn
1 parent 1bb4e6d commit 5d95f5f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

commons-rest-openapi/src/main/resources/templates/hook/hook-template.pebble

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,25 @@ export function {{ method.hookName -}}<TData = {{ method.shortReturnType }}, {{
5959
const queryClient = useQueryClient();
6060
const { {{ configuredGroupVar }} } = useApi();
6161
return useMutation<{{ method.shortReturnType }}, TError, {{ method.shortInputType }}, TContext>({
62-
mutationFn: ({% if not method.isVoidShortInputType %}content{% endif %}) => {{ configuredGroupVar -}}.{{- controller.fieldName -}}.{{- method.methodName -}}({% if method.isVoidShortInputType %} {} {% else %} content {% endif %}),
63-
{% if method.invalidateKeysPrepared('content.', 'data.') is not empty %}
64-
onSuccess: async (data, content{% if reactQueryVersion.number >= 5 %}, onMutateResult{% endif %}, context) => {
65-
const invalide = async () => await Promise.all([{% for ik in method.invalidateKeysPrepared('content.', 'data.') %}
62+
mutationFn: ({% if not method.isVoidShortInputType %}content: {{ method.shortInputType }}{% endif %}) => {{ configuredGroupVar -}}.{{- controller.fieldName -}}.{{- method.methodName -}}({% if method.isVoidShortInputType %} {} {% else %} content {% endif %}),
63+
{% if method.invalidateKeysPrepared('variables.', 'data.') is not empty %}
64+
{% if reactQueryVersion.number >= 5 %}
65+
onSuccess: async (data: {{ method.shortReturnType }}, variables: {{ method.shortInputType }}, onMutateResult: TContext | undefined, context: unknown) => {
66+
{% else %}
67+
onSuccess: async (data: {{ method.shortReturnType }}, variables: {{ method.shortInputType }}, context: TContext) => {
68+
{% endif %}
69+
const invalide = async () => await Promise.all([{% for ik in method.invalidateKeysPrepared('variables.', 'data.') %}
6670
queryClient.invalidateQueries(
6771
{% if reactQueryVersion.name equals "v5" %}{queryKey: [{% for k in ik %}`{{ k }}`{% if not loop.last %}, {% endif %}{% endfor %}]}
6872
{% else %}[{% for k in ik %}`{{ k }}`{% if not loop.last %}, {% endif %}{% endfor %}]{% endif %}
6973
){% if not loop.last %}, {% endif %}{% endfor %}]);
7074

7175
if (onSuccess) {
72-
const result = onSuccess(data, content{% if reactQueryVersion.number >= 5 %}, onMutateResult{% endif %}, context);
76+
{% if reactQueryVersion.number >= 5 %}
77+
const result = onSuccess(data, variables, onMutateResult, context);
78+
{% else %}
79+
const result = onSuccess(data, variables, context);
80+
{% endif %}
7381
if (result && Object.prototype.toString.call(result) === "[object Promise]") {
7482
await result;
7583
return invalide();

0 commit comments

Comments
 (0)