Skip to content

Commit

Permalink
fix(useQuery): result when error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Dec 1, 2019
1 parent fac6fea commit d7f14b3
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/vue-apollo-composable/src/useQuery.ts
Expand Up @@ -84,20 +84,34 @@ export function useQuery<
next: onNextResult,
error: onError,
})
}

for (const item of subscribeToMoreItems) {
addSubscribeToMore(item)
function onNextResult (queryResult: ApolloQueryResult<TResult>) {
processNextResult(queryResult)

// Result errors
// This is set when `errorPolicy` is `all`
if (queryResult.errors && queryResult.errors.length) {
const e = new Error(`GraphQL error: ${queryResult.errors.map(e => e.message).join(' | ')}`)
Object.assign(e, {
graphQLErrors: queryResult.errors,
networkError: null,
})
processError(e)
}
}

function onNextResult (queryResult: ApolloQueryResult<TResult>) {
result.value = queryResult.data
function processNextResult (queryResult: ApolloQueryResult<TResult>) {
result.value = queryResult.data && Object.keys(queryResult.data).length === 0 ? null : queryResult.data
loading.value = queryResult.loading
networkStatus.value = queryResult.networkStatus
resultEvent.trigger(queryResult)
}

function onError (queryError: any) {
processNextResult(query.value.currentResult() as ApolloQueryResult<TResult>)
processError(queryError)
function processError (queryError: any) {
error.value = queryError
loading.value = false
networkStatus.value = 8
Expand Down

0 comments on commit d7f14b3

Please sign in to comment.