Skip to content

Commit 841121a

Browse files
authored
Merge pull request #39 from guendev/fix/useMutation-hook
fix: ensure onDone is triggered properly on mutation success
2 parents f124107 + 74d5d01 commit 841121a

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

.changeset/wide-jokes-clean.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@vue3-apollo/core": patch
3+
"@vue3-apollo/nuxt": patch
4+
---
5+
6+
fix: ensure `onDone` is triggered properly on mutation success

packages/core/src/composables/useMutation.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { nextTick, ref, shallowRef } from 'vue'
77
import type { HookContext, UseBaseOption } from '../utils/type'
88

99
import { useApolloTracking } from '../helpers/useApolloTracking'
10-
import { isDefined } from '../utils/isDefined'
1110
import { useApolloClient } from './useApolloClient'
1211

1312
/**
@@ -115,17 +114,15 @@ export function useMutation<
115114
...mutateOptions
116115
})
117116

118-
data.value = result.data
119-
120-
if (isDefined(result.data)) {
121-
await nextTick()
122-
void onDone.trigger(result.data, { client })
123-
}
124-
125117
if (result.error) {
126118
error.value = result.error
127119
void onError.trigger(result.error, { client })
128120
}
121+
else {
122+
data.value = result.data
123+
await nextTick()
124+
void onDone.trigger(result.data as TData, { client })
125+
}
129126

130127
return result
131128
}

0 commit comments

Comments
 (0)