@@ -19,11 +19,13 @@ import type {
19
19
ApolloQueryResult ,
20
20
SubscribeToMoreOptions ,
21
21
FetchMoreQueryOptions ,
22
- FetchMoreOptions ,
23
22
ObservableSubscription ,
24
23
TypedDocumentNode ,
25
24
ApolloError ,
26
25
ApolloClient ,
26
+ UpdateQueryMapFn ,
27
+ Unmasked ,
28
+ MaybeMasked ,
27
29
} from '@apollo/client/core/index.js'
28
30
import { throttle , debounce } from 'throttle-debounce'
29
31
import { useApolloClient } from './useApolloClient'
@@ -81,9 +83,14 @@ export interface UseQueryReturn<TResult, TVariables extends OperationVariables>
81
83
options : UseQueryOptions < TResult , TVariables > | Ref < UseQueryOptions < TResult , TVariables > >
82
84
query : Ref < ObservableQuery < TResult , TVariables > | null | undefined >
83
85
refetch : ( variables ?: TVariables ) => Promise < ApolloQueryResult < TResult > > | undefined
84
- fetchMore : ( options : FetchMoreQueryOptions < TVariables , TResult > & FetchMoreOptions < TResult , TVariables > ) => Promise < ApolloQueryResult < TResult > > | undefined
85
- updateQuery : ( mapFn : ( previousQueryResult : TResult , options : Pick < WatchQueryOptions < TVariables , TResult > , 'variables' > ) => TResult ) => void
86
- subscribeToMore : < TSubscriptionVariables = OperationVariables , TSubscriptionData = TResult > ( options : SubscribeToMoreOptions < TResult , TSubscriptionVariables , TSubscriptionData > | Ref < SubscribeToMoreOptions < TResult , TSubscriptionVariables , TSubscriptionData > > | ReactiveFunction < SubscribeToMoreOptions < TResult , TSubscriptionVariables , TSubscriptionData > > ) => void
86
+ fetchMore : < TFetchData = TResult , TFetchVars extends OperationVariables = TVariables > ( options : FetchMoreQueryOptions < TFetchVars , TFetchData > & {
87
+ updateQuery ?: ( previousQueryResult : Unmasked < TResult > , options : {
88
+ fetchMoreResult : Unmasked < TFetchData >
89
+ variables : TFetchVars
90
+ } ) => Unmasked < TResult >
91
+ } ) => Promise < ApolloQueryResult < MaybeMasked < TFetchData > > > | undefined
92
+ updateQuery : ( mapFn : UpdateQueryMapFn < TResult , TVariables > ) => void
93
+ subscribeToMore : < TSubscriptionVariables extends OperationVariables = OperationVariables , TSubscriptionData = TResult > ( options : SubscribeToMoreOptions < TResult , TSubscriptionVariables , TSubscriptionData > | Ref < SubscribeToMoreOptions < TResult , TSubscriptionVariables , TSubscriptionData > > | ReactiveFunction < SubscribeToMoreOptions < TResult , TSubscriptionVariables , TSubscriptionData > > ) => void
87
94
onResult : ( fn : ( param : ApolloQueryResult < TResult > , context : OnResultContext ) => void ) => {
88
95
off : ( ) => void
89
96
}
@@ -545,15 +552,20 @@ export function useQueryImpl<
545
552
546
553
// Update Query
547
554
548
- function updateQuery ( mapFn : ( previousQueryResult : TResult , options : Pick < WatchQueryOptions < TVariables , TResult > , 'variables' > ) => TResult ) {
555
+ function updateQuery ( mapFn : UpdateQueryMapFn < TResult , TVariables > ) {
549
556
if ( query . value ) {
550
557
query . value . updateQuery ( mapFn )
551
558
}
552
559
}
553
560
554
561
// Fetch more
555
562
556
- function fetchMore ( options : FetchMoreQueryOptions < TVariables , TResult > & FetchMoreOptions < TResult , TVariables > ) {
563
+ function fetchMore < TFetchData = TResult , TFetchVars extends OperationVariables = TVariables > ( options : FetchMoreQueryOptions < TFetchVars , TFetchData > & {
564
+ updateQuery ?: ( previousQueryResult : Unmasked < TResult > , options : {
565
+ fetchMoreResult : Unmasked < TFetchData >
566
+ variables : TFetchVars
567
+ } ) => Unmasked < TResult >
568
+ } ) : Promise < ApolloQueryResult < MaybeMasked < TFetchData > > > | undefined {
557
569
if ( query . value ) {
558
570
error . value = null
559
571
loading . value = true
@@ -571,7 +583,7 @@ export function useQueryImpl<
571
583
const subscribeToMoreItems : SubscribeToMoreItem [ ] = [ ]
572
584
573
585
function subscribeToMore <
574
- TSubscriptionVariables = OperationVariables ,
586
+ TSubscriptionVariables extends OperationVariables = OperationVariables ,
575
587
TSubscriptionData = TResult
576
588
> (
577
589
options : SubscribeToMoreOptions < TResult , TSubscriptionVariables , TSubscriptionData > |
0 commit comments