@apollo/client 3.11.7 → 3.12.0-alpha.0
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/nasty-camels-pay.md +36 -0
- package/.changeset/pre.json +10 -0
- package/CHANGELOG.md +43 -0
- package/apollo-client.cjs +438 -111
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +218 -22
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +218 -22
- package/cache/core/cache.d.ts +13 -10
- package/cache/core/cache.js +32 -14
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +2 -1
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +4 -3
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/inMemoryCache.d.ts +3 -1
- package/cache/inmemory/inMemoryCache.js +7 -0
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +4 -4
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ApolloClient.d.ts +14 -6
- package/core/ApolloClient.js +14 -6
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +2 -2
- package/core/ObservableQuery.d.ts +17 -14
- package/core/ObservableQuery.js +29 -16
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +18 -3
- package/core/QueryManager.js +39 -14
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +285 -37
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +285 -37
- package/core/index.d.ts +1 -0
- package/core/index.js.map +1 -1
- package/core/masking.d.ts +4 -0
- package/core/masking.js +212 -0
- package/core/masking.js.map +1 -0
- package/core/types.d.ts +3 -2
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.d.ts +8 -6
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +131 -87
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +131 -87
- package/invariantErrorCodes.js +140 -86
- package/link/core/ApolloLink.js +2 -2
- package/link/core/core.cjs +2 -2
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +2 -2
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/http.cjs +6 -6
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +6 -6
- package/link/http/selectHttpOptionsAndBody.js +3 -3
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/persisted-queries.cjs +2 -2
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
- package/link/utils/toPromise.js +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js +1 -1
- package/masking/index.d.ts +2 -0
- package/masking/index.js +2 -0
- package/masking/index.js.map +1 -0
- package/masking/internal/types.d.ts +15 -0
- package/masking/internal/types.js +2 -0
- package/masking/internal/types.js.map +1 -0
- package/masking/masking.cjs +3 -0
- package/masking/masking.cjs.map +1 -0
- package/masking/masking.cjs.native.js +3 -0
- package/masking/masking.d.cts +1 -0
- package/masking/package.json +8 -0
- package/masking/types.d.ts +44 -0
- package/masking/types.js +2 -0
- package/masking/types.js.map +1 -0
- package/package.json +2 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs +3 -3
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +3 -3
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs +2 -2
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +2 -2
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs +24 -16
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +24 -16
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useFragment.d.ts +4 -3
- package/react/hooks/useFragment.js +12 -5
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +1 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.js +2 -2
- package/react/hooks/useQuery.d.ts +4 -3
- package/react/hooks/useQuery.js +2 -1
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +2 -1
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +2 -1
- package/react/hooks/useSubscription.js +3 -3
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +6 -5
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/internal/cache/QueryReference.d.ts +5 -4
- package/react/internal/cache/QueryReference.js +1 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/internal.cjs +2 -2
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +2 -2
- package/react/parser/index.js +5 -5
- package/react/parser/parser.cjs +5 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +5 -5
- package/react/types/types.d.ts +18 -42
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +3 -3
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +3 -3
- package/testing/core/mocking/mockLink.d.ts +3 -2
- package/testing/core/mocking/mockLink.js +3 -3
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts +1 -0
- package/testing/core/mocking/mockQueryManager.js +1 -1
- package/testing/core/mocking/mockQueryManager.js.map +1 -1
- package/testing/internal/disposables/index.d.ts +1 -0
- package/testing/internal/disposables/index.js +1 -0
- package/testing/internal/disposables/index.js.map +1 -1
- package/testing/internal/disposables/withProdMode.d.ts +4 -0
- package/testing/internal/disposables/withProdMode.js +10 -0
- package/testing/internal/disposables/withProdMode.js.map +1 -0
- package/testing/internal/scenarios/index.d.ts +28 -0
- package/testing/internal/scenarios/index.js +18 -2
- package/testing/internal/scenarios/index.js.map +1 -1
- package/utilities/common/maybeDeepFreeze.d.ts +1 -0
- package/utilities/common/maybeDeepFreeze.js +1 -1
- package/utilities/common/maybeDeepFreeze.js.map +1 -1
- 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/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/graphql/directives.d.ts +3 -1
- package/utilities/graphql/directives.js +39 -5
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.js +3 -3
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/transform.d.ts +1 -0
- package/utilities/graphql/transform.js +15 -2
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +7 -3
- package/utilities/index.js +4 -3
- package/utilities/index.js.map +1 -1
- package/utilities/promises/preventUnhandledRejection.d.ts +2 -0
- package/utilities/promises/preventUnhandledRejection.js +5 -0
- package/utilities/promises/preventUnhandledRejection.js.map +1 -0
- package/utilities/subscriptions/relay/relay.cjs.map +1 -1
- package/utilities/subscriptions/urql/urql.cjs.map +1 -1
- package/utilities/types/NoInfer.d.ts +27 -0
- package/utilities/types/NoInfer.js +2 -0
- package/utilities/types/NoInfer.js.map +1 -0
- package/utilities/types/Prettify.d.ts +4 -0
- package/utilities/types/Prettify.js +2 -0
- package/utilities/types/Prettify.js.map +1 -0
- package/utilities/types/UnionToIntersection.d.ts +2 -0
- package/utilities/types/UnionToIntersection.js +2 -0
- package/utilities/types/UnionToIntersection.js.map +1 -0
- package/utilities/utilities.cjs +73 -19
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +73 -19
- package/version.js +1 -1
|
@@ -34,7 +34,7 @@ var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
|
34
34
|
function useApolloClient(override) {
|
|
35
35
|
var context$1 = React__namespace.useContext(context.getApolloContext());
|
|
36
36
|
var client = override || context$1.client;
|
|
37
|
-
globals.invariant(!!client,
|
|
37
|
+
globals.invariant(!!client, 57);
|
|
38
38
|
return client;
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -49,7 +49,7 @@ var useSyncExternalStore = realHook$1 ||
|
|
|
49
49
|
!didWarnUncachedGetSnapshot &&
|
|
50
50
|
value !== getSnapshot()) {
|
|
51
51
|
didWarnUncachedGetSnapshot = true;
|
|
52
|
-
globalThis.__DEV__ !== false && globals.invariant.error(
|
|
52
|
+
globalThis.__DEV__ !== false && globals.invariant.error(67);
|
|
53
53
|
}
|
|
54
54
|
var _a = React__namespace.useState({
|
|
55
55
|
inst: { value: value, getSnapshot: getSnapshot },
|
|
@@ -263,7 +263,8 @@ function useObservableSubscriptionResult(resultData, observable, client, options
|
|
|
263
263
|
(previousResult && previousResult.loading) ||
|
|
264
264
|
!equal.equal(error, previousResult.error)) {
|
|
265
265
|
setResult({
|
|
266
|
-
data: (previousResult &&
|
|
266
|
+
data: (previousResult &&
|
|
267
|
+
previousResult.data),
|
|
267
268
|
error: error,
|
|
268
269
|
loading: false,
|
|
269
270
|
networkStatus: core.NetworkStatus.error,
|
|
@@ -527,7 +528,7 @@ function executeQuery(resultData, observable, client, currentQuery, options, onQ
|
|
|
527
528
|
resolve(toQueryResult(observable.getCurrentResult(), resultData.previousData, observable, client));
|
|
528
529
|
},
|
|
529
530
|
complete: function () {
|
|
530
|
-
resolve(toQueryResult(result, resultData.previousData, observable, client));
|
|
531
|
+
resolve(toQueryResult(observable["maskResult"](result), resultData.previousData, observable, client));
|
|
531
532
|
},
|
|
532
533
|
});
|
|
533
534
|
});
|
|
@@ -652,10 +653,10 @@ function useSubscription(subscription, options) {
|
|
|
652
653
|
if (!hasIssuedDeprecationWarningRef.current) {
|
|
653
654
|
hasIssuedDeprecationWarningRef.current = true;
|
|
654
655
|
if (options.onSubscriptionData) {
|
|
655
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(options.onData ?
|
|
656
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(options.onData ? 60 : 61);
|
|
656
657
|
}
|
|
657
658
|
if (options.onSubscriptionComplete) {
|
|
658
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(options.onComplete ?
|
|
659
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(options.onComplete ? 62 : 63);
|
|
659
660
|
}
|
|
660
661
|
}
|
|
661
662
|
var skip = options.skip, fetchPolicy = options.fetchPolicy, errorPolicy = options.errorPolicy, shouldResubscribe = options.shouldResubscribe, context = options.context, extensions = options.extensions, ignoreResults = options.ignoreResults;
|
|
@@ -776,7 +777,7 @@ function useSubscription(subscription, options) {
|
|
|
776
777
|
: fallbackResult;
|
|
777
778
|
}, function () { return fallbackResult; });
|
|
778
779
|
var restart = React__namespace.useCallback(function () {
|
|
779
|
-
globals.invariant(!optionsRef.current.skip,
|
|
780
|
+
globals.invariant(!optionsRef.current.skip, 64);
|
|
780
781
|
setObservable(recreateRef.current());
|
|
781
782
|
}, [optionsRef, recreateRef]);
|
|
782
783
|
return React__namespace.useMemo(function () { return (tslib.__assign(tslib.__assign({}, ret), { restart: restart })); }, [ret, restart]);
|
|
@@ -823,20 +824,27 @@ function useFragment(options) {
|
|
|
823
824
|
return wrapHook("useFragment", _useFragment, useApolloClient(options.client))(options);
|
|
824
825
|
}
|
|
825
826
|
function _useFragment(options) {
|
|
826
|
-
var
|
|
827
|
+
var client = useApolloClient(options.client);
|
|
828
|
+
var cache = client.cache;
|
|
827
829
|
var from = options.from, rest = tslib.__rest(options, ["from"]);
|
|
828
830
|
var id = React__namespace.useMemo(function () { return (typeof from === "string" ? from : cache.identify(from)); }, [cache, from]);
|
|
829
831
|
var stableOptions = useDeepMemo(function () { return (tslib.__assign(tslib.__assign({}, rest), { from: id })); }, [rest, id]);
|
|
830
832
|
var diff = React__namespace.useMemo(function () {
|
|
831
833
|
var fragment = stableOptions.fragment, fragmentName = stableOptions.fragmentName, from = stableOptions.from, _a = stableOptions.optimistic, optimistic = _a === void 0 ? true : _a;
|
|
834
|
+
var cache = client.cache;
|
|
835
|
+
var diff = cache.diff(tslib.__assign(tslib.__assign({}, stableOptions), { returnPartialData: true, id: from, query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic }));
|
|
832
836
|
return {
|
|
833
|
-
result: diffToResult(
|
|
837
|
+
result: diffToResult(tslib.__assign(tslib.__assign({}, diff), { result: client["queryManager"].maskFragment({
|
|
838
|
+
fragment: fragment,
|
|
839
|
+
fragmentName: fragmentName,
|
|
840
|
+
data: diff.result,
|
|
841
|
+
}) })),
|
|
834
842
|
};
|
|
835
|
-
}, [
|
|
843
|
+
}, [client, stableOptions]);
|
|
836
844
|
var getSnapshot = React__namespace.useCallback(function () { return diff.result; }, [diff]);
|
|
837
845
|
return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
|
|
838
846
|
var lastTimeout = 0;
|
|
839
|
-
var subscription =
|
|
847
|
+
var subscription = client.watchFragment(stableOptions).subscribe({
|
|
840
848
|
next: function (result) {
|
|
841
849
|
if (equal__default(result, diff.result))
|
|
842
850
|
return;
|
|
@@ -849,7 +857,7 @@ function _useFragment(options) {
|
|
|
849
857
|
subscription.unsubscribe();
|
|
850
858
|
clearTimeout(lastTimeout);
|
|
851
859
|
};
|
|
852
|
-
}, [
|
|
860
|
+
}, [client, stableOptions, diff]), getSnapshot, getSnapshot);
|
|
853
861
|
}
|
|
854
862
|
function diffToResult(diff) {
|
|
855
863
|
var result = {
|
|
@@ -951,11 +959,11 @@ function validateFetchPolicy(fetchPolicy) {
|
|
|
951
959
|
"no-cache",
|
|
952
960
|
"cache-and-network",
|
|
953
961
|
];
|
|
954
|
-
globals.invariant(supportedFetchPolicies.includes(fetchPolicy),
|
|
962
|
+
globals.invariant(supportedFetchPolicies.includes(fetchPolicy), 65, fetchPolicy);
|
|
955
963
|
}
|
|
956
964
|
function validatePartialDataReturn(fetchPolicy, returnPartialData) {
|
|
957
965
|
if (fetchPolicy === "no-cache" && returnPartialData) {
|
|
958
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
966
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(66);
|
|
959
967
|
}
|
|
960
968
|
}
|
|
961
969
|
function toApolloError(result) {
|
|
@@ -1075,7 +1083,7 @@ function useLoadableQuery(query, options) {
|
|
|
1075
1083
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1076
1084
|
args[_i] = arguments[_i];
|
|
1077
1085
|
}
|
|
1078
|
-
globals.invariant(!calledDuringRender(),
|
|
1086
|
+
globals.invariant(!calledDuringRender(), 58);
|
|
1079
1087
|
var variables = args[0];
|
|
1080
1088
|
var cacheKey = tslib.__spreadArray([
|
|
1081
1089
|
query,
|
|
@@ -1094,7 +1102,7 @@ function useLoadableQuery(query, options) {
|
|
|
1094
1102
|
client,
|
|
1095
1103
|
]);
|
|
1096
1104
|
var subscribeToMore = React__namespace.useCallback(function (options) {
|
|
1097
|
-
globals.invariant(internalQueryRef,
|
|
1105
|
+
globals.invariant(internalQueryRef, 59);
|
|
1098
1106
|
return internalQueryRef.observable.subscribeToMore(options);
|
|
1099
1107
|
}, [internalQueryRef]);
|
|
1100
1108
|
var reset = React__namespace.useCallback(function () {
|
|
@@ -19,7 +19,7 @@ import { getApolloContext } from "../context/index.js";
|
|
|
19
19
|
export function useApolloClient(override) {
|
|
20
20
|
var context = React.useContext(getApolloContext());
|
|
21
21
|
var client = override || context.client;
|
|
22
|
-
invariant(!!client,
|
|
22
|
+
invariant(!!client, 57);
|
|
23
23
|
return client;
|
|
24
24
|
}
|
|
25
25
|
//# sourceMappingURL=useApolloClient.js.map
|
|
@@ -2,8 +2,9 @@ import type { DeepPartial } from "../../utilities/index.js";
|
|
|
2
2
|
import type { Cache, Reference, StoreObject, MissingTree } from "../../cache/index.js";
|
|
3
3
|
import type { ApolloClient, OperationVariables } from "../../core/index.js";
|
|
4
4
|
import type { NoInfer } from "../types/types.js";
|
|
5
|
+
import type { FragmentType, MaybeMasked } from "../../masking/index.js";
|
|
5
6
|
export interface UseFragmentOptions<TData, TVars> extends Omit<Cache.DiffOptions<NoInfer<TData>, NoInfer<TVars>>, "id" | "query" | "optimistic" | "previousResult" | "returnPartialData">, Omit<Cache.ReadFragmentOptions<TData, TVars>, "id" | "variables" | "returnPartialData"> {
|
|
6
|
-
from: StoreObject | Reference | string;
|
|
7
|
+
from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string;
|
|
7
8
|
optimistic?: boolean;
|
|
8
9
|
/**
|
|
9
10
|
* The instance of `ApolloClient` to use to look up the fragment.
|
|
@@ -16,11 +17,11 @@ export interface UseFragmentOptions<TData, TVars> extends Omit<Cache.DiffOptions
|
|
|
16
17
|
client?: ApolloClient<any>;
|
|
17
18
|
}
|
|
18
19
|
export type UseFragmentResult<TData> = {
|
|
19
|
-
data: TData
|
|
20
|
+
data: MaybeMasked<TData>;
|
|
20
21
|
complete: true;
|
|
21
22
|
missing?: never;
|
|
22
23
|
} | {
|
|
23
|
-
data: DeepPartial<TData
|
|
24
|
+
data: DeepPartial<MaybeMasked<TData>>;
|
|
24
25
|
complete: false;
|
|
25
26
|
missing?: MissingTree;
|
|
26
27
|
};
|
|
@@ -9,7 +9,8 @@ export function useFragment(options) {
|
|
|
9
9
|
return wrapHook("useFragment", _useFragment, useApolloClient(options.client))(options);
|
|
10
10
|
}
|
|
11
11
|
function _useFragment(options) {
|
|
12
|
-
var
|
|
12
|
+
var client = useApolloClient(options.client);
|
|
13
|
+
var cache = client.cache;
|
|
13
14
|
var from = options.from, rest = __rest(options, ["from"]);
|
|
14
15
|
// We calculate the cache id seperately from `stableOptions` because we don't
|
|
15
16
|
// want changes to non key fields in the `from` property to affect
|
|
@@ -21,15 +22,21 @@ function _useFragment(options) {
|
|
|
21
22
|
// get the correct diff on the next render given new diffOptions
|
|
22
23
|
var diff = React.useMemo(function () {
|
|
23
24
|
var fragment = stableOptions.fragment, fragmentName = stableOptions.fragmentName, from = stableOptions.from, _a = stableOptions.optimistic, optimistic = _a === void 0 ? true : _a;
|
|
25
|
+
var cache = client.cache;
|
|
26
|
+
var diff = cache.diff(__assign(__assign({}, stableOptions), { returnPartialData: true, id: from, query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic }));
|
|
24
27
|
return {
|
|
25
|
-
result: diffToResult(
|
|
28
|
+
result: diffToResult(__assign(__assign({}, diff), { result: client["queryManager"].maskFragment({
|
|
29
|
+
fragment: fragment,
|
|
30
|
+
fragmentName: fragmentName,
|
|
31
|
+
data: diff.result,
|
|
32
|
+
}) })),
|
|
26
33
|
};
|
|
27
|
-
}, [
|
|
34
|
+
}, [client, stableOptions]);
|
|
28
35
|
// Used for both getSnapshot and getServerSnapshot
|
|
29
36
|
var getSnapshot = React.useCallback(function () { return diff.result; }, [diff]);
|
|
30
37
|
return useSyncExternalStore(React.useCallback(function (forceUpdate) {
|
|
31
38
|
var lastTimeout = 0;
|
|
32
|
-
var subscription =
|
|
39
|
+
var subscription = client.watchFragment(stableOptions).subscribe({
|
|
33
40
|
next: function (result) {
|
|
34
41
|
// Since `next` is called async by zen-observable, we want to avoid
|
|
35
42
|
// unnecessarily rerendering this hook for the initial result
|
|
@@ -50,7 +57,7 @@ function _useFragment(options) {
|
|
|
50
57
|
subscription.unsubscribe();
|
|
51
58
|
clearTimeout(lastTimeout);
|
|
52
59
|
};
|
|
53
|
-
}, [
|
|
60
|
+
}, [client, stableOptions, diff]), getSnapshot, getSnapshot);
|
|
54
61
|
}
|
|
55
62
|
function diffToResult(diff) {
|
|
56
63
|
var result = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAQ1D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAQ1D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,MAAM,eAAe,CAAC;AAsClC,MAAM,UAAU,WAAW,CACzB,OAAyC;IAEzC,OAAO,QAAQ,CACb,aAAa,EACb,YAAY,EACZ,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAChC,CAAC,OAAO,CAAC,CAAC;AACb,CAAC;AAED,SAAS,YAAY,CACnB,OAAyC;IAEzC,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,IAAA,KAAK,GAAK,MAAM,MAAX,CAAY;IACjB,IAAA,IAAI,GAAc,OAAO,KAArB,EAAK,IAAI,UAAK,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AAK,IAAK,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport { mergeDeepArray } from \"../../utilities/index.js\";\nimport type {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache/index.js\";\n\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport type { ApolloClient, OperationVariables } from \"../../core/index.js\";\nimport type { NoInfer } from \"../types/types.js\";\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport equal from \"@wry/equality\";\nimport type { FragmentType, MaybeMasked } from \"../../masking/index.js\";\n\nexport interface UseFragmentOptions<TData, TVars>\n extends Omit<\n Cache.DiffOptions<NoInfer<TData>, NoInfer<TVars>>,\n \"id\" | \"query\" | \"optimistic\" | \"previousResult\" | \"returnPartialData\"\n >,\n Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n \"id\" | \"variables\" | \"returnPartialData\"\n > {\n from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient<any>;\n}\n\nexport type UseFragmentResult<TData> =\n | {\n data: MaybeMasked<TData>;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<MaybeMasked<TData>>;\n complete: false;\n missing?: MissingTree;\n };\n\nexport function useFragment<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\n return wrapHook(\n \"useFragment\",\n _useFragment,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction _useFragment<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\n const client = useApolloClient(options.client);\n const { cache } = client;\n const { from, ...rest } = options;\n\n // We calculate the cache id seperately from `stableOptions` because we don't\n // want changes to non key fields in the `from` property to affect\n // `stableOptions` and retrigger our subscription. If the cache identifier\n // stays the same between renders, we want to reuse the existing subscription.\n const id = React.useMemo(\n () => (typeof from === \"string\" ? from : cache.identify(from)),\n [cache, from]\n );\n\n const stableOptions = useDeepMemo(() => ({ ...rest, from: id! }), [rest, id]);\n\n // Since .next is async, we need to make sure that we\n // get the correct diff on the next render given new diffOptions\n const diff = React.useMemo(() => {\n const { fragment, fragmentName, from, optimistic = true } = stableOptions;\n const { cache } = client;\n const diff = cache.diff<TData>({\n ...stableOptions,\n returnPartialData: true,\n id: from,\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n });\n\n return {\n result: diffToResult({\n ...diff,\n result: client[\"queryManager\"].maskFragment({\n fragment,\n fragmentName,\n data: diff.result,\n }),\n }),\n };\n }, [client, stableOptions]);\n\n // Used for both getSnapshot and getServerSnapshot\n const getSnapshot = React.useCallback(() => diff.result, [diff]);\n\n return useSyncExternalStore(\n React.useCallback(\n (forceUpdate) => {\n let lastTimeout = 0;\n const subscription = client.watchFragment(stableOptions).subscribe({\n next: (result) => {\n // Since `next` is called async by zen-observable, we want to avoid\n // unnecessarily rerendering this hook for the initial result\n // emitted from watchFragment which should be equal to\n // `diff.result`.\n if (equal(result, diff.result)) return;\n diff.result = result;\n // If we get another update before we've re-rendered, bail out of\n // the update and try again. This ensures that the relative timing\n // between useQuery and useFragment stays roughly the same as\n // fixed in https://github.com/apollographql/apollo-client/pull/11083\n clearTimeout(lastTimeout);\n lastTimeout = setTimeout(forceUpdate) as any;\n },\n });\n return () => {\n subscription.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [client, stableOptions, diff]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>\n): UseFragmentResult<TData> {\n const result = {\n data: diff.result!,\n complete: !!diff.complete,\n } as UseFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(diff.missing.map((error) => error.missing));\n }\n\n return result;\n}\n"]}
|
|
@@ -140,7 +140,7 @@ function executeQuery(resultData, observable, client, currentQuery, options, onQ
|
|
|
140
140
|
resolve(toQueryResult(observable.getCurrentResult(), resultData.previousData, observable, client));
|
|
141
141
|
},
|
|
142
142
|
complete: function () {
|
|
143
|
-
resolve(toQueryResult(result, resultData.previousData, observable, client));
|
|
143
|
+
resolve(toQueryResult(observable["maskResult"](result), resultData.previousData, observable, client));
|
|
144
144
|
},
|
|
145
145
|
});
|
|
146
146
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAQjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAUxD,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAEpF,2EAA2E;AAC3E,+DAA+D;AAC/D,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,aAAa;IACb,iBAAiB;CACT,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,YAAY,CAI1B,KAA0D,EAC1D,OAAmE;;IAEnE,IAAM,cAAc,GAClB,KAAK,CAAC,MAAM,EAAwD,CAAC;IACvE,IAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAA2C,CAAC;IAC3E,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAE1B,CAAC;IACJ,I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AAO,CACL,aAAa,CACX,UAAU,CAAC,gBAAgB,EAAE,EAC7B,UAAU,CAAC,YAAY,EACvB,UAAU,EACV,MAAM,CACP,CACF,CAAC;YACJ,CAAC;YACD,QAAQ,EAAE;gBACR,OAAO,CACL,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,YAAY,EAAE,UAAU,EAAE,MAAM,CAAC,CACnE,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport * as React from \"rehackt\";\n\nimport type {\n ApolloClient,\n ApolloQueryResult,\n OperationVariables,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport type {\n LazyQueryHookExecOptions,\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n NoInfer,\n QueryHookOptions,\n QueryResult,\n} from \"../types/types.js\";\nimport type { InternalResult, ObsQueryWithMeta } from \"./useQuery.js\";\nimport {\n createMakeWatchQueryOptions,\n getDefaultFetchPolicy,\n getObsQueryOptions,\n toQueryResult,\n useQueryInternals,\n} from \"./useQuery.js\";\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\n\n// The following methods, when called will execute the query, regardless of\n// whether the useLazyQuery execute function was called before.\nconst EAGER_METHODS = [\n \"refetch\",\n \"reobserve\",\n \"fetchMore\",\n \"updateQuery\",\n \"startPolling\",\n \"stopPolling\",\n \"subscribeToMore\",\n] as const;\n\n/**\n * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.\n *\n * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.\n *\n * @example\n * ```jsx\n * import { gql, useLazyQuery } 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 [loadGreeting, { called, loading, data }] = useLazyQuery(\n * GET_GREETING,\n * { variables: { language: \"english\" } }\n * );\n * if (called && loading) return <p>Loading ...</p>\n * if (!called) {\n * return <button onClick={() => loadGreeting()}>Load greeting</button>\n * }\n * return <h1>Hello {data.greeting.message}!</h1>;\n * }\n * ```\n * @since 3.0.0\n *\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - Default options to control how the query is executed.\n * @returns A tuple in the form of `[execute, result]`\n */\nexport function useLazyQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n): LazyQueryResultTuple<TData, TVariables> {\n const execOptionsRef =\n React.useRef<Partial<LazyQueryHookExecOptions<TData, TVariables>>>();\n const optionsRef = React.useRef<LazyQueryHookOptions<TData, TVariables>>();\n const queryRef = React.useRef<\n DocumentNode | TypedDocumentNode<TData, TVariables>\n >();\n const merged = mergeOptions(options, execOptionsRef.current || {});\n const document = merged?.query ?? query;\n\n // Use refs to track options and the used query to ensure the `execute`\n // function remains referentially stable between renders.\n optionsRef.current = options;\n queryRef.current = document;\n\n const queryHookOptions = {\n ...merged,\n skip: !execOptionsRef.current,\n };\n const {\n obsQueryFields,\n result: useQueryResult,\n client,\n resultData,\n observable,\n onQueryExecuted,\n } = useQueryInternals(document, queryHookOptions);\n\n const initialFetchPolicy =\n observable.options.initialFetchPolicy ||\n getDefaultFetchPolicy(\n queryHookOptions.defaultOptions,\n client.defaultOptions\n );\n\n const forceUpdateState = React.useReducer((tick) => tick + 1, 0)[1];\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = React.useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = obsQueryFields[key];\n eagerMethods[key] = function () {\n if (!execOptionsRef.current) {\n execOptionsRef.current = Object.create(null);\n // Only the first time populating execOptionsRef.current matters here.\n forceUpdateState();\n }\n // @ts-expect-error this is just too generic to type\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods as typeof obsQueryFields;\n }, [forceUpdateState, obsQueryFields]);\n\n const called = !!execOptionsRef.current;\n const result = React.useMemo(\n () => ({\n ...useQueryResult,\n ...eagerMethods,\n called,\n }),\n [useQueryResult, eagerMethods, called]\n );\n\n const execute = React.useCallback<LazyQueryResultTuple<TData, TVariables>[0]>(\n (executeOptions) => {\n execOptionsRef.current =\n executeOptions ?\n {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n }\n : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const options = mergeOptions(optionsRef.current, {\n query: queryRef.current,\n ...execOptionsRef.current,\n });\n\n const promise = executeQuery(\n resultData,\n observable,\n client,\n document,\n { ...options, skip: false },\n onQueryExecuted\n ).then((queryResult) => Object.assign(queryResult, eagerMethods));\n\n // Because the return value of `useLazyQuery` is usually floated, we need\n // to catch the promise to prevent unhandled rejections.\n promise.catch(() => {});\n\n return promise;\n },\n [\n client,\n document,\n eagerMethods,\n initialFetchPolicy,\n observable,\n resultData,\n onQueryExecuted,\n ]\n );\n\n const executeRef = React.useRef(execute);\n useIsomorphicLayoutEffect(() => {\n executeRef.current = execute;\n });\n\n const stableExecute = React.useCallback<typeof execute>(\n (...args) => executeRef.current(...args),\n []\n );\n return [stableExecute, result];\n}\n\nfunction executeQuery<TData, TVariables extends OperationVariables>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObsQueryWithMeta<TData, TVariables>,\n client: ApolloClient<object>,\n currentQuery: DocumentNode,\n options: QueryHookOptions<TData, TVariables> & {\n query?: DocumentNode;\n },\n onQueryExecuted: (options: WatchQueryOptions<TVariables, TData>) => void\n) {\n const query = options.query || currentQuery;\n const watchQueryOptions = createMakeWatchQueryOptions(\n client,\n query,\n options,\n false\n )(observable);\n\n const concast = observable.reobserveAsConcast(\n getObsQueryOptions(observable, client, options, watchQueryOptions)\n );\n onQueryExecuted(watchQueryOptions);\n\n return new Promise<\n Omit<QueryResult<TData, TVariables>, (typeof EAGER_METHODS)[number]>\n >((resolve) => {\n let result: ApolloQueryResult<TData>;\n\n // Subscribe to the concast independently of the ObservableQuery in case\n // the component gets unmounted before the promise resolves. This prevents\n // the concast from terminating early and resolving with `undefined` when\n // there are no more subscribers for the concast.\n concast.subscribe({\n next: (value) => {\n result = value;\n },\n error: () => {\n resolve(\n toQueryResult(\n observable.getCurrentResult(),\n resultData.previousData,\n observable,\n client\n )\n );\n },\n complete: () => {\n resolve(\n toQueryResult(result, resultData.previousData, observable, client)\n );\n },\n });\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAQjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAUxD,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAEpF,2EAA2E;AAC3E,+DAA+D;AAC/D,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,aAAa;IACb,iBAAiB;CACT,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,YAAY,CAI1B,KAA0D,EAC1D,OAAmE;;IAEnE,IAAM,cAAc,GAClB,KAAK,CAAC,MAAM,EAAwD,CAAC;IACvE,IAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAA2C,CAAC;IAC3E,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAE1B,CAAC;IACJ,IAAM,MAAM,GAAG,YA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,UAAU,CAAC,gBAAgB,EAAE,EAC7B,UAAU,CAAC,YAAY,EACvB,UAAU,EACV,MAAM,CACP,CACF,CAAC;YACJ,CAAC;YACD,QAAQ,EAAE;gBACR,OAAO,CACL,aAAa,CACX,UAAU,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EAChC,UAAU,CAAC,YAAY,EACvB,UAAU,EACV,MAAM,CACP,CACF,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport * as React from \"rehackt\";\n\nimport type {\n ApolloClient,\n ApolloQueryResult,\n OperationVariables,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport type {\n LazyQueryHookExecOptions,\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n NoInfer,\n QueryHookOptions,\n QueryResult,\n} from \"../types/types.js\";\nimport type { InternalResult, ObsQueryWithMeta } from \"./useQuery.js\";\nimport {\n createMakeWatchQueryOptions,\n getDefaultFetchPolicy,\n getObsQueryOptions,\n toQueryResult,\n useQueryInternals,\n} from \"./useQuery.js\";\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\n\n// The following methods, when called will execute the query, regardless of\n// whether the useLazyQuery execute function was called before.\nconst EAGER_METHODS = [\n \"refetch\",\n \"reobserve\",\n \"fetchMore\",\n \"updateQuery\",\n \"startPolling\",\n \"stopPolling\",\n \"subscribeToMore\",\n] as const;\n\n/**\n * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.\n *\n * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.\n *\n * @example\n * ```jsx\n * import { gql, useLazyQuery } 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 [loadGreeting, { called, loading, data }] = useLazyQuery(\n * GET_GREETING,\n * { variables: { language: \"english\" } }\n * );\n * if (called && loading) return <p>Loading ...</p>\n * if (!called) {\n * return <button onClick={() => loadGreeting()}>Load greeting</button>\n * }\n * return <h1>Hello {data.greeting.message}!</h1>;\n * }\n * ```\n * @since 3.0.0\n *\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - Default options to control how the query is executed.\n * @returns A tuple in the form of `[execute, result]`\n */\nexport function useLazyQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n): LazyQueryResultTuple<TData, TVariables> {\n const execOptionsRef =\n React.useRef<Partial<LazyQueryHookExecOptions<TData, TVariables>>>();\n const optionsRef = React.useRef<LazyQueryHookOptions<TData, TVariables>>();\n const queryRef = React.useRef<\n DocumentNode | TypedDocumentNode<TData, TVariables>\n >();\n const merged = mergeOptions(options, execOptionsRef.current || {});\n const document = merged?.query ?? query;\n\n // Use refs to track options and the used query to ensure the `execute`\n // function remains referentially stable between renders.\n optionsRef.current = options;\n queryRef.current = document;\n\n const queryHookOptions = {\n ...merged,\n skip: !execOptionsRef.current,\n };\n const {\n obsQueryFields,\n result: useQueryResult,\n client,\n resultData,\n observable,\n onQueryExecuted,\n } = useQueryInternals(document, queryHookOptions);\n\n const initialFetchPolicy =\n observable.options.initialFetchPolicy ||\n getDefaultFetchPolicy(\n queryHookOptions.defaultOptions,\n client.defaultOptions\n );\n\n const forceUpdateState = React.useReducer((tick) => tick + 1, 0)[1];\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = React.useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = obsQueryFields[key];\n eagerMethods[key] = function () {\n if (!execOptionsRef.current) {\n execOptionsRef.current = Object.create(null);\n // Only the first time populating execOptionsRef.current matters here.\n forceUpdateState();\n }\n // @ts-expect-error this is just too generic to type\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods as typeof obsQueryFields;\n }, [forceUpdateState, obsQueryFields]);\n\n const called = !!execOptionsRef.current;\n const result = React.useMemo(\n () => ({\n ...useQueryResult,\n ...eagerMethods,\n called,\n }),\n [useQueryResult, eagerMethods, called]\n );\n\n const execute = React.useCallback<LazyQueryResultTuple<TData, TVariables>[0]>(\n (executeOptions) => {\n execOptionsRef.current =\n executeOptions ?\n {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n }\n : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const options = mergeOptions(optionsRef.current, {\n query: queryRef.current,\n ...execOptionsRef.current,\n });\n\n const promise = executeQuery(\n resultData,\n observable,\n client,\n document,\n { ...options, skip: false },\n onQueryExecuted\n ).then((queryResult) => Object.assign(queryResult, eagerMethods));\n\n // Because the return value of `useLazyQuery` is usually floated, we need\n // to catch the promise to prevent unhandled rejections.\n promise.catch(() => {});\n\n return promise;\n },\n [\n client,\n document,\n eagerMethods,\n initialFetchPolicy,\n observable,\n resultData,\n onQueryExecuted,\n ]\n );\n\n const executeRef = React.useRef(execute);\n useIsomorphicLayoutEffect(() => {\n executeRef.current = execute;\n });\n\n const stableExecute = React.useCallback<typeof execute>(\n (...args) => executeRef.current(...args),\n []\n );\n return [stableExecute, result];\n}\n\nfunction executeQuery<TData, TVariables extends OperationVariables>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObsQueryWithMeta<TData, TVariables>,\n client: ApolloClient<object>,\n currentQuery: DocumentNode,\n options: QueryHookOptions<TData, TVariables> & {\n query?: DocumentNode;\n },\n onQueryExecuted: (options: WatchQueryOptions<TVariables, TData>) => void\n) {\n const query = options.query || currentQuery;\n const watchQueryOptions = createMakeWatchQueryOptions(\n client,\n query,\n options,\n false\n )(observable);\n\n const concast = observable.reobserveAsConcast(\n getObsQueryOptions(observable, client, options, watchQueryOptions)\n );\n onQueryExecuted(watchQueryOptions);\n\n return new Promise<\n Omit<QueryResult<TData, TVariables>, (typeof EAGER_METHODS)[number]>\n >((resolve) => {\n let result: ApolloQueryResult<TData>;\n\n // Subscribe to the concast independently of the ObservableQuery in case\n // the component gets unmounted before the promise resolves. This prevents\n // the concast from terminating early and resolving with `undefined` when\n // there are no more subscribers for the concast.\n concast.subscribe({\n next: (value) => {\n result = value;\n },\n error: () => {\n resolve(\n toQueryResult(\n observable.getCurrentResult(),\n resultData.previousData,\n observable,\n client\n )\n );\n },\n complete: () => {\n resolve(\n toQueryResult(\n observable[\"maskResult\"](result),\n resultData.previousData,\n observable,\n client\n )\n );\n },\n });\n });\n}\n"]}
|
|
@@ -41,7 +41,7 @@ export function useLoadableQuery(query, options) {
|
|
|
41
41
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
42
42
|
args[_i] = arguments[_i];
|
|
43
43
|
}
|
|
44
|
-
invariant(!calledDuringRender(),
|
|
44
|
+
invariant(!calledDuringRender(), 58);
|
|
45
45
|
var variables = args[0];
|
|
46
46
|
var cacheKey = __spreadArray([
|
|
47
47
|
query,
|
|
@@ -60,7 +60,7 @@ export function useLoadableQuery(query, options) {
|
|
|
60
60
|
client,
|
|
61
61
|
]);
|
|
62
62
|
var subscribeToMore = React.useCallback(function (options) {
|
|
63
|
-
invariant(internalQueryRef,
|
|
63
|
+
invariant(internalQueryRef, 59);
|
|
64
64
|
return internalQueryRef.observable.subscribeToMore(options);
|
|
65
65
|
}, [internalQueryRef]);
|
|
66
66
|
var reset = React.useCallback(function () {
|
|
@@ -3,6 +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
|
+
import type { MaybeMasked } from "../../masking/index.js";
|
|
6
7
|
type InternalQueryResult<TData, TVariables extends OperationVariables> = Omit<QueryResult<TData, TVariables>, Exclude<keyof ObservableQueryFields<TData, TVariables>, "variables">>;
|
|
7
8
|
export declare const lastWatchOptions: unique symbol;
|
|
8
9
|
export interface ObsQueryWithMeta<TData, TVariables extends OperationVariables> extends ObservableQuery<TData, TVariables> {
|
|
@@ -10,7 +11,7 @@ export interface ObsQueryWithMeta<TData, TVariables extends OperationVariables>
|
|
|
10
11
|
}
|
|
11
12
|
export interface InternalResult<TData, TVariables extends OperationVariables> {
|
|
12
13
|
current?: undefined | InternalQueryResult<TData, TVariables>;
|
|
13
|
-
previousData?: undefined | TData
|
|
14
|
+
previousData?: undefined | MaybeMasked<TData>;
|
|
14
15
|
}
|
|
15
16
|
interface InternalState<TData, TVariables extends OperationVariables> {
|
|
16
17
|
client: ReturnType<typeof useApolloClient>;
|
|
@@ -55,7 +56,7 @@ export type UpdateInternalState<TData, TVariables extends OperationVariables> =
|
|
|
55
56
|
*/
|
|
56
57
|
export declare function useQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>): QueryResult<TData, TVariables>;
|
|
57
58
|
export declare function useQueryInternals<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>): {
|
|
58
|
-
result: InternalQueryResult<TData, TVariables
|
|
59
|
+
result: InternalQueryResult<TData, TVariables>;
|
|
59
60
|
obsQueryFields: Omit<ObservableQueryFields<TData, TVariables>, "variables">;
|
|
60
61
|
observable: ObsQueryWithMeta<TData, TVariables>;
|
|
61
62
|
resultData: InternalResult<TData, TVariables>;
|
|
@@ -66,6 +67,6 @@ export declare function createMakeWatchQueryOptions<TData = any, TVariables exte
|
|
|
66
67
|
export declare function getObsQueryOptions<TData, TVariables extends OperationVariables>(observable: ObservableQuery<TData, TVariables> | undefined, client: ApolloClient<object>, queryHookOptions: QueryHookOptions<TData, TVariables>, watchQueryOptions: Partial<WatchQueryOptions<TVariables, TData>>): WatchQueryOptions<TVariables, TData>;
|
|
67
68
|
export declare function getDefaultFetchPolicy<TData, TVariables extends OperationVariables>(queryHookDefaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>, clientDefaultOptions?: DefaultOptions): WatchQueryFetchPolicy;
|
|
68
69
|
export declare function toApolloError<TData>(result: Pick<ApolloQueryResult<TData>, "errors" | "error">): ApolloError | undefined;
|
|
69
|
-
export declare function toQueryResult<TData, TVariables extends OperationVariables>(result: ApolloQueryResult<TData
|
|
70
|
+
export declare function toQueryResult<TData, TVariables extends OperationVariables>(result: ApolloQueryResult<MaybeMasked<TData>>, previousData: MaybeMasked<TData> | undefined, observable: ObservableQuery<TData, TVariables>, client: ApolloClient<object>): InternalQueryResult<TData, TVariables>;
|
|
70
71
|
export {};
|
|
71
72
|
//# sourceMappingURL=useQuery.d.ts.map
|
package/react/hooks/useQuery.js
CHANGED
|
@@ -231,7 +231,8 @@ function useObservableSubscriptionResult(resultData, observable, client, options
|
|
|
231
231
|
(previousResult && previousResult.loading) ||
|
|
232
232
|
!equal(error, previousResult.error)) {
|
|
233
233
|
setResult({
|
|
234
|
-
data: (previousResult &&
|
|
234
|
+
data: (previousResult &&
|
|
235
|
+
previousResult.data),
|
|
235
236
|
error: error,
|
|
236
237
|
loading: false,
|
|
237
238
|
networkStatus: NetworkStatus.error,
|
|
@@ -1 +1 @@
|
|
|
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;AAC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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"]}
|
|
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;AAKhC,IAAA,cAAc,GACzB,MAAM,yBADmB,CAClB;AAOX,SAAS,IAAI,KAAI,CAAC;AAClB,MAAM,CAAC,IAAM,gBAAgB,GAAG,MAAM,EAAE,CAAC;AAkCzC;;;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C,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\";\nimport type { MaybeMasked } from \"../../masking/index.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 | MaybeMasked<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: MaybeMasked<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: MaybeMasked<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 &&\n previousResult.data) as MaybeMasked<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<MaybeMasked<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<MaybeMasked<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<MaybeMasked<TData>>,\n previousData: MaybeMasked<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<MaybeMasked<TData>>,\n observable: ObservableQuery<TData, TVariables>,\n partialRefetch: boolean | undefined\n): ApolloQueryResult<MaybeMasked<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"]}
|