Skip to content

Commit 28fda86

Browse files
committed
feat(useQuery): add updateQuery
1 parent 6fa46ab commit 28fda86

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/vue-apollo-composable/src/useQuery.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface UseQueryReturn<TResult, TVariables extends OperationVariables>
8181
query: Ref<ObservableQuery<TResult, TVariables> | null | undefined>
8282
refetch: (variables?: TVariables) => Promise<ApolloQueryResult<TResult>> | undefined
8383
fetchMore: (options: FetchMoreQueryOptions<TVariables, TResult> & FetchMoreOptions<TResult, TVariables>) => Promise<ApolloQueryResult<TResult>> | undefined
84+
updateQuery: (mapFn: (previousQueryResult: TResult, options: Pick<WatchQueryOptions<TVariables, TResult>, 'variables'>) => TResult) => void
8485
subscribeToMore: <TSubscriptionVariables = OperationVariables, TSubscriptionData = TResult>(options: SubscribeToMoreOptions<TResult, TSubscriptionVariables, TSubscriptionData> | Ref<SubscribeToMoreOptions<TResult, TSubscriptionVariables, TSubscriptionData>> | ReactiveFunction<SubscribeToMoreOptions<TResult, TSubscriptionVariables, TSubscriptionData>>) => void
8586
onResult: (fn: (param: ApolloQueryResult<TResult>, context: OnResultContext) => void) => {
8687
off: () => void
@@ -534,6 +535,14 @@ export function useQueryImpl<
534535
}
535536
}
536537

538+
// Update Query
539+
540+
function updateQuery (mapFn: (previousQueryResult: TResult, options: Pick<WatchQueryOptions<TVariables, TResult>, 'variables'>) => TResult) {
541+
if (query.value) {
542+
query.value.updateQuery(mapFn)
543+
}
544+
}
545+
537546
// Fetch more
538547

539548
function fetchMore (options: FetchMoreQueryOptions<TVariables, TResult> & FetchMoreOptions<TResult, TVariables>) {
@@ -637,6 +646,7 @@ export function useQueryImpl<
637646
refetch,
638647
fetchMore,
639648
subscribeToMore,
649+
updateQuery,
640650
onResult: resultEvent.on,
641651
onError: errorEvent.on,
642652
}

0 commit comments

Comments
 (0)