Skip to content

Commit 4ed0ce8

Browse files
authored
Merge pull request #16 from guendev/ssr-fix-2
fix(core): rename onResult to onResultEvent in useQuery composable
2 parents 22616c6 + 646c6fb commit 4ed0ce8

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

.changeset/sour-bars-eat.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(core): rename `onResult` to `onResultEvent` in `useQuery` composable

packages/core/src/composables/useQuery.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export function useQuery<TData = unknown, TVariables extends OperationVariables
155155
const networkStatus = ref<NetworkStatus>()
156156
const error = ref<ErrorLike>()
157157

158-
const onResult = createEventHook<[TData, HookContext]>()
158+
const onResultEvent = createEventHook<[TData, HookContext]>()
159159
const onErrorEvent = createEventHook<[ErrorLike, HookContext]>()
160160

161161
// Setup loading tracking
@@ -199,16 +199,11 @@ export function useQuery<TData = unknown, TVariables extends OperationVariables
199199
loading.value = false
200200
if (queryResult.error) {
201201
error.value = queryResult.error
202-
void onErrorEvent.trigger(queryResult.error, { client })
203-
}
204-
else if (isDefined(result.value)) {
205-
void onResult.trigger(result.value, { client })
206202
}
207203
}
208204
catch (e) {
209205
error.value = e as ErrorLike
210206
loading.value = false
211-
void onErrorEvent.trigger(error.value, { client })
212207
}
213208
})
214209
}
@@ -228,7 +223,7 @@ export function useQuery<TData = unknown, TVariables extends OperationVariables
228223
if (isDefined(value.data) || !options?.keepPreviousResult) {
229224
result.value = value.data as TData
230225
if (isDefined(result.value)) {
231-
void onResult.trigger(value.data as TData, { client })
226+
void onResultEvent.trigger(value.data as TData, { client })
232227
}
233228
}
234229
}
@@ -435,13 +430,13 @@ export function useQuery<TData = unknown, TVariables extends OperationVariables
435430
*
436431
* @example
437432
* ```ts
438-
* onResult((data, context) => {
433+
* onResultEvent((data, context) => {
439434
* console.log('New data:', data)
440435
* console.log('Apollo client:', context.client)
441436
* })
442437
* ```
443438
*/
444-
onResult: onResult.on,
439+
onResult: onResultEvent.on,
445440

446441
/**
447442
* Manually refetch the query with optional new variables.

0 commit comments

Comments
 (0)