feat(useQuery): fetchMore

This commit is contained in:
Guillaume Chau
2019-12-01 17:14:15 +01:00
parent 5ca557dfb3
commit d73eac827b
+18 -1
View File
@@ -1,7 +1,15 @@
import { ref, watch, onUnmounted, Ref, isRef, computed } from '@vue/composition-api'
import Vue from 'vue'
import { DocumentNode } from 'graphql'
import { OperationVariables, WatchQueryOptions, ObservableQuery, ApolloQueryResult, SubscribeToMoreOptions } from 'apollo-client'
import {
OperationVariables,
WatchQueryOptions,
ObservableQuery,
ApolloQueryResult,
SubscribeToMoreOptions,
FetchMoreQueryOptions,
FetchMoreOptions,
} from 'apollo-client'
import { Subscription } from 'apollo-client/util/Observable'
import { useApolloClient } from './useApolloClient'
import { ReactiveFunction } from './util/ReactiveFunction'
@@ -221,6 +229,14 @@ export function useQuery<
}
}
// Fetch more
function fetchMore<K extends keyof TVariables> (options: FetchMoreQueryOptions<TVariables, K> & FetchMoreOptions<TResult, TVariables>) {
if (query.value) {
return query.value.fetchMore(options)
}
}
// Subscribe to more
const subscribeToMoreItems: SubscribeToMoreItem[] = []
@@ -303,6 +319,7 @@ export function useQuery<
options: optionsRef,
query,
refetch,
fetchMore,
subscribeToMore,
onResult: resultEvent.on,
onError: errorEvent.on,