@apollo/client 3.11.0-rc.0 → 3.11.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/breezy-deers-dream.md +5 -0
- package/.changeset/curly-vans-draw.md +5 -0
- package/.changeset/early-tips-vanish.md +5 -0
- package/.changeset/good-suns-happen.md +5 -0
- package/.changeset/hungry-rings-help.md +5 -0
- package/.changeset/pink-flowers-switch.md +5 -0
- package/.changeset/pre.json +7 -0
- package/.changeset/proud-humans-begin.md +5 -0
- package/CHANGELOG.md +22 -0
- package/README.md +5 -5
- package/apollo-client.cjs +1393 -1405
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +2 -7
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +2 -7
- package/cache/core/cache.d.ts +0 -11
- package/cache/core/cache.js +2 -7
- package/cache/core/cache.js.map +1 -1
- package/config/jest/areApolloErrorsEqual.d.ts +3 -0
- package/config/jest/areApolloErrorsEqual.js +23 -0
- package/config/jest/areApolloErrorsEqual.js.map +1 -0
- package/config/jest/areGraphQlErrorsEqual.d.ts +3 -0
- package/config/jest/areGraphQlErrorsEqual.js +7 -0
- package/config/jest/areGraphQlErrorsEqual.js.map +1 -0
- package/config/jest/setup.js +4 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ApolloClient.js +1 -1
- package/core/ApolloClient.js.map +1 -1
- package/core/QueryManager.d.ts +15 -14
- package/core/QueryManager.js +12 -13
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +806 -806
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +806 -806
- package/core/watchQueryOptions.d.ts +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/package.json +8 -5
- package/react/hooks/hooks.cjs +26 -33
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +26 -33
- package/react/hooks/useQuery.d.ts +2 -5
- package/react/hooks/useQuery.js +42 -53
- package/react/hooks/useQuery.js.map +1 -1
- package/react/internal/internal.cjs +1 -1
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +1 -1
- package/react/types/types.d.ts +6 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts +15 -0
- package/testing/core/mocking/mockQueryManager.js +5 -2
- package/testing/core/mocking/mockQueryManager.js.map +1 -1
- package/testing/experimental/createSchemaFetch.js +5 -12
- package/testing/experimental/createSchemaFetch.js.map +1 -1
- package/testing/experimental/experimental.cjs +3 -5
- package/testing/experimental/experimental.cjs.map +1 -1
- package/testing/experimental/experimental.cjs.native.js +3 -5
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/version.js +1 -1
|
@@ -153,7 +153,6 @@ function wrapHook(hookName, useHook, clientOrObsQuery) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
156
|
-
var originalResult = Symbol();
|
|
157
156
|
function noop() { }
|
|
158
157
|
var lastWatchOptions = Symbol();
|
|
159
158
|
function useQuery(query, options) {
|
|
@@ -216,10 +215,8 @@ function useQueryInternals(query, options) {
|
|
|
216
215
|
observable,
|
|
217
216
|
client, options, watchQueryOptions);
|
|
218
217
|
var obsQueryFields = React__namespace.useMemo(function () { return bindObservableMethods(observable); }, [observable]);
|
|
219
|
-
useHandleSkip(resultData,
|
|
220
|
-
observable, client, options, watchQueryOptions, disableNetworkFetches, isSyncSSR);
|
|
221
218
|
useRegisterSSRObservable(observable, renderPromises, ssrAllowed);
|
|
222
|
-
var result = useObservableSubscriptionResult(resultData, observable, client, disableNetworkFetches, partialRefetch, isSyncSSR, {
|
|
219
|
+
var result = useObservableSubscriptionResult(resultData, observable, client, options, watchQueryOptions, disableNetworkFetches, partialRefetch, isSyncSSR, {
|
|
223
220
|
onCompleted: options.onCompleted || noop,
|
|
224
221
|
onError: options.onError || noop,
|
|
225
222
|
});
|
|
@@ -232,13 +229,25 @@ function useQueryInternals(query, options) {
|
|
|
232
229
|
onQueryExecuted: onQueryExecuted,
|
|
233
230
|
};
|
|
234
231
|
}
|
|
235
|
-
function useObservableSubscriptionResult(resultData, observable, client, disableNetworkFetches, partialRefetch,
|
|
232
|
+
function useObservableSubscriptionResult(resultData, observable, client, options, watchQueryOptions, disableNetworkFetches, partialRefetch, isSyncSSR, callbacks) {
|
|
236
233
|
var callbackRef = React__namespace.useRef(callbacks);
|
|
237
234
|
React__namespace.useEffect(function () {
|
|
238
235
|
callbackRef.current = callbacks;
|
|
239
236
|
});
|
|
237
|
+
var resultOverride = ((isSyncSSR || disableNetworkFetches) &&
|
|
238
|
+
options.ssr === false &&
|
|
239
|
+
!options.skip) ?
|
|
240
|
+
ssrDisabledResult
|
|
241
|
+
: options.skip || watchQueryOptions.fetchPolicy === "standby" ?
|
|
242
|
+
skipStandbyResult
|
|
243
|
+
: void 0;
|
|
244
|
+
var previousData = resultData.previousData;
|
|
245
|
+
var currentResultOverride = React__namespace.useMemo(function () {
|
|
246
|
+
return resultOverride &&
|
|
247
|
+
toQueryResult(resultOverride, previousData, observable, client);
|
|
248
|
+
}, [client, observable, resultOverride, previousData]);
|
|
240
249
|
return useSyncExternalStore(React__namespace.useCallback(function (handleStoreChange) {
|
|
241
|
-
if (
|
|
250
|
+
if (isSyncSSR) {
|
|
242
251
|
return function () { };
|
|
243
252
|
}
|
|
244
253
|
var onNext = function () {
|
|
@@ -276,15 +285,17 @@ function useObservableSubscriptionResult(resultData, observable, client, disable
|
|
|
276
285
|
};
|
|
277
286
|
}, [
|
|
278
287
|
disableNetworkFetches,
|
|
279
|
-
|
|
288
|
+
isSyncSSR,
|
|
280
289
|
observable,
|
|
281
290
|
resultData,
|
|
282
291
|
partialRefetch,
|
|
283
292
|
client,
|
|
284
293
|
]), function () {
|
|
285
|
-
return
|
|
294
|
+
return currentResultOverride ||
|
|
295
|
+
getCurrentResult(resultData, observable, callbackRef.current, partialRefetch, client);
|
|
286
296
|
}, function () {
|
|
287
|
-
return
|
|
297
|
+
return currentResultOverride ||
|
|
298
|
+
getCurrentResult(resultData, observable, callbackRef.current, partialRefetch, client);
|
|
288
299
|
});
|
|
289
300
|
}
|
|
290
301
|
function useRegisterSSRObservable(observable, renderPromises, ssrAllowed) {
|
|
@@ -295,23 +306,6 @@ function useRegisterSSRObservable(observable, renderPromises, ssrAllowed) {
|
|
|
295
306
|
}
|
|
296
307
|
}
|
|
297
308
|
}
|
|
298
|
-
function useHandleSkip(
|
|
299
|
-
resultData, observable, client, options, watchQueryOptions, disableNetworkFetches, isSyncSSR) {
|
|
300
|
-
if ((isSyncSSR || disableNetworkFetches) &&
|
|
301
|
-
options.ssr === false &&
|
|
302
|
-
!options.skip) {
|
|
303
|
-
resultData.current = toQueryResult(ssrDisabledResult, resultData.previousData, observable, client);
|
|
304
|
-
}
|
|
305
|
-
else if (options.skip || watchQueryOptions.fetchPolicy === "standby") {
|
|
306
|
-
resultData.current = toQueryResult(skipStandbyResult, resultData.previousData, observable, client);
|
|
307
|
-
}
|
|
308
|
-
else if (
|
|
309
|
-
resultData.current &&
|
|
310
|
-
(resultData.current[originalResult] === ssrDisabledResult ||
|
|
311
|
-
resultData.current[originalResult] === skipStandbyResult)) {
|
|
312
|
-
resultData.current = void 0;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
309
|
function useResubscribeIfNecessary(
|
|
316
310
|
resultData,
|
|
317
311
|
observable, client, options, watchQueryOptions) {
|
|
@@ -370,11 +364,14 @@ function setResult(nextResult, resultData, observable, client, partialRefetch, f
|
|
|
370
364
|
if (previousResult && previousResult.data) {
|
|
371
365
|
resultData.previousData = previousResult.data;
|
|
372
366
|
}
|
|
367
|
+
if (!nextResult.error && utilities.isNonEmptyArray(nextResult.errors)) {
|
|
368
|
+
nextResult.error = new errors.ApolloError({ graphQLErrors: nextResult.errors });
|
|
369
|
+
}
|
|
373
370
|
resultData.current = toQueryResult(unsafeHandlePartialRefetch(nextResult, observable, partialRefetch), resultData.previousData, observable, client);
|
|
374
371
|
forceUpdate();
|
|
375
|
-
handleErrorOrCompleted(nextResult, previousResult === null || previousResult === void 0 ? void 0 : previousResult
|
|
372
|
+
handleErrorOrCompleted(nextResult, previousResult === null || previousResult === void 0 ? void 0 : previousResult.networkStatus, callbacks);
|
|
376
373
|
}
|
|
377
|
-
function handleErrorOrCompleted(result,
|
|
374
|
+
function handleErrorOrCompleted(result, previousNetworkStatus, callbacks) {
|
|
378
375
|
if (!result.loading) {
|
|
379
376
|
var error_1 = toApolloError$1(result);
|
|
380
377
|
Promise.resolve()
|
|
@@ -383,7 +380,7 @@ function handleErrorOrCompleted(result, previousResult, callbacks) {
|
|
|
383
380
|
callbacks.onError(error_1);
|
|
384
381
|
}
|
|
385
382
|
else if (result.data &&
|
|
386
|
-
|
|
383
|
+
previousNetworkStatus !== result.networkStatus &&
|
|
387
384
|
result.networkStatus === core.NetworkStatus.ready) {
|
|
388
385
|
callbacks.onCompleted(result.data);
|
|
389
386
|
}
|
|
@@ -413,10 +410,6 @@ function toApolloError$1(result) {
|
|
|
413
410
|
function toQueryResult(result, previousData, observable, client) {
|
|
414
411
|
var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
|
|
415
412
|
var queryResult = tslib.__assign(tslib.__assign({ data: data }, resultWithoutPartial), { client: client, observable: observable, variables: observable.variables, called: result !== ssrDisabledResult && result !== skipStandbyResult, previousData: previousData });
|
|
416
|
-
Object.defineProperty(queryResult, originalResult, { value: result });
|
|
417
|
-
if (!queryResult.error && utilities.isNonEmptyArray(result.errors)) {
|
|
418
|
-
queryResult.error = new errors.ApolloError({ graphQLErrors: result.errors });
|
|
419
|
-
}
|
|
420
413
|
return queryResult;
|
|
421
414
|
}
|
|
422
415
|
function unsafeHandlePartialRefetch(result, observable, partialRefetch) {
|
|
@@ -3,10 +3,7 @@ import { ApolloError } from "../../errors/index.js";
|
|
|
3
3
|
import type { ApolloQueryResult, ObservableQuery, DocumentNode, TypedDocumentNode, WatchQueryOptions } from "../../core/index.js";
|
|
4
4
|
import type { QueryHookOptions, QueryResult, ObservableQueryFields, NoInfer } from "../types/types.js";
|
|
5
5
|
import { useApolloClient } from "./useApolloClient.js";
|
|
6
|
-
|
|
7
|
-
interface InternalQueryResult<TData, TVariables extends OperationVariables> extends Omit<QueryResult<TData, TVariables>, Exclude<keyof ObservableQueryFields<TData, TVariables>, "variables">> {
|
|
8
|
-
[originalResult]: ApolloQueryResult<TData>;
|
|
9
|
-
}
|
|
6
|
+
type InternalQueryResult<TData, TVariables extends OperationVariables> = Omit<QueryResult<TData, TVariables>, Exclude<keyof ObservableQueryFields<TData, TVariables>, "variables">>;
|
|
10
7
|
export declare const lastWatchOptions: unique symbol;
|
|
11
8
|
export interface ObsQueryWithMeta<TData, TVariables extends OperationVariables> extends ObservableQuery<TData, TVariables> {
|
|
12
9
|
[lastWatchOptions]?: WatchQueryOptions<TVariables, TData>;
|
|
@@ -58,7 +55,7 @@ export type UpdateInternalState<TData, TVariables extends OperationVariables> =
|
|
|
58
55
|
*/
|
|
59
56
|
export declare function useQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>): QueryResult<TData, TVariables>;
|
|
60
57
|
export declare function useQueryInternals<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>): {
|
|
61
|
-
result: InternalQueryResult<TData, TVariables>;
|
|
58
|
+
result: InternalQueryResult<TData, TVariables> | InternalQueryResult<any, TVariables>;
|
|
62
59
|
obsQueryFields: Omit<ObservableQueryFields<TData, TVariables>, "variables">;
|
|
63
60
|
observable: ObsQueryWithMeta<TData, TVariables>;
|
|
64
61
|
resultData: InternalResult<TData, TVariables>;
|
package/react/hooks/useQuery.js
CHANGED
|
@@ -31,7 +31,6 @@ import { useApolloClient } from "./useApolloClient.js";
|
|
|
31
31
|
import { compact, isNonEmptyArray, maybeDeepFreeze, } from "../../utilities/index.js";
|
|
32
32
|
import { wrapHook } from "./internal/index.js";
|
|
33
33
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
34
|
-
var originalResult = Symbol();
|
|
35
34
|
function noop() { }
|
|
36
35
|
export var lastWatchOptions = Symbol();
|
|
37
36
|
/**
|
|
@@ -149,10 +148,8 @@ export function useQueryInternals(query, options) {
|
|
|
149
148
|
observable, // might get mutated during render
|
|
150
149
|
client, options, watchQueryOptions);
|
|
151
150
|
var obsQueryFields = React.useMemo(function () { return bindObservableMethods(observable); }, [observable]);
|
|
152
|
-
useHandleSkip(resultData, // might get mutated during render
|
|
153
|
-
observable, client, options, watchQueryOptions, disableNetworkFetches, isSyncSSR);
|
|
154
151
|
useRegisterSSRObservable(observable, renderPromises, ssrAllowed);
|
|
155
|
-
var result = useObservableSubscriptionResult(resultData, observable, client, disableNetworkFetches, partialRefetch, isSyncSSR, {
|
|
152
|
+
var result = useObservableSubscriptionResult(resultData, observable, client, options, watchQueryOptions, disableNetworkFetches, partialRefetch, isSyncSSR, {
|
|
156
153
|
onCompleted: options.onCompleted || noop,
|
|
157
154
|
onError: options.onError || noop,
|
|
158
155
|
});
|
|
@@ -165,7 +162,7 @@ export function useQueryInternals(query, options) {
|
|
|
165
162
|
onQueryExecuted: onQueryExecuted,
|
|
166
163
|
};
|
|
167
164
|
}
|
|
168
|
-
function useObservableSubscriptionResult(resultData, observable, client, disableNetworkFetches, partialRefetch,
|
|
165
|
+
function useObservableSubscriptionResult(resultData, observable, client, options, watchQueryOptions, disableNetworkFetches, partialRefetch, isSyncSSR, callbacks) {
|
|
169
166
|
var callbackRef = React.useRef(callbacks);
|
|
170
167
|
React.useEffect(function () {
|
|
171
168
|
// Make sure state.onCompleted and state.onError always reflect the latest
|
|
@@ -176,11 +173,35 @@ function useObservableSubscriptionResult(resultData, observable, client, disable
|
|
|
176
173
|
// base state object (without modifying the prototype).
|
|
177
174
|
callbackRef.current = callbacks;
|
|
178
175
|
});
|
|
176
|
+
var resultOverride = ((isSyncSSR || disableNetworkFetches) &&
|
|
177
|
+
options.ssr === false &&
|
|
178
|
+
!options.skip) ?
|
|
179
|
+
// If SSR has been explicitly disabled, and this function has been called
|
|
180
|
+
// on the server side, return the default loading state.
|
|
181
|
+
ssrDisabledResult
|
|
182
|
+
: options.skip || watchQueryOptions.fetchPolicy === "standby" ?
|
|
183
|
+
// When skipping a query (ie. we're not querying for data but still want to
|
|
184
|
+
// render children), make sure the `data` is cleared out and `loading` is
|
|
185
|
+
// set to `false` (since we aren't loading anything).
|
|
186
|
+
//
|
|
187
|
+
// NOTE: We no longer think this is the correct behavior. Skipping should
|
|
188
|
+
// not automatically set `data` to `undefined`, but instead leave the
|
|
189
|
+
// previous data in place. In other words, skipping should not mandate that
|
|
190
|
+
// previously received data is all of a sudden removed. Unfortunately,
|
|
191
|
+
// changing this is breaking, so we'll have to wait until Apollo Client 4.0
|
|
192
|
+
// to address this.
|
|
193
|
+
skipStandbyResult
|
|
194
|
+
: void 0;
|
|
195
|
+
var previousData = resultData.previousData;
|
|
196
|
+
var currentResultOverride = React.useMemo(function () {
|
|
197
|
+
return resultOverride &&
|
|
198
|
+
toQueryResult(resultOverride, previousData, observable, client);
|
|
199
|
+
}, [client, observable, resultOverride, previousData]);
|
|
179
200
|
return useSyncExternalStore(React.useCallback(function (handleStoreChange) {
|
|
180
201
|
// reference `disableNetworkFetches` here to ensure that the rules of hooks
|
|
181
202
|
// keep it as a dependency of this effect, even though it's not used
|
|
182
203
|
disableNetworkFetches;
|
|
183
|
-
if (
|
|
204
|
+
if (isSyncSSR) {
|
|
184
205
|
return function () { };
|
|
185
206
|
}
|
|
186
207
|
var onNext = function () {
|
|
@@ -232,15 +253,17 @@ function useObservableSubscriptionResult(resultData, observable, client, disable
|
|
|
232
253
|
};
|
|
233
254
|
}, [
|
|
234
255
|
disableNetworkFetches,
|
|
235
|
-
|
|
256
|
+
isSyncSSR,
|
|
236
257
|
observable,
|
|
237
258
|
resultData,
|
|
238
259
|
partialRefetch,
|
|
239
260
|
client,
|
|
240
261
|
]), function () {
|
|
241
|
-
return
|
|
262
|
+
return currentResultOverride ||
|
|
263
|
+
getCurrentResult(resultData, observable, callbackRef.current, partialRefetch, client);
|
|
242
264
|
}, function () {
|
|
243
|
-
return
|
|
265
|
+
return currentResultOverride ||
|
|
266
|
+
getCurrentResult(resultData, observable, callbackRef.current, partialRefetch, client);
|
|
244
267
|
});
|
|
245
268
|
}
|
|
246
269
|
function useRegisterSSRObservable(observable, renderPromises, ssrAllowed) {
|
|
@@ -252,38 +275,6 @@ function useRegisterSSRObservable(observable, renderPromises, ssrAllowed) {
|
|
|
252
275
|
}
|
|
253
276
|
}
|
|
254
277
|
}
|
|
255
|
-
function useHandleSkip(
|
|
256
|
-
/** this hook will mutate properties on `resultData` */
|
|
257
|
-
resultData, observable, client, options, watchQueryOptions, disableNetworkFetches, isSyncSSR) {
|
|
258
|
-
if ((isSyncSSR || disableNetworkFetches) &&
|
|
259
|
-
options.ssr === false &&
|
|
260
|
-
!options.skip) {
|
|
261
|
-
// If SSR has been explicitly disabled, and this function has been called
|
|
262
|
-
// on the server side, return the default loading state.
|
|
263
|
-
resultData.current = toQueryResult(ssrDisabledResult, resultData.previousData, observable, client);
|
|
264
|
-
}
|
|
265
|
-
else if (options.skip || watchQueryOptions.fetchPolicy === "standby") {
|
|
266
|
-
// When skipping a query (ie. we're not querying for data but still want to
|
|
267
|
-
// render children), make sure the `data` is cleared out and `loading` is
|
|
268
|
-
// set to `false` (since we aren't loading anything).
|
|
269
|
-
//
|
|
270
|
-
// NOTE: We no longer think this is the correct behavior. Skipping should
|
|
271
|
-
// not automatically set `data` to `undefined`, but instead leave the
|
|
272
|
-
// previous data in place. In other words, skipping should not mandate that
|
|
273
|
-
// previously received data is all of a sudden removed. Unfortunately,
|
|
274
|
-
// changing this is breaking, so we'll have to wait until Apollo Client 4.0
|
|
275
|
-
// to address this.
|
|
276
|
-
resultData.current = toQueryResult(skipStandbyResult, resultData.previousData, observable, client);
|
|
277
|
-
}
|
|
278
|
-
else if (
|
|
279
|
-
// reset result if the last render was skipping for some reason,
|
|
280
|
-
// but this render isn't skipping anymore
|
|
281
|
-
resultData.current &&
|
|
282
|
-
(resultData.current[originalResult] === ssrDisabledResult ||
|
|
283
|
-
resultData.current[originalResult] === skipStandbyResult)) {
|
|
284
|
-
resultData.current = void 0;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
278
|
// this hook is not compatible with any rules of React, and there's no good way to rewrite it.
|
|
288
279
|
// it should stay a separate hook that will not be optimized by the compiler
|
|
289
280
|
function useResubscribeIfNecessary(
|
|
@@ -382,13 +373,20 @@ function setResult(nextResult, resultData, observable, client, partialRefetch, f
|
|
|
382
373
|
if (previousResult && previousResult.data) {
|
|
383
374
|
resultData.previousData = previousResult.data;
|
|
384
375
|
}
|
|
376
|
+
if (!nextResult.error && isNonEmptyArray(nextResult.errors)) {
|
|
377
|
+
// Until a set naming convention for networkError and graphQLErrors is
|
|
378
|
+
// decided upon, we map errors (graphQLErrors) to the error options.
|
|
379
|
+
// TODO: Is it possible for both result.error and result.errors to be
|
|
380
|
+
// defined here?
|
|
381
|
+
nextResult.error = new ApolloError({ graphQLErrors: nextResult.errors });
|
|
382
|
+
}
|
|
385
383
|
resultData.current = toQueryResult(unsafeHandlePartialRefetch(nextResult, observable, partialRefetch), resultData.previousData, observable, client);
|
|
386
384
|
// Calling state.setResult always triggers an update, though some call sites
|
|
387
385
|
// perform additional equality checks before committing to an update.
|
|
388
386
|
forceUpdate();
|
|
389
|
-
handleErrorOrCompleted(nextResult, previousResult === null || previousResult === void 0 ? void 0 : previousResult
|
|
387
|
+
handleErrorOrCompleted(nextResult, previousResult === null || previousResult === void 0 ? void 0 : previousResult.networkStatus, callbacks);
|
|
390
388
|
}
|
|
391
|
-
function handleErrorOrCompleted(result,
|
|
389
|
+
function handleErrorOrCompleted(result, previousNetworkStatus, callbacks) {
|
|
392
390
|
if (!result.loading) {
|
|
393
391
|
var error_1 = toApolloError(result);
|
|
394
392
|
// wait a tick in case we are in the middle of rendering a component
|
|
@@ -398,7 +396,7 @@ function handleErrorOrCompleted(result, previousResult, callbacks) {
|
|
|
398
396
|
callbacks.onError(error_1);
|
|
399
397
|
}
|
|
400
398
|
else if (result.data &&
|
|
401
|
-
|
|
399
|
+
previousNetworkStatus !== result.networkStatus &&
|
|
402
400
|
result.networkStatus === NetworkStatus.ready) {
|
|
403
401
|
callbacks.onCompleted(result.data);
|
|
404
402
|
}
|
|
@@ -433,15 +431,6 @@ export function toApolloError(result) {
|
|
|
433
431
|
export function toQueryResult(result, previousData, observable, client) {
|
|
434
432
|
var data = result.data, partial = result.partial, resultWithoutPartial = __rest(result, ["data", "partial"]);
|
|
435
433
|
var queryResult = __assign(__assign({ data: data }, resultWithoutPartial), { client: client, observable: observable, variables: observable.variables, called: result !== ssrDisabledResult && result !== skipStandbyResult, previousData: previousData });
|
|
436
|
-
// non-enumerable property to hold the original result, for referential equality checks
|
|
437
|
-
Object.defineProperty(queryResult, originalResult, { value: result });
|
|
438
|
-
if (!queryResult.error && isNonEmptyArray(result.errors)) {
|
|
439
|
-
// Until a set naming convention for networkError and graphQLErrors is
|
|
440
|
-
// decided upon, we map errors (graphQLErrors) to the error options.
|
|
441
|
-
// TODO: Is it possible for both result.error and result.errors to be
|
|
442
|
-
// defined here?
|
|
443
|
-
queryResult.error = new ApolloError({ graphQLErrors: result.errors });
|
|
444
|
-
}
|
|
445
434
|
return queryResult;
|
|
446
435
|
}
|
|
447
436
|
function unsafeHandlePartialRefetch(result, observable, partialRefetch) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.js","sourceR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\n * readability and consistency. The order is as follows:\n *\n * resultData\n * observable\n * client\n * query\n * options\n * watchQueryOptions\n * makeWatchQueryOptions\n * isSSRAllowed\n * disableNetworkFetches\n * partialRefetch\n * renderPromises\n * isSyncSSR\n * callbacks\n */\n/** */\nimport { invariant } from \"../../utilities/globals/index.js\";\n\nimport * as React from \"rehackt\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport { equal } from \"@wry/equality\";\n\nimport type {\n ApolloClient,\n DefaultOptions,\n OperationVariables,\n WatchQueryFetchPolicy,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport { getApolloContext } from \"../context/index.js\";\nimport { ApolloError } from \"../../errors/index.js\";\nimport type {\n ApolloQueryResult,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { NetworkStatus } from \"../../core/index.js\";\nimport type {\n QueryHookOptions,\n QueryResult,\n ObservableQueryFields,\n NoInfer,\n} from \"../types/types.js\";\n\nimport { DocumentType, verifyDocumentType } from \"../parser/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n compact,\n isNonEmptyArray,\n maybeDeepFreeze,\n} from \"../../utilities/index.js\";\nimport { wrapHook } from \"./internal/index.js\";\nimport type { RenderPromises } from \"../ssr/RenderPromises.js\";\n\nconst {\n prototype: { hasOwnProperty },\n} = Object;\n\nconst originalResult = Symbol();\ninterface InternalQueryResult<TData, TVariables extends OperationVariables>\n extends Omit<\n QueryResult<TData, TVariables>,\n Exclude<keyof ObservableQueryFields<TData, TVariables>, \"variables\">\n > {\n [originalResult]: ApolloQueryResult<TData>;\n}\n\nfunction noop() {}\nexport const lastWatchOptions = Symbol();\n\nexport interface ObsQueryWithMeta<TData, TVariables extends OperationVariables>\n extends ObservableQuery<TData, TVariables> {\n [lastWatchOptions]?: WatchQueryOptions<TVariables, TData>;\n}\n\nexport interface InternalResult<TData, TVariables extends OperationVariables> {\n // These members are populated by getCurrentResult and setResult, and it's\n // okay/normal for them to be initially undefined.\n current?: undefined | InternalQueryResult<TData, TVariables>;\n previousData?: undefined | TData;\n}\n\ninterface InternalState<TData, TVariables extends OperationVariables> {\n client: ReturnType<typeof useApolloClient>;\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n observable: ObsQueryWithMeta<TData, TVariables>;\n resultData: InternalResult<TData, TVariables>;\n}\n\nexport type UpdateInternalState<\n TData,\n TVariables extends OperationVariables,\n> = (state: InternalState<TData, TVariables>) => void;\n\ninterface Callbacks<TData> {\n // Defining these methods as no-ops on the prototype allows us to call\n // state.onCompleted and/or state.onError without worrying about whether a\n // callback was provided.\n onCompleted(data: TData): void;\n onError(error: ApolloError): void;\n}\n\n/**\n * A hook for executing queries in an Apollo application.\n *\n * To run a query within a React component, call `useQuery` and pass it a GraphQL query document.\n *\n * When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, and `data` properties you can use to render your UI.\n *\n * > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.\n *\n * @example\n * ```jsx\n * import { gql, useQuery } from '@apollo/client';\n *\n * const GET_GREETING = gql`\n * query GetGreeting($language: String!) {\n * greeting(language: $language) {\n * message\n * }\n * }\n * `;\n *\n * function Hello() {\n * const { loading, error, data } = useQuery(GET_GREETING, {\n * variables: { language: 'english' },\n * });\n * if (loading) return <p>Loading ...</p>;\n * return <h1>Hello {data.greeting.message}!</h1>;\n * }\n * ```\n * @since 3.0.0\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - Options to control how the query is executed.\n * @returns Query result object\n */\nexport function useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<\n NoInfer<TData>,\n NoInfer<TVariables>\n > = Object.create(null)\n): QueryResult<TData, TVariables> {\n return wrapHook(\n \"useQuery\",\n _useQuery,\n useApolloClient(options && options.client)\n )(query, options);\n}\n\nfunction _useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n) {\n const { result, obsQueryFields } = useQueryInternals(query, options);\n return React.useMemo(\n () => ({ ...result, ...obsQueryFields }),\n [result, obsQueryFields]\n );\n}\n\nfunction useInternalState<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n client: ApolloClient<object>,\n query: DocumentNode | TypedDocumentNode<any, any>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n renderPromises: RenderPromises | undefined,\n makeWatchQueryOptions: () => WatchQueryOptions<TVariables, TData>\n) {\n function createInternalState(previous?: InternalState<TData, TVariables>) {\n verifyDocumentType(query, DocumentType.Query);\n\n const internalState: InternalState<TData, TVariables> = {\n client,\n query,\n observable:\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n (renderPromises &&\n renderPromises.getSSRObservable(makeWatchQueryOptions())) ||\n client.watchQuery(\n getObsQueryOptions(void 0, client, options, makeWatchQueryOptions())\n ),\n resultData: {\n // Reuse previousData from previous InternalState (if any) to provide\n // continuity of previousData even if/when the query or client changes.\n previousData: previous?.resultData.current?.data,\n },\n };\n\n return internalState as InternalState<TData, TVariables>;\n }\n\n let [internalState, updateInternalState] =\n React.useState(createInternalState);\n\n /**\n * Used by `useLazyQuery` when a new query is executed.\n * We keep this logic here since it needs to update things in unsafe\n * ways and here we at least can keep track of that in a single place.\n */\n function onQueryExecuted(\n watchQueryOptions: WatchQueryOptions<TVariables, TData>\n ) {\n // this needs to be set to prevent an immediate `resubscribe` in the\n // next rerender of the `useQuery` internals\n Object.assign(internalState.observable, {\n [lastWatchOptions]: watchQueryOptions,\n });\n const resultData = internalState.resultData;\n updateInternalState({\n ...internalState,\n // might be a different query\n query: watchQueryOptions.query,\n resultData: Object.assign(resultData, {\n // We need to modify the previous `resultData` object as we rely on the\n // object reference in other places\n previousData: resultData.current?.data || resultData.previousData,\n current: undefined,\n }),\n });\n }\n\n if (client !== internalState.client || query !== internalState.query) {\n // If the client or query have changed, we need to create a new InternalState.\n // This will trigger a re-render with the new state, but it will also continue\n // to run the current render function to completion.\n // Since we sometimes trigger some side-effects in the render function, we\n // re-assign `state` to the new state to ensure that those side-effects are\n // triggered with the new state.\n const newInternalState = createInternalState(internalState);\n updateInternalState(newInternalState);\n return [newInternalState, onQueryExecuted] as const;\n }\n\n return [internalState, onQueryExecuted] as const;\n}\n\nexport function useQueryInternals<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n) {\n const client = useApolloClient(options.client);\n\n const renderPromises = React.useContext(getApolloContext()).renderPromises;\n const isSyncSSR = !!renderPromises;\n const disableNetworkFetches = client.disableNetworkFetches;\n const ssrAllowed = options.ssr !== false && !options.skip;\n const partialRefetch = options.partialRefetch;\n\n const makeWatchQueryOptions = createMakeWatchQueryOptions(\n client,\n query,\n options,\n isSyncSSR\n );\n\n const [{ observable, resultData }, onQueryExecuted] = useInternalState(\n client,\n query,\n options,\n renderPromises,\n makeWatchQueryOptions\n );\n\n const watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>> =\n makeWatchQueryOptions(observable);\n\n useResubscribeIfNecessary<TData, TVariables>(\n resultData, // might get mutated during render\n observable, // might get mutated during render\n client,\n options,\n watchQueryOptions\n );\n\n const obsQueryFields = React.useMemo<\n Omit<ObservableQueryFields<TData, TVariables>, \"variables\">\n >(() => bindObservableMethods(observable), [observable]);\n\n useHandleSkip<TData, TVariables>(\n resultData, // might get mutated during render\n observable,\n client,\n options,\n watchQueryOptions,\n disableNetworkFetches,\n isSyncSSR\n );\n\n useRegisterSSRObservable(observable, renderPromises, ssrAllowed);\n\n const result = useObservableSubscriptionResult<TData, TVariables>(\n resultData,\n observable,\n client,\n disableNetworkFetches,\n partialRefetch,\n isSyncSSR,\n {\n onCompleted: options.onCompleted || noop,\n onError: options.onError || noop,\n }\n );\n\n return {\n result,\n obsQueryFields,\n observable,\n resultData,\n client,\n onQueryExecuted,\n };\n}\n\nfunction useObservableSubscriptionResult<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>,\n disableNetworkFetches: boolean,\n partialRefetch: boolean | undefined,\n skipSubscribing: boolean,\n callbacks: {\n onCompleted: (data: TData) => void;\n onError: (error: ApolloError) => void;\n }\n) {\n const callbackRef = React.useRef<Callbacks<TData>>(callbacks);\n React.useEffect(() => {\n // Make sure state.onCompleted and state.onError always reflect the latest\n // options.onCompleted and options.onError callbacks provided to useQuery,\n // since those functions are often recreated every time useQuery is called.\n // Like the forceUpdate method, the versions of these methods inherited from\n // InternalState.prototype are empty no-ops, but we can override them on the\n // base state object (without modifying the prototype).\n callbackRef.current = callbacks;\n });\n\n return useSyncExternalStore(\n React.useCallback(\n (handleStoreChange) => {\n // reference `disableNetworkFetches` here to ensure that the rules of hooks\n // keep it as a dependency of this effect, even though it's not used\n disableNetworkFetches;\n\n if (skipSubscribing) {\n return () => {};\n }\n\n const onNext = () => {\n const previousResult = resultData.current;\n // We use `getCurrentResult()` instead of the onNext argument because\n // the values differ slightly. Specifically, loading results will have\n // an empty object for data instead of `undefined` for some reason.\n const result = observable.getCurrentResult();\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n setResult(\n result,\n resultData,\n observable,\n client,\n partialRefetch,\n handleStoreChange,\n callbackRef.current\n );\n };\n\n const onError = (error: Error) => {\n subscription.current.unsubscribe();\n subscription.current = observable.resubscribeAfterError(\n onNext,\n onError\n );\n\n if (!hasOwnProperty.call(error, \"graphQLErrors\")) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = resultData.current;\n if (\n !previousResult ||\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n setResult(\n {\n data: (previousResult && previousResult.data) as TData,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n },\n resultData,\n observable,\n client,\n partialRefetch,\n handleStoreChange,\n callbackRef.current\n );\n }\n };\n\n // TODO evaluate if we keep this in\n // React Compiler cannot handle scoped `let` access, but a mutable object\n // like this is fine.\n // was:\n // let subscription = observable.subscribe(onNext, onError);\n const subscription = { current: observable.subscribe(onNext, onError) };\n\n // Do the \"unsubscribe\" with a short delay.\n // This way, an existing subscription can be reused without an additional\n // request if \"unsubscribe\" and \"resubscribe\" to the same ObservableQuery\n // happen in very fast succession.\n return () => {\n setTimeout(() => subscription.current.unsubscribe());\n };\n },\n\n [\n disableNetworkFetches,\n skipSubscribing,\n observable,\n resultData,\n partialRefetch,\n client,\n ]\n ),\n () =>\n getCurrentResult(\n resultData,\n observable,\n callbackRef.current,\n partialRefetch,\n client\n ),\n () =>\n getCurrentResult(\n resultData,\n observable,\n callbackRef.current,\n partialRefetch,\n client\n )\n );\n}\n\nfunction useRegisterSSRObservable(\n observable: ObsQueryWithMeta<any, any>,\n renderPromises: RenderPromises | undefined,\n ssrAllowed: boolean\n) {\n if (renderPromises && ssrAllowed) {\n renderPromises.registerSSRObservable(observable);\n\n if (observable.getCurrentResult().loading) {\n // TODO: This is a legacy API which could probably be cleaned up\n renderPromises.addObservableQueryPromise(observable);\n }\n }\n}\n\nfunction useHandleSkip<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n /** this hook will mutate properties on `resultData` */\n resultData: InternalResult<TData, TVariables>,\n observable: ObsQueryWithMeta<TData, TVariables>,\n client: ApolloClient<object>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>>,\n disableNetworkFetches: boolean,\n isSyncSSR: boolean\n) {\n if (\n (isSyncSSR || disableNetworkFetches) &&\n options.ssr === false &&\n !options.skip\n ) {\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n resultData.current = toQueryResult(\n ssrDisabledResult,\n resultData.previousData,\n observable,\n client\n );\n } else if (options.skip || watchQueryOptions.fetchPolicy === \"standby\") {\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n resultData.current = toQueryResult(\n skipStandbyResult,\n resultData.previousData,\n observable,\n client\n );\n } else if (\n // reset result if the last render was skipping for some reason,\n // but this render isn't skipping anymore\n resultData.current &&\n (resultData.current[originalResult] === ssrDisabledResult ||\n resultData.current[originalResult] === skipStandbyResult)\n ) {\n resultData.current = void 0;\n }\n}\n\n// this hook is not compatible with any rules of React, and there's no good way to rewrite it.\n// it should stay a separate hook that will not be optimized by the compiler\nfunction useResubscribeIfNecessary<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n /** this hook will mutate properties on `resultData` */\n resultData: InternalResult<TData, TVariables>,\n /** this hook will mutate properties on `observable` */\n observable: ObsQueryWithMeta<TData, TVariables>,\n client: ApolloClient<object>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>>\n) {\n if (\n observable[lastWatchOptions] &&\n !equal(observable[lastWatchOptions], watchQueryOptions)\n ) {\n // Though it might be tempting to postpone this reobserve call to the\n // useEffect block, we need getCurrentResult to return an appropriate\n // loading:true result synchronously (later within the same call to\n // useQuery). Since we already have this.observable here (not true for\n // the very first call to useQuery), we are not initiating any new\n // subscriptions, though it does feel less than ideal that reobserve\n // (potentially) kicks off a network request (for example, when the\n // variables have changed), which is technically a side-effect.\n observable.reobserve(\n getObsQueryOptions(observable, client, options, watchQueryOptions)\n );\n\n // Make sure getCurrentResult returns a fresh ApolloQueryResult<TData>,\n // but save the current data as this.previousData, just like setResult\n // usually does.\n resultData.previousData =\n resultData.current?.data || resultData.previousData;\n resultData.current = void 0;\n }\n observable[lastWatchOptions] = watchQueryOptions;\n}\n\n/*\n * A function to massage options before passing them to ObservableQuery.\n * This is two-step curried because we want to reuse the `make` function,\n * but the `observable` might differ between calls to `make`.\n */\nexport function createMakeWatchQueryOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n client: ApolloClient<object>,\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n {\n skip,\n ssr,\n onCompleted,\n onError,\n defaultOptions,\n // The above options are useQuery-specific, so this ...otherOptions spread\n // makes otherOptions almost a WatchQueryOptions object, except for the\n // query property that we add below.\n ...otherOptions\n }: QueryHookOptions<TData, TVariables> = {},\n isSyncSSR: boolean\n) {\n return (\n observable?: ObservableQuery<TData, TVariables>\n ): WatchQueryOptions<TVariables, TData> => {\n // This Object.assign is safe because otherOptions is a fresh ...rest object\n // that did not exist until just now, so modifications are still allowed.\n const watchQueryOptions: WatchQueryOptions<TVariables, TData> =\n Object.assign(otherOptions, { query });\n\n if (\n isSyncSSR &&\n (watchQueryOptions.fetchPolicy === \"network-only\" ||\n watchQueryOptions.fetchPolicy === \"cache-and-network\")\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = \"cache-first\";\n }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n if (skip) {\n // When skipping, we set watchQueryOptions.fetchPolicy initially to\n // \"standby\", but we also need/want to preserve the initial non-standby\n // fetchPolicy that would have been used if not skipping.\n watchQueryOptions.initialFetchPolicy =\n watchQueryOptions.initialFetchPolicy ||\n watchQueryOptions.fetchPolicy ||\n getDefaultFetchPolicy(defaultOptions, client.defaultOptions);\n watchQueryOptions.fetchPolicy = \"standby\";\n } else if (!watchQueryOptions.fetchPolicy) {\n watchQueryOptions.fetchPolicy =\n observable?.options.initialFetchPolicy ||\n getDefaultFetchPolicy(defaultOptions, client.defaultOptions);\n }\n\n return watchQueryOptions;\n };\n}\n\nexport function getObsQueryOptions<\n TData,\n TVariables extends OperationVariables,\n>(\n observable: ObservableQuery<TData, TVariables> | undefined,\n client: ApolloClient<object>,\n queryHookOptions: QueryHookOptions<TData, TVariables>,\n watchQueryOptions: Partial<WatchQueryOptions<TVariables, TData>>\n): WatchQueryOptions<TVariables, TData> {\n const toMerge: Array<Partial<WatchQueryOptions<TVariables, TData>>> = [];\n\n const globalDefaults = client.defaultOptions.watchQuery;\n if (globalDefaults) toMerge.push(globalDefaults);\n\n if (queryHookOptions.defaultOptions) {\n toMerge.push(queryHookOptions.defaultOptions);\n }\n\n // We use compact rather than mergeOptions for this part of the merge,\n // because we want watchQueryOptions.variables (if defined) to replace\n // this.observable.options.variables whole. This replacement allows\n // removing variables by removing them from the variables input to\n // useQuery. If the variables were always merged together (rather than\n // replaced), there would be no way to remove existing variables.\n // However, the variables from options.defaultOptions and globalDefaults\n // (if provided) should be merged, to ensure individual defaulted\n // variables always have values, if not otherwise defined in\n // observable.options or watchQueryOptions.\n toMerge.push(compact(observable && observable.options, watchQueryOptions));\n\n return toMerge.reduce(mergeOptions) as WatchQueryOptions<TVariables, TData>;\n}\n\nfunction setResult<TData, TVariables extends OperationVariables>(\n nextResult: ApolloQueryResult<TData>,\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>,\n partialRefetch: boolean | undefined,\n forceUpdate: () => void,\n callbacks: Callbacks<TData>\n) {\n const previousResult = resultData.current;\n if (previousResult && previousResult.data) {\n resultData.previousData = previousResult.data;\n }\n resultData.current = toQueryResult(\n unsafeHandlePartialRefetch(nextResult, observable, partialRefetch),\n resultData.previousData,\n observable,\n client\n );\n // Calling state.setResult always triggers an update, though some call sites\n // perform additional equality checks before committing to an update.\n forceUpdate();\n handleErrorOrCompleted(\n nextResult,\n previousResult?.[originalResult],\n callbacks\n );\n}\n\nfunction handleErrorOrCompleted<TData>(\n result: ApolloQueryResult<TData>,\n previousResult: ApolloQueryResult<TData> | undefined,\n callbacks: Callbacks<TData>\n) {\n if (!result.loading) {\n const error = toApolloError(result);\n\n // wait a tick in case we are in the middle of rendering a component\n Promise.resolve()\n .then(() => {\n if (error) {\n callbacks.onError(error);\n } else if (\n result.data &&\n previousResult?.networkStatus !== result.networkStatus &&\n result.networkStatus === NetworkStatus.ready\n ) {\n callbacks.onCompleted(result.data);\n }\n })\n .catch((error) => {\n invariant.warn(error);\n });\n }\n}\n\nfunction getCurrentResult<TData, TVariables extends OperationVariables>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n callbacks: Callbacks<TData>,\n partialRefetch: boolean | undefined,\n client: ApolloClient<object>\n): InternalQueryResult<TData, TVariables> {\n // Using this.result as a cache ensures getCurrentResult continues returning\n // the same (===) result object, unless state.setResult has been called, or\n // we're doing server rendering and therefore override the result below.\n if (!resultData.current) {\n // WARNING: SIDE-EFFECTS IN THE RENDER FUNCTION\n // this could call unsafeHandlePartialRefetch\n setResult(\n observable.getCurrentResult(),\n resultData,\n observable,\n client,\n partialRefetch,\n () => {},\n callbacks\n );\n }\n return resultData.current!;\n}\n\nexport function getDefaultFetchPolicy<\n TData,\n TVariables extends OperationVariables,\n>(\n queryHookDefaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>,\n clientDefaultOptions?: DefaultOptions\n): WatchQueryFetchPolicy {\n return (\n queryHookDefaultOptions?.fetchPolicy ||\n clientDefaultOptions?.watchQuery?.fetchPolicy ||\n \"cache-first\"\n );\n}\n\nexport function toApolloError<TData>(\n result: Pick<ApolloQueryResult<TData>, \"errors\" | \"error\">\n): ApolloError | undefined {\n return isNonEmptyArray(result.errors) ?\n new ApolloError({ graphQLErrors: result.errors })\n : result.error;\n}\n\nexport function toQueryResult<TData, TVariables extends OperationVariables>(\n result: ApolloQueryResult<TData>,\n previousData: TData | undefined,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>\n): InternalQueryResult<TData, TVariables> {\n const { data, partial, ...resultWithoutPartial } = result;\n const queryResult: InternalQueryResult<TData, TVariables> = {\n data, // Ensure always defined, even if result.data is missing.\n ...resultWithoutPartial,\n client: client,\n observable: observable,\n variables: observable.variables,\n called: result !== ssrDisabledResult && result !== skipStandbyResult,\n previousData,\n } satisfies Omit<\n InternalQueryResult<TData, TVariables>,\n typeof originalResult\n > as InternalQueryResult<TData, TVariables>;\n // non-enumerable property to hold the original result, for referential equality checks\n Object.defineProperty(queryResult, originalResult, { value: result });\n\n if (!queryResult.error && isNonEmptyArray(result.errors)) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n queryResult.error = new ApolloError({ graphQLErrors: result.errors });\n }\n\n return queryResult;\n}\n\nfunction unsafeHandlePartialRefetch<\n TData,\n TVariables extends OperationVariables,\n>(\n result: ApolloQueryResult<TData>,\n observable: ObservableQuery<TData, TVariables>,\n partialRefetch: boolean | undefined\n): ApolloQueryResult<TData> {\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n result.partial &&\n partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n observable.options.fetchPolicy !== \"cache-only\"\n ) {\n observable.refetch();\n return {\n ...result,\n loading: true,\n networkStatus: NetworkStatus.refetch,\n };\n }\n return result;\n}\n\nconst ssrDisabledResult = maybeDeepFreeze({\n loading: true,\n data: void 0 as any,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n});\n\nconst skipStandbyResult = maybeDeepFreeze({\n loading: false,\n data: void 0 as any,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n});\n\nfunction bindObservableMethods<TData, TVariables extends OperationVariables>(\n observable: ObservableQuery<TData, TVariables>\n) {\n return {\n refetch: observable.refetch.bind(observable),\n reobserve: observable.reobserve.bind(observable),\n fetchMore: observable.fetchMore.bind(observable),\n updateQuery: observable.updateQuery.bind(observable),\n startPolling: observable.startPolling.bind(observable),\n stopPolling: observable.stopPolling.bind(observable),\n subscribeToMore: observable.subscribeToMore.bind(observable),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM;AACN,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAQtC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAQpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQpD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,OAAO,EACP,eAAe,EACf,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIhC,IAAA,cAAc,GACzB,MAAM,yBADmB,CAClB;AAOX,SAAS,IAAI,KAAI,CAAC;AAClB,MAAM,CAAC,IAAM,gBAAgB,GAAG,MAAM,EAA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D,UAAU,CAAC,OAAO,EAAE,CAAC;QACrB,6BACK,MAAM,KACT,OAAO,EAAE,IAAI,EACb,aAAa,EAAE,aAAa,CAAC,OAAO,IACpC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,IAAM,iBAAiB,GAAG,eAAe,CAAC;IACxC,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,KAAK,CAAQ;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,aAAa,CAAC,OAAO;CACrC,CAAC,CAAC;AAEH,IAAM,iBAAiB,GAAG,eAAe,CAAC;IACxC,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,KAAK,CAAQ;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,aAAa,CAAC,KAAK;CACnC,CAAC,CAAC;AAEH,SAAS,qBAAqB,CAC5B,UAA8C;IAE9C,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAC5C,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC;QACpD,YAAY,EAAE,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;QACtD,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC;QACpD,eAAe,EAAE,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Function parameters in this file try to follow a common order for the sake of\n * readability and consistency. The order is as follows:\n *\n * resultData\n * observable\n * client\n * query\n * options\n * watchQueryOptions\n * makeWatchQueryOptions\n * isSSRAllowed\n * disableNetworkFetches\n * partialRefetch\n * renderPromises\n * isSyncSSR\n * callbacks\n */\n/** */\nimport { invariant } from \"../../utilities/globals/index.js\";\n\nimport * as React from \"rehackt\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport { equal } from \"@wry/equality\";\n\nimport type {\n ApolloClient,\n DefaultOptions,\n OperationVariables,\n WatchQueryFetchPolicy,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport { getApolloContext } from \"../context/index.js\";\nimport { ApolloError } from \"../../errors/index.js\";\nimport type {\n ApolloQueryResult,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { NetworkStatus } from \"../../core/index.js\";\nimport type {\n QueryHookOptions,\n QueryResult,\n ObservableQueryFields,\n NoInfer,\n} from \"../types/types.js\";\n\nimport { DocumentType, verifyDocumentType } from \"../parser/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n compact,\n isNonEmptyArray,\n maybeDeepFreeze,\n} from \"../../utilities/index.js\";\nimport { wrapHook } from \"./internal/index.js\";\nimport type { RenderPromises } from \"../ssr/RenderPromises.js\";\n\nconst {\n prototype: { hasOwnProperty },\n} = Object;\n\ntype InternalQueryResult<TData, TVariables extends OperationVariables> = Omit<\n QueryResult<TData, TVariables>,\n Exclude<keyof ObservableQueryFields<TData, TVariables>, \"variables\">\n>;\n\nfunction noop() {}\nexport const lastWatchOptions = Symbol();\n\nexport interface ObsQueryWithMeta<TData, TVariables extends OperationVariables>\n extends ObservableQuery<TData, TVariables> {\n [lastWatchOptions]?: WatchQueryOptions<TVariables, TData>;\n}\n\nexport interface InternalResult<TData, TVariables extends OperationVariables> {\n // These members are populated by getCurrentResult and setResult, and it's\n // okay/normal for them to be initially undefined.\n current?: undefined | InternalQueryResult<TData, TVariables>;\n previousData?: undefined | TData;\n}\n\ninterface InternalState<TData, TVariables extends OperationVariables> {\n client: ReturnType<typeof useApolloClient>;\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n observable: ObsQueryWithMeta<TData, TVariables>;\n resultData: InternalResult<TData, TVariables>;\n}\n\nexport type UpdateInternalState<\n TData,\n TVariables extends OperationVariables,\n> = (state: InternalState<TData, TVariables>) => void;\n\ninterface Callbacks<TData> {\n // Defining these methods as no-ops on the prototype allows us to call\n // state.onCompleted and/or state.onError without worrying about whether a\n // callback was provided.\n onCompleted(data: TData): void;\n onError(error: ApolloError): void;\n}\n\n/**\n * A hook for executing queries in an Apollo application.\n *\n * To run a query within a React component, call `useQuery` and pass it a GraphQL query document.\n *\n * When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, and `data` properties you can use to render your UI.\n *\n * > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.\n *\n * @example\n * ```jsx\n * import { gql, useQuery } from '@apollo/client';\n *\n * const GET_GREETING = gql`\n * query GetGreeting($language: String!) {\n * greeting(language: $language) {\n * message\n * }\n * }\n * `;\n *\n * function Hello() {\n * const { loading, error, data } = useQuery(GET_GREETING, {\n * variables: { language: 'english' },\n * });\n * if (loading) return <p>Loading ...</p>;\n * return <h1>Hello {data.greeting.message}!</h1>;\n * }\n * ```\n * @since 3.0.0\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - Options to control how the query is executed.\n * @returns Query result object\n */\nexport function useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<\n NoInfer<TData>,\n NoInfer<TVariables>\n > = Object.create(null)\n): QueryResult<TData, TVariables> {\n return wrapHook(\n \"useQuery\",\n _useQuery,\n useApolloClient(options && options.client)\n )(query, options);\n}\n\nfunction _useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n) {\n const { result, obsQueryFields } = useQueryInternals(query, options);\n return React.useMemo(\n () => ({ ...result, ...obsQueryFields }),\n [result, obsQueryFields]\n );\n}\n\nfunction useInternalState<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n client: ApolloClient<object>,\n query: DocumentNode | TypedDocumentNode<any, any>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n renderPromises: RenderPromises | undefined,\n makeWatchQueryOptions: () => WatchQueryOptions<TVariables, TData>\n) {\n function createInternalState(previous?: InternalState<TData, TVariables>) {\n verifyDocumentType(query, DocumentType.Query);\n\n const internalState: InternalState<TData, TVariables> = {\n client,\n query,\n observable:\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n (renderPromises &&\n renderPromises.getSSRObservable(makeWatchQueryOptions())) ||\n client.watchQuery(\n getObsQueryOptions(void 0, client, options, makeWatchQueryOptions())\n ),\n resultData: {\n // Reuse previousData from previous InternalState (if any) to provide\n // continuity of previousData even if/when the query or client changes.\n previousData: previous?.resultData.current?.data,\n },\n };\n\n return internalState as InternalState<TData, TVariables>;\n }\n\n let [internalState, updateInternalState] =\n React.useState(createInternalState);\n\n /**\n * Used by `useLazyQuery` when a new query is executed.\n * We keep this logic here since it needs to update things in unsafe\n * ways and here we at least can keep track of that in a single place.\n */\n function onQueryExecuted(\n watchQueryOptions: WatchQueryOptions<TVariables, TData>\n ) {\n // this needs to be set to prevent an immediate `resubscribe` in the\n // next rerender of the `useQuery` internals\n Object.assign(internalState.observable, {\n [lastWatchOptions]: watchQueryOptions,\n });\n const resultData = internalState.resultData;\n updateInternalState({\n ...internalState,\n // might be a different query\n query: watchQueryOptions.query,\n resultData: Object.assign(resultData, {\n // We need to modify the previous `resultData` object as we rely on the\n // object reference in other places\n previousData: resultData.current?.data || resultData.previousData,\n current: undefined,\n }),\n });\n }\n\n if (client !== internalState.client || query !== internalState.query) {\n // If the client or query have changed, we need to create a new InternalState.\n // This will trigger a re-render with the new state, but it will also continue\n // to run the current render function to completion.\n // Since we sometimes trigger some side-effects in the render function, we\n // re-assign `state` to the new state to ensure that those side-effects are\n // triggered with the new state.\n const newInternalState = createInternalState(internalState);\n updateInternalState(newInternalState);\n return [newInternalState, onQueryExecuted] as const;\n }\n\n return [internalState, onQueryExecuted] as const;\n}\n\nexport function useQueryInternals<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n) {\n const client = useApolloClient(options.client);\n\n const renderPromises = React.useContext(getApolloContext()).renderPromises;\n const isSyncSSR = !!renderPromises;\n const disableNetworkFetches = client.disableNetworkFetches;\n const ssrAllowed = options.ssr !== false && !options.skip;\n const partialRefetch = options.partialRefetch;\n\n const makeWatchQueryOptions = createMakeWatchQueryOptions(\n client,\n query,\n options,\n isSyncSSR\n );\n\n const [{ observable, resultData }, onQueryExecuted] = useInternalState(\n client,\n query,\n options,\n renderPromises,\n makeWatchQueryOptions\n );\n\n const watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>> =\n makeWatchQueryOptions(observable);\n\n useResubscribeIfNecessary<TData, TVariables>(\n resultData, // might get mutated during render\n observable, // might get mutated during render\n client,\n options,\n watchQueryOptions\n );\n\n const obsQueryFields = React.useMemo<\n Omit<ObservableQueryFields<TData, TVariables>, \"variables\">\n >(() => bindObservableMethods(observable), [observable]);\n\n useRegisterSSRObservable(observable, renderPromises, ssrAllowed);\n\n const result = useObservableSubscriptionResult<TData, TVariables>(\n resultData,\n observable,\n client,\n options,\n watchQueryOptions,\n disableNetworkFetches,\n partialRefetch,\n isSyncSSR,\n {\n onCompleted: options.onCompleted || noop,\n onError: options.onError || noop,\n }\n );\n\n return {\n result,\n obsQueryFields,\n observable,\n resultData,\n client,\n onQueryExecuted,\n };\n}\n\nfunction useObservableSubscriptionResult<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>>,\n disableNetworkFetches: boolean,\n partialRefetch: boolean | undefined,\n isSyncSSR: boolean,\n callbacks: {\n onCompleted: (data: TData) => void;\n onError: (error: ApolloError) => void;\n }\n) {\n const callbackRef = React.useRef<Callbacks<TData>>(callbacks);\n React.useEffect(() => {\n // Make sure state.onCompleted and state.onError always reflect the latest\n // options.onCompleted and options.onError callbacks provided to useQuery,\n // since those functions are often recreated every time useQuery is called.\n // Like the forceUpdate method, the versions of these methods inherited from\n // InternalState.prototype are empty no-ops, but we can override them on the\n // base state object (without modifying the prototype).\n callbackRef.current = callbacks;\n });\n\n const resultOverride =\n (\n (isSyncSSR || disableNetworkFetches) &&\n options.ssr === false &&\n !options.skip\n ) ?\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n ssrDisabledResult\n : options.skip || watchQueryOptions.fetchPolicy === \"standby\" ?\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n skipStandbyResult\n : void 0;\n\n const previousData = resultData.previousData;\n const currentResultOverride = React.useMemo(\n () =>\n resultOverride &&\n toQueryResult(resultOverride, previousData, observable, client),\n [client, observable, resultOverride, previousData]\n );\n\n return useSyncExternalStore(\n React.useCallback(\n (handleStoreChange) => {\n // reference `disableNetworkFetches` here to ensure that the rules of hooks\n // keep it as a dependency of this effect, even though it's not used\n disableNetworkFetches;\n\n if (isSyncSSR) {\n return () => {};\n }\n\n const onNext = () => {\n const previousResult = resultData.current;\n // We use `getCurrentResult()` instead of the onNext argument because\n // the values differ slightly. Specifically, loading results will have\n // an empty object for data instead of `undefined` for some reason.\n const result = observable.getCurrentResult();\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n setResult(\n result,\n resultData,\n observable,\n client,\n partialRefetch,\n handleStoreChange,\n callbackRef.current\n );\n };\n\n const onError = (error: Error) => {\n subscription.current.unsubscribe();\n subscription.current = observable.resubscribeAfterError(\n onNext,\n onError\n );\n\n if (!hasOwnProperty.call(error, \"graphQLErrors\")) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = resultData.current;\n if (\n !previousResult ||\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n setResult(\n {\n data: (previousResult && previousResult.data) as TData,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n },\n resultData,\n observable,\n client,\n partialRefetch,\n handleStoreChange,\n callbackRef.current\n );\n }\n };\n\n // TODO evaluate if we keep this in\n // React Compiler cannot handle scoped `let` access, but a mutable object\n // like this is fine.\n // was:\n // let subscription = observable.subscribe(onNext, onError);\n const subscription = { current: observable.subscribe(onNext, onError) };\n\n // Do the \"unsubscribe\" with a short delay.\n // This way, an existing subscription can be reused without an additional\n // request if \"unsubscribe\" and \"resubscribe\" to the same ObservableQuery\n // happen in very fast succession.\n return () => {\n setTimeout(() => subscription.current.unsubscribe());\n };\n },\n\n [\n disableNetworkFetches,\n isSyncSSR,\n observable,\n resultData,\n partialRefetch,\n client,\n ]\n ),\n () =>\n currentResultOverride ||\n getCurrentResult(\n resultData,\n observable,\n callbackRef.current,\n partialRefetch,\n client\n ),\n () =>\n currentResultOverride ||\n getCurrentResult(\n resultData,\n observable,\n callbackRef.current,\n partialRefetch,\n client\n )\n );\n}\n\nfunction useRegisterSSRObservable(\n observable: ObsQueryWithMeta<any, any>,\n renderPromises: RenderPromises | undefined,\n ssrAllowed: boolean\n) {\n if (renderPromises && ssrAllowed) {\n renderPromises.registerSSRObservable(observable);\n\n if (observable.getCurrentResult().loading) {\n // TODO: This is a legacy API which could probably be cleaned up\n renderPromises.addObservableQueryPromise(observable);\n }\n }\n}\n\n// this hook is not compatible with any rules of React, and there's no good way to rewrite it.\n// it should stay a separate hook that will not be optimized by the compiler\nfunction useResubscribeIfNecessary<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n /** this hook will mutate properties on `resultData` */\n resultData: InternalResult<TData, TVariables>,\n /** this hook will mutate properties on `observable` */\n observable: ObsQueryWithMeta<TData, TVariables>,\n client: ApolloClient<object>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>>\n) {\n if (\n observable[lastWatchOptions] &&\n !equal(observable[lastWatchOptions], watchQueryOptions)\n ) {\n // Though it might be tempting to postpone this reobserve call to the\n // useEffect block, we need getCurrentResult to return an appropriate\n // loading:true result synchronously (later within the same call to\n // useQuery). Since we already have this.observable here (not true for\n // the very first call to useQuery), we are not initiating any new\n // subscriptions, though it does feel less than ideal that reobserve\n // (potentially) kicks off a network request (for example, when the\n // variables have changed), which is technically a side-effect.\n observable.reobserve(\n getObsQueryOptions(observable, client, options, watchQueryOptions)\n );\n\n // Make sure getCurrentResult returns a fresh ApolloQueryResult<TData>,\n // but save the current data as this.previousData, just like setResult\n // usually does.\n resultData.previousData =\n resultData.current?.data || resultData.previousData;\n resultData.current = void 0;\n }\n observable[lastWatchOptions] = watchQueryOptions;\n}\n\n/*\n * A function to massage options before passing them to ObservableQuery.\n * This is two-step curried because we want to reuse the `make` function,\n * but the `observable` might differ between calls to `make`.\n */\nexport function createMakeWatchQueryOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n client: ApolloClient<object>,\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n {\n skip,\n ssr,\n onCompleted,\n onError,\n defaultOptions,\n // The above options are useQuery-specific, so this ...otherOptions spread\n // makes otherOptions almost a WatchQueryOptions object, except for the\n // query property that we add below.\n ...otherOptions\n }: QueryHookOptions<TData, TVariables> = {},\n isSyncSSR: boolean\n) {\n return (\n observable?: ObservableQuery<TData, TVariables>\n ): WatchQueryOptions<TVariables, TData> => {\n // This Object.assign is safe because otherOptions is a fresh ...rest object\n // that did not exist until just now, so modifications are still allowed.\n const watchQueryOptions: WatchQueryOptions<TVariables, TData> =\n Object.assign(otherOptions, { query });\n\n if (\n isSyncSSR &&\n (watchQueryOptions.fetchPolicy === \"network-only\" ||\n watchQueryOptions.fetchPolicy === \"cache-and-network\")\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = \"cache-first\";\n }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n if (skip) {\n // When skipping, we set watchQueryOptions.fetchPolicy initially to\n // \"standby\", but we also need/want to preserve the initial non-standby\n // fetchPolicy that would have been used if not skipping.\n watchQueryOptions.initialFetchPolicy =\n watchQueryOptions.initialFetchPolicy ||\n watchQueryOptions.fetchPolicy ||\n getDefaultFetchPolicy(defaultOptions, client.defaultOptions);\n watchQueryOptions.fetchPolicy = \"standby\";\n } else if (!watchQueryOptions.fetchPolicy) {\n watchQueryOptions.fetchPolicy =\n observable?.options.initialFetchPolicy ||\n getDefaultFetchPolicy(defaultOptions, client.defaultOptions);\n }\n\n return watchQueryOptions;\n };\n}\n\nexport function getObsQueryOptions<\n TData,\n TVariables extends OperationVariables,\n>(\n observable: ObservableQuery<TData, TVariables> | undefined,\n client: ApolloClient<object>,\n queryHookOptions: QueryHookOptions<TData, TVariables>,\n watchQueryOptions: Partial<WatchQueryOptions<TVariables, TData>>\n): WatchQueryOptions<TVariables, TData> {\n const toMerge: Array<Partial<WatchQueryOptions<TVariables, TData>>> = [];\n\n const globalDefaults = client.defaultOptions.watchQuery;\n if (globalDefaults) toMerge.push(globalDefaults);\n\n if (queryHookOptions.defaultOptions) {\n toMerge.push(queryHookOptions.defaultOptions);\n }\n\n // We use compact rather than mergeOptions for this part of the merge,\n // because we want watchQueryOptions.variables (if defined) to replace\n // this.observable.options.variables whole. This replacement allows\n // removing variables by removing them from the variables input to\n // useQuery. If the variables were always merged together (rather than\n // replaced), there would be no way to remove existing variables.\n // However, the variables from options.defaultOptions and globalDefaults\n // (if provided) should be merged, to ensure individual defaulted\n // variables always have values, if not otherwise defined in\n // observable.options or watchQueryOptions.\n toMerge.push(compact(observable && observable.options, watchQueryOptions));\n\n return toMerge.reduce(mergeOptions) as WatchQueryOptions<TVariables, TData>;\n}\n\nfunction setResult<TData, TVariables extends OperationVariables>(\n nextResult: ApolloQueryResult<TData>,\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>,\n partialRefetch: boolean | undefined,\n forceUpdate: () => void,\n callbacks: Callbacks<TData>\n) {\n const previousResult = resultData.current;\n if (previousResult && previousResult.data) {\n resultData.previousData = previousResult.data;\n }\n\n if (!nextResult.error && isNonEmptyArray(nextResult.errors)) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n nextResult.error = new ApolloError({ graphQLErrors: nextResult.errors });\n }\n\n resultData.current = toQueryResult(\n unsafeHandlePartialRefetch(nextResult, observable, partialRefetch),\n resultData.previousData,\n observable,\n client\n );\n // Calling state.setResult always triggers an update, though some call sites\n // perform additional equality checks before committing to an update.\n forceUpdate();\n handleErrorOrCompleted(nextResult, previousResult?.networkStatus, callbacks);\n}\n\nfunction handleErrorOrCompleted<TData>(\n result: ApolloQueryResult<TData>,\n previousNetworkStatus: NetworkStatus | undefined,\n callbacks: Callbacks<TData>\n) {\n if (!result.loading) {\n const error = toApolloError(result);\n\n // wait a tick in case we are in the middle of rendering a component\n Promise.resolve()\n .then(() => {\n if (error) {\n callbacks.onError(error);\n } else if (\n result.data &&\n previousNetworkStatus !== result.networkStatus &&\n result.networkStatus === NetworkStatus.ready\n ) {\n callbacks.onCompleted(result.data);\n }\n })\n .catch((error) => {\n invariant.warn(error);\n });\n }\n}\n\nfunction getCurrentResult<TData, TVariables extends OperationVariables>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n callbacks: Callbacks<TData>,\n partialRefetch: boolean | undefined,\n client: ApolloClient<object>\n): InternalQueryResult<TData, TVariables> {\n // Using this.result as a cache ensures getCurrentResult continues returning\n // the same (===) result object, unless state.setResult has been called, or\n // we're doing server rendering and therefore override the result below.\n if (!resultData.current) {\n // WARNING: SIDE-EFFECTS IN THE RENDER FUNCTION\n // this could call unsafeHandlePartialRefetch\n setResult(\n observable.getCurrentResult(),\n resultData,\n observable,\n client,\n partialRefetch,\n () => {},\n callbacks\n );\n }\n return resultData.current!;\n}\n\nexport function getDefaultFetchPolicy<\n TData,\n TVariables extends OperationVariables,\n>(\n queryHookDefaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>,\n clientDefaultOptions?: DefaultOptions\n): WatchQueryFetchPolicy {\n return (\n queryHookDefaultOptions?.fetchPolicy ||\n clientDefaultOptions?.watchQuery?.fetchPolicy ||\n \"cache-first\"\n );\n}\n\nexport function toApolloError<TData>(\n result: Pick<ApolloQueryResult<TData>, \"errors\" | \"error\">\n): ApolloError | undefined {\n return isNonEmptyArray(result.errors) ?\n new ApolloError({ graphQLErrors: result.errors })\n : result.error;\n}\n\nexport function toQueryResult<TData, TVariables extends OperationVariables>(\n result: ApolloQueryResult<TData>,\n previousData: TData | undefined,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>\n): InternalQueryResult<TData, TVariables> {\n const { data, partial, ...resultWithoutPartial } = result;\n const queryResult: InternalQueryResult<TData, TVariables> = {\n data, // Ensure always defined, even if result.data is missing.\n ...resultWithoutPartial,\n client: client,\n observable: observable,\n variables: observable.variables,\n called: result !== ssrDisabledResult && result !== skipStandbyResult,\n previousData,\n };\n return queryResult;\n}\n\nfunction unsafeHandlePartialRefetch<\n TData,\n TVariables extends OperationVariables,\n>(\n result: ApolloQueryResult<TData>,\n observable: ObservableQuery<TData, TVariables>,\n partialRefetch: boolean | undefined\n): ApolloQueryResult<TData> {\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n result.partial &&\n partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n observable.options.fetchPolicy !== \"cache-only\"\n ) {\n observable.refetch();\n return {\n ...result,\n loading: true,\n networkStatus: NetworkStatus.refetch,\n };\n }\n return result;\n}\n\nconst ssrDisabledResult = maybeDeepFreeze({\n loading: true,\n data: void 0 as any,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n});\n\nconst skipStandbyResult = maybeDeepFreeze({\n loading: false,\n data: void 0 as any,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n});\n\nfunction bindObservableMethods<TData, TVariables extends OperationVariables>(\n observable: ObservableQuery<TData, TVariables>\n) {\n return {\n refetch: observable.refetch.bind(observable),\n reobserve: observable.reobserve.bind(observable),\n fetchMore: observable.fetchMore.bind(observable),\n updateQuery: observable.updateQuery.bind(observable),\n startPolling: observable.startPolling.bind(observable),\n stopPolling: observable.stopPolling.bind(observable),\n subscribeToMore: observable.subscribeToMore.bind(observable),\n };\n}\n"]}
|