@@ -6,6 +6,7 @@ import type {
6
6
ApolloClient ,
7
7
ApolloQueryResult ,
8
8
OperationVariables ,
9
+ WatchQueryOptions ,
9
10
} from "../../core/index.js" ;
10
11
import { mergeOptions } from "../../utilities/index.js" ;
11
12
import type {
@@ -16,16 +17,11 @@ import type {
16
17
QueryHookOptions ,
17
18
QueryResult ,
18
19
} from "../types/types.js" ;
19
- import type {
20
- InternalResult ,
21
- ObsQueryWithMeta ,
22
- UpdateInternalState ,
23
- } from "./useQuery.js" ;
20
+ import type { InternalResult , ObsQueryWithMeta } from "./useQuery.js" ;
24
21
import {
25
22
createMakeWatchQueryOptions ,
26
23
getDefaultFetchPolicy ,
27
24
getObsQueryOptions ,
28
- lastWatchOptions ,
29
25
toQueryResult ,
30
26
useQueryInternals ,
31
27
} from "./useQuery.js" ;
@@ -108,7 +104,7 @@ export function useLazyQuery<
108
104
client,
109
105
resultData,
110
106
observable,
111
- updateInternalState ,
107
+ onQueryExecuted ,
112
108
} = useQueryInternals ( document , queryHookOptions ) ;
113
109
114
110
const initialFetchPolicy =
@@ -171,7 +167,7 @@ export function useLazyQuery<
171
167
client ,
172
168
document ,
173
169
{ ...options , skip : false } ,
174
- updateInternalState
170
+ onQueryExecuted
175
171
) . then ( ( queryResult ) => Object . assign ( queryResult , eagerMethods ) ) ;
176
172
177
173
// Because the return value of `useLazyQuery` is usually floated, we need
@@ -187,7 +183,7 @@ export function useLazyQuery<
187
183
initialFetchPolicy ,
188
184
observable ,
189
185
resultData ,
190
- updateInternalState ,
186
+ onQueryExecuted ,
191
187
]
192
188
) ;
193
189
@@ -211,7 +207,7 @@ function executeQuery<TData, TVariables extends OperationVariables>(
211
207
options : QueryHookOptions < TData , TVariables > & {
212
208
query ?: DocumentNode ;
213
209
} ,
214
- updateInternalState : UpdateInternalState < TData , TVariables >
210
+ onQueryExecuted : ( options : WatchQueryOptions < TVariables , TData > ) => void
215
211
) {
216
212
const query = options . query || currentQuery ;
217
213
const watchQueryOptions = createMakeWatchQueryOptions (
@@ -224,21 +220,7 @@ function executeQuery<TData, TVariables extends OperationVariables>(
224
220
const concast = observable . reobserveAsConcast (
225
221
getObsQueryOptions ( observable , client , options , watchQueryOptions )
226
222
) ;
227
- // this needs to be set to prevent an immediate `resubscribe` in the
228
- // next rerender of the `useQuery` internals
229
- observable [ lastWatchOptions ] = watchQueryOptions ;
230
- updateInternalState ( {
231
- client,
232
- observable,
233
- // might be a different query
234
- query,
235
- resultData : Object . assign ( resultData , {
236
- // We need to modify the previous `resultData` object as we rely on the
237
- // object reference in other places
238
- previousData : resultData . current ?. data || resultData . previousData ,
239
- current : undefined ,
240
- } ) ,
241
- } ) ;
223
+ onQueryExecuted ( watchQueryOptions ) ;
242
224
243
225
return new Promise <
244
226
Omit < QueryResult < TData , TVariables > , ( typeof EAGER_METHODS ) [ number ] >
0 commit comments