@apollo/client 4.4.0-alpha.0 → 4.4.0-alpha.1
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/CHANGELOG.md +39 -0
- package/__cjs/cache/core/cache.cjs +50 -15
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +22 -4
- package/__cjs/cache/index.cjs.map +1 -1
- package/__cjs/cache/index.d.cts +1 -1
- package/__cjs/cache/inmemory/entityStore.cjs +4 -4
- package/__cjs/cache/inmemory/helpers.cjs +12 -0
- package/__cjs/cache/inmemory/helpers.cjs.map +1 -1
- package/__cjs/cache/inmemory/helpers.d.cts +10 -5
- package/__cjs/cache/inmemory/inMemoryCache.cjs +13 -2
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +19 -4
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +7 -7
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/readFromStore.cjs +86 -31
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/types.d.cts +11 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +27 -24
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.d.cts +5 -4
- package/__cjs/core/ApolloClient.cjs +19 -15
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +1 -0
- package/__cjs/core/ObservableQuery.cjs +8 -8
- package/__cjs/core/QueryInfo.cjs +1 -1
- package/__cjs/core/QueryManager.cjs +12 -12
- package/__cjs/core/RefetchEventManager.cjs +3 -3
- package/__cjs/errors/CombinedGraphQLErrors.cjs +3 -7
- package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedGraphQLErrors.d.cts +2 -2
- package/__cjs/errors/CombinedProtocolErrors.cjs +3 -8
- package/__cjs/errors/CombinedProtocolErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedProtocolErrors.d.cts +2 -2
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +2 -2
- package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
- package/__cjs/invariantErrorCodes.cjs +125 -120
- package/__cjs/link/core/ApolloLink.cjs +3 -3
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
- package/__cjs/link/persisted-queries/index.cjs +2 -2
- package/__cjs/link/ws/index.cjs +1 -1
- package/__cjs/local-state/LocalState.cjs +23 -22
- package/__cjs/local-state/LocalState.cjs.map +1 -1
- package/__cjs/masking/maskDefinition.cjs +20 -2
- package/__cjs/masking/maskDefinition.cjs.map +1 -1
- package/__cjs/masking/maskFragment.cjs +2 -2
- package/__cjs/masking/maskOperation.cjs +1 -1
- package/__cjs/masking/utils.cjs +3 -3
- package/__cjs/react/context/ApolloContext.cjs +1 -1
- package/__cjs/react/context/ApolloProvider.cjs +1 -1
- package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs +2 -2
- package/__cjs/react/hooks/useApolloClient.cjs +1 -1
- package/__cjs/react/hooks/useFragment.cjs +8 -2
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
- package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
- package/__cjs/react/hooks/useSubscription.cjs +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.cjs +10 -4
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
- package/__cjs/react/internal/cache/FragmentReference.cjs +2 -2
- package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/FragmentReference.d.cts +4 -5
- package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
- package/__cjs/react/internal/cache/SuspenseCache.cjs +3 -3
- package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
- package/__cjs/react/internal/cache/SuspenseCache.d.cts +4 -5
- package/__cjs/react/internal/cache/types.d.cts +0 -5
- package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
- package/__cjs/testing/core/mocking/mockLink.cjs +4 -4
- package/__cjs/utilities/graphql/DocumentTransform.cjs +1 -1
- package/__cjs/utilities/internal/DeepMerger.cjs +6 -2
- package/__cjs/utilities/internal/DeepMerger.cjs.map +1 -1
- package/__cjs/utilities/internal/DeepMerger.d.cts +13 -3
- package/__cjs/utilities/internal/constants.cjs +33 -1
- package/__cjs/utilities/internal/constants.cjs.map +1 -1
- package/__cjs/utilities/internal/constants.d.cts +32 -0
- package/__cjs/utilities/internal/createArgumentNode.cjs +14 -0
- package/__cjs/utilities/internal/createArgumentNode.cjs.map +1 -0
- package/__cjs/utilities/internal/createArgumentNode.d.cts +3 -0
- package/__cjs/utilities/internal/createDirectiveNode.cjs +14 -0
- package/__cjs/utilities/internal/createDirectiveNode.cjs.map +1 -0
- package/__cjs/utilities/internal/createDirectiveNode.d.cts +3 -0
- package/__cjs/utilities/internal/createFragmentSpreadNode.cjs +4 -1
- package/__cjs/utilities/internal/createFragmentSpreadNode.cjs.map +1 -1
- package/__cjs/utilities/internal/createFragmentSpreadNode.d.cts +3 -2
- package/__cjs/utilities/internal/createValueNode.cjs +27 -0
- package/__cjs/utilities/internal/createValueNode.cjs.map +1 -0
- package/__cjs/utilities/internal/createValueNode.d.cts +12 -0
- package/__cjs/utilities/internal/equalByQuery.cjs +8 -8
- package/__cjs/utilities/internal/equalByQuery.cjs.map +1 -1
- package/__cjs/utilities/internal/equalByQuery.d.cts +2 -3
- package/__cjs/utilities/internal/getFragmentDefinition.cjs +3 -3
- package/__cjs/utilities/internal/getFragmentDefinition.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs +1 -1
- package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +10 -2
- package/__cjs/utilities/internal/getFragmentQueryDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentScope.cjs +23 -0
- package/__cjs/utilities/internal/getFragmentScope.cjs.map +1 -0
- package/__cjs/utilities/internal/getFragmentScope.d.cts +13 -0
- package/__cjs/utilities/internal/getFragmentVariables.cjs +14 -15
- package/__cjs/utilities/internal/getFragmentVariables.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentVariables.d.cts +8 -4
- package/__cjs/utilities/internal/getMainDefinition.cjs +1 -1
- package/__cjs/utilities/internal/getQueryDefinition.cjs +1 -1
- package/__cjs/utilities/internal/index.cjs +9 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +5 -1
- package/__cjs/utilities/internal/isNonEmptyObject.cjs +13 -0
- package/__cjs/utilities/internal/isNonEmptyObject.cjs.map +1 -0
- package/__cjs/utilities/internal/isNonEmptyObject.d.cts +7 -0
- package/__cjs/utilities/internal/isNonNullObject.cjs.map +1 -1
- package/__cjs/utilities/internal/isNonNullObject.d.cts +1 -1
- package/__cjs/utilities/internal/mapObservableFragment.cjs +14 -9
- package/__cjs/utilities/internal/mapObservableFragment.cjs.map +1 -1
- package/__cjs/utilities/internal/mapObservableFragment.d.cts +5 -1
- package/__cjs/utilities/internal/mergeDeepArray.cjs +2 -2
- package/__cjs/utilities/internal/mergeDeepArray.cjs.map +1 -1
- package/__cjs/utilities/internal/mergeDeepArray.d.cts +2 -1
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +1 -1
- package/__cjs/utilities/internal/removeFragmentSpreads.cjs +55 -2
- package/__cjs/utilities/internal/removeFragmentSpreads.cjs.map +1 -1
- package/__cjs/utilities/internal/removeFragmentSpreads.d.cts +17 -1
- package/__cjs/utilities/internal/shouldInclude.cjs +4 -4
- package/__cjs/utilities/internal/types/FragmentInfo.cjs +3 -0
- package/__cjs/utilities/internal/types/FragmentInfo.cjs.map +1 -0
- package/__cjs/utilities/internal/types/FragmentInfo.d.cts +14 -0
- package/__cjs/utilities/internal/types/ObjectWithFragmentInfo.cjs +3 -0
- package/__cjs/utilities/internal/types/ObjectWithFragmentInfo.cjs.map +1 -0
- package/__cjs/utilities/internal/types/ObjectWithFragmentInfo.d.cts +13 -0
- package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +22 -4
- package/cache/core/cache.js +51 -16
- package/cache/core/cache.js.map +1 -1
- package/cache/index.d.ts +1 -1
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.js +4 -4
- package/cache/inmemory/helpers.d.ts +10 -5
- package/cache/inmemory/helpers.js +12 -1
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +19 -4
- package/cache/inmemory/inMemoryCache.js +14 -3
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +7 -7
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +89 -34
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +11 -2
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +5 -4
- package/cache/inmemory/writeToStore.js +30 -27
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +1 -0
- package/core/ApolloClient.js +20 -16
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.js +8 -8
- package/core/QueryInfo.js +1 -1
- package/core/QueryManager.js +12 -12
- package/core/RefetchEventManager.js +3 -3
- package/errors/CombinedGraphQLErrors.d.ts +2 -2
- package/errors/CombinedGraphQLErrors.js +3 -7
- package/errors/CombinedGraphQLErrors.js.map +1 -1
- package/errors/CombinedProtocolErrors.d.ts +2 -2
- package/errors/CombinedProtocolErrors.js +3 -8
- package/errors/CombinedProtocolErrors.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.js +2 -2
- package/incremental/handlers/notImplemented.js +1 -1
- package/invariantErrorCodes.js +125 -120
- package/link/core/ApolloLink.js +3 -3
- package/link/http/checkFetcher.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/ws/index.js +1 -1
- package/local-state/LocalState.js +24 -23
- package/local-state/LocalState.js.map +1 -1
- package/masking/maskDefinition.js +21 -3
- package/masking/maskDefinition.js.map +1 -1
- package/masking/maskFragment.js +2 -2
- package/masking/maskOperation.js +1 -1
- package/masking/utils.js +3 -3
- package/package.json +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/hooks/internal/validateSuspenseHookOptions.js +2 -2
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useFragment.js +8 -2
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +2 -2
- package/react/hooks/useLoadableQuery.js +2 -2
- package/react/hooks/useSubscription.js +1 -1
- package/react/hooks/useSuspenseFragment.js +10 -4
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/hooks-compiled/internal/validateSuspenseHookOptions.js +2 -2
- package/react/hooks-compiled/useApolloClient.js +1 -1
- package/react/hooks-compiled/useFragment.js +56 -32
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.js +2 -2
- package/react/hooks-compiled/useLoadableQuery.js +2 -2
- package/react/hooks-compiled/useSubscription.js +1 -1
- package/react/hooks-compiled/useSuspenseFragment.js +10 -4
- package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js +1 -1
- package/react/internal/cache/FragmentReference.d.ts +4 -5
- package/react/internal/cache/FragmentReference.js +2 -2
- package/react/internal/cache/FragmentReference.js.map +1 -1
- package/react/internal/cache/QueryReference.js +1 -1
- package/react/internal/cache/SuspenseCache.d.ts +4 -5
- package/react/internal/cache/SuspenseCache.js +3 -3
- package/react/internal/cache/SuspenseCache.js.map +1 -1
- package/react/internal/cache/types.d.ts +0 -5
- package/react/internal/cache/types.js.map +1 -1
- package/react/ssr/prerenderStatic.js +2 -2
- package/testing/core/mocking/mockLink.js +4 -4
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/internal/DeepMerger.d.ts +13 -3
- package/utilities/internal/DeepMerger.js +6 -2
- package/utilities/internal/DeepMerger.js.map +1 -1
- package/utilities/internal/constants.d.ts +32 -0
- package/utilities/internal/constants.js +32 -0
- package/utilities/internal/constants.js.map +1 -1
- package/utilities/internal/createArgumentNode.d.ts +3 -0
- package/utilities/internal/createArgumentNode.js +11 -0
- package/utilities/internal/createArgumentNode.js.map +1 -0
- package/utilities/internal/createDirectiveNode.d.ts +3 -0
- package/utilities/internal/createDirectiveNode.js +11 -0
- package/utilities/internal/createDirectiveNode.js.map +1 -0
- package/utilities/internal/createFragmentSpreadNode.d.ts +3 -2
- package/utilities/internal/createFragmentSpreadNode.js +4 -1
- package/utilities/internal/createFragmentSpreadNode.js.map +1 -1
- package/utilities/internal/createValueNode.d.ts +12 -0
- package/utilities/internal/createValueNode.js +24 -0
- package/utilities/internal/createValueNode.js.map +1 -0
- package/utilities/internal/equalByQuery.d.ts +2 -3
- package/utilities/internal/equalByQuery.js +8 -8
- package/utilities/internal/equalByQuery.js.map +1 -1
- package/utilities/internal/getFragmentDefinition.js +3 -3
- package/utilities/internal/getFragmentDefinition.js.map +1 -1
- package/utilities/internal/getFragmentFromSelection.js +1 -1
- package/utilities/internal/getFragmentQueryDocument.js +10 -2
- package/utilities/internal/getFragmentQueryDocument.js.map +1 -1
- package/utilities/internal/getFragmentScope.d.ts +13 -0
- package/utilities/internal/getFragmentScope.js +20 -0
- package/utilities/internal/getFragmentScope.js.map +1 -0
- package/utilities/internal/getFragmentVariables.d.ts +9 -5
- package/utilities/internal/getFragmentVariables.js +15 -16
- package/utilities/internal/getFragmentVariables.js.map +1 -1
- package/utilities/internal/getMainDefinition.js +1 -1
- package/utilities/internal/getQueryDefinition.js +1 -1
- package/utilities/internal/index.d.ts +5 -1
- package/utilities/internal/index.js +3 -1
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/isNonEmptyObject.d.ts +7 -0
- package/utilities/internal/isNonEmptyObject.js +10 -0
- package/utilities/internal/isNonEmptyObject.js.map +1 -0
- package/utilities/internal/isNonNullObject.d.ts +1 -1
- package/utilities/internal/isNonNullObject.js.map +1 -1
- package/utilities/internal/mapObservableFragment.d.ts +5 -1
- package/utilities/internal/mapObservableFragment.js +14 -9
- package/utilities/internal/mapObservableFragment.js.map +1 -1
- package/utilities/internal/mergeDeepArray.d.ts +2 -1
- package/utilities/internal/mergeDeepArray.js +2 -2
- package/utilities/internal/mergeDeepArray.js.map +1 -1
- package/utilities/internal/removeDirectivesFromDocument.js +1 -1
- package/utilities/internal/removeFragmentSpreads.d.ts +18 -2
- package/utilities/internal/removeFragmentSpreads.js +56 -3
- package/utilities/internal/removeFragmentSpreads.js.map +1 -1
- package/utilities/internal/shouldInclude.js +4 -4
- package/utilities/internal/types/FragmentInfo.d.ts +14 -0
- package/utilities/internal/types/FragmentInfo.js +2 -0
- package/utilities/internal/types/FragmentInfo.js.map +1 -0
- package/utilities/internal/types/ObjectWithFragmentInfo.d.ts +13 -0
- package/utilities/internal/types/ObjectWithFragmentInfo.js +2 -0
- package/utilities/internal/types/ObjectWithFragmentInfo.js.map +1 -0
- package/utilities/internal/valueToObjectRepresentation.js +1 -1
- package/version.js +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { c as _c } from "@apollo/client/react/internal/compiler-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
import { fragmentInfoSymbol } from "@apollo/client/utilities/internal";
|
|
3
4
|
import { useDeepMemo, wrapHook } from "./internal/index.js";
|
|
4
5
|
import { useApolloClient } from "./useApolloClient.js";
|
|
5
6
|
import { useSyncExternalStore } from "./useSyncExternalStore.js";
|
|
@@ -8,7 +9,7 @@ export function useFragment(options) {
|
|
|
8
9
|
return wrapHook("useFragment", useFragment_, useApolloClient(options.client))(options);
|
|
9
10
|
}
|
|
10
11
|
function useFragment_(options) {
|
|
11
|
-
const $ = _c(
|
|
12
|
+
const $ = _c(24);
|
|
12
13
|
const client = useApolloClient(options.client);
|
|
13
14
|
let from;
|
|
14
15
|
let rest;
|
|
@@ -51,51 +52,71 @@ function useFragment_(options) {
|
|
|
51
52
|
|
|
52
53
|
const ids_0 = useDeepMemo(t0, t1);
|
|
53
54
|
let t2;
|
|
55
|
+
|
|
56
|
+
if ($[7] !== from) {
|
|
57
|
+
t2 = Array.isArray(from) ? from.map(_temp) : from?.[fragmentInfoSymbol];
|
|
58
|
+
$[7] = from;
|
|
59
|
+
$[8] = t2;
|
|
60
|
+
} else {
|
|
61
|
+
t2 = $[8];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const fragmentInfo = t2;
|
|
54
65
|
let t3;
|
|
55
66
|
|
|
56
|
-
if ($[
|
|
57
|
-
|
|
67
|
+
if ($[9] !== from || $[10] !== rest) {
|
|
68
|
+
t3 = () => ({
|
|
58
69
|
...rest,
|
|
59
|
-
from
|
|
60
|
-
});
|
|
61
|
-
$[
|
|
62
|
-
$[
|
|
63
|
-
$[
|
|
64
|
-
$[10] = t3;
|
|
70
|
+
from
|
|
71
|
+
});
|
|
72
|
+
$[9] = from;
|
|
73
|
+
$[10] = rest;
|
|
74
|
+
$[11] = t3;
|
|
65
75
|
} else {
|
|
66
|
-
|
|
67
|
-
t3 = $[10];
|
|
76
|
+
t3 = $[11];
|
|
68
77
|
}
|
|
69
78
|
|
|
70
|
-
const stableOptions = useDeepMemo(t2, t3);
|
|
71
79
|
let t4;
|
|
72
80
|
|
|
73
|
-
if ($[
|
|
74
|
-
t4 =
|
|
75
|
-
$[
|
|
76
|
-
$[
|
|
77
|
-
$[
|
|
81
|
+
if ($[12] !== fragmentInfo || $[13] !== ids_0 || $[14] !== rest) {
|
|
82
|
+
t4 = [rest, ids_0, fragmentInfo];
|
|
83
|
+
$[12] = fragmentInfo;
|
|
84
|
+
$[13] = ids_0;
|
|
85
|
+
$[14] = rest;
|
|
86
|
+
$[15] = t4;
|
|
78
87
|
} else {
|
|
79
|
-
t4 = $[
|
|
88
|
+
t4 = $[15];
|
|
80
89
|
}
|
|
81
90
|
|
|
82
|
-
const
|
|
91
|
+
const stableOptions = useDeepMemo(t3, t4);
|
|
83
92
|
let t5;
|
|
84
93
|
|
|
85
|
-
if ($[
|
|
86
|
-
t5 =
|
|
87
|
-
$[
|
|
88
|
-
$[
|
|
89
|
-
$[
|
|
94
|
+
if ($[16] !== client || $[17] !== stableOptions) {
|
|
95
|
+
t5 = client.watchFragment(stableOptions);
|
|
96
|
+
$[16] = client;
|
|
97
|
+
$[17] = stableOptions;
|
|
98
|
+
$[18] = t5;
|
|
90
99
|
} else {
|
|
91
|
-
t5 = $[
|
|
100
|
+
t5 = $[18];
|
|
92
101
|
}
|
|
93
102
|
|
|
94
|
-
const
|
|
103
|
+
const observable = t5;
|
|
95
104
|
let t6;
|
|
96
105
|
|
|
97
|
-
if ($[
|
|
98
|
-
t6 =
|
|
106
|
+
if ($[19] !== from || $[20] !== observable) {
|
|
107
|
+
t6 = () => from === null ? nullResult : observable.getCurrentResult();
|
|
108
|
+
$[19] = from;
|
|
109
|
+
$[20] = observable;
|
|
110
|
+
$[21] = t6;
|
|
111
|
+
} else {
|
|
112
|
+
t6 = $[21];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const getSnapshot = t6;
|
|
116
|
+
let t7;
|
|
117
|
+
|
|
118
|
+
if ($[22] !== observable) {
|
|
119
|
+
t7 = update => {
|
|
99
120
|
let lastTimeout = 0;
|
|
100
121
|
const subscription = observable.subscribe({
|
|
101
122
|
next: () => {
|
|
@@ -109,13 +130,16 @@ function useFragment_(options) {
|
|
|
109
130
|
clearTimeout(lastTimeout);
|
|
110
131
|
};
|
|
111
132
|
};
|
|
112
|
-
$[
|
|
113
|
-
$[
|
|
133
|
+
$[22] = observable;
|
|
134
|
+
$[23] = t7;
|
|
114
135
|
} else {
|
|
115
|
-
|
|
136
|
+
t7 = $[23];
|
|
116
137
|
}
|
|
117
138
|
|
|
118
|
-
return useSyncExternalStore(
|
|
139
|
+
return useSyncExternalStore(t7, getSnapshot, getSnapshot);
|
|
140
|
+
}
|
|
141
|
+
function _temp(value_0) {
|
|
142
|
+
return value_0?.[fragmentInfoSymbol];
|
|
119
143
|
}
|
|
120
144
|
const nullResult = Object.freeze({
|
|
121
145
|
data: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFragment.js","sources":["../../../src/react/hooks/useFragment.ts"],"sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataValue,\n DocumentNode,\n GetDataState,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type { ApolloCache, MissingTree } from \"@apollo/client/cache\";\nimport type { MaybeMasked } from \"@apollo/client/masking\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\n\nexport declare namespace useFragment {\n export namespace Base {\n export interface Options<TData, TVariables extends OperationVariables> {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * An object or array containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID (uncommon).\n */\n from:\n | useFragment.FromOptionValue<TData>\n | Array<useFragment.FromOptionValue<TData> | null>\n | null;\n\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n *\n * @defaultValue true\n */\n optimistic?: boolean;\n\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;\n }\n }\n\n export type Options<\n TData,\n TVariables extends OperationVariables,\n > = Base.Options<TData, TVariables> & VariablesOption<NoInfer<TVariables>>;\n\n namespace DocumentationTypes {\n namespace useFragment {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options<TData, TVariables>,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n /**\n * Acceptable values provided to the `from` option.\n */\n export type FromOptionValue<TData> = ApolloCache.FromOptionValue<TData>;\n\n // TODO: Update this to return `null` when there is no data returned from the\n // fragment.\n export type Result<TData> =\n | ({\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: true;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: never;\n } & GetDataState<MaybeMasked<TData>, \"complete\">)\n | {\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: false;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: MissingTree;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: TData extends Array<infer TItem> ?\n Array<DataValue.Partial<TItem> | null>\n : DataValue.Partial<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"partial\";\n };\n\n export namespace DocumentationTypes {\n namespace useFragment {\n export interface Result<TData> {\n data: MaybeMasked<TData> | DataValue.Partial<MaybeMasked<TData>>;\n complete: boolean;\n /**\n * A tree of all `MissingFieldError` messages reported during fragment reading, where the branches of the tree indicate the paths of the errors within the query result.\n */\n missing?: MissingTree;\n }\n }\n }\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\n export function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >({\n fragment,\n from,\n fragmentName,\n variables,\n optimistic,\n client,\n }: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n }\n}\n\n/**\n * `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.\n *\n * Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.\n *\n * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.\n */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<useFragment.FromOptionValue<TData>>;\n }\n): useFragment.Result<Array<TData>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<null>;\n }\n): useFragment.Result<Array<null>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<useFragment.FromOptionValue<TData> | null>;\n }\n): useFragment.Result<Array<TData | null>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(options: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> | useFragment.Result<Array<TData | null>> {\n \"use no memo\";\n return wrapHook(\n \"useFragment\",\n useFragment_,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction useFragment_<TData, TVariables extends OperationVariables>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> | useFragment.Result<Array<TData | null>> {\n const client = useApolloClient(options.client);\n const { from, ...rest } = options;\n const { cache } = client;\n\n // We calculate the cache id seperately because we don't want changes to non\n // key fields in the `from` property to recreate the observable. If the cache\n // identifier stays the same between renders, we want to reuse the existing\n // subscription.\n const ids = useDeepMemo(() => {\n const fromArray = Array.isArray(from) ? from : [from];\n\n const ids = fromArray.map((value) =>\n typeof value === \"string\" ? value\n : value === null ? null\n : cache.identify(value)\n );\n\n return Array.isArray(from) ? ids : ids[0];\n }, [cache, from]);\n\n const stableOptions = useDeepMemo(\n () => ({ ...rest, from: ids as any }),\n [rest, ids]\n );\n\n const observable = React.useMemo(\n () => client.watchFragment(stableOptions),\n [client, stableOptions]\n );\n\n // Unfortunately we forgot to update the use case of `from: null` on\n // useFragment in 4.0 to match `useSuspenseFragment`. As such, we need to\n // fallback to data: {} with complete: false when `from` is `null` to maintain\n // backwards compatibility. We should plan to change this in v5.\n const getSnapshot = React.useCallback(\n () => (from === null ? nullResult : observable.getCurrentResult()),\n [from, observable]\n );\n\n return useSyncExternalStore(\n React.useCallback(\n (update) => {\n let lastTimeout = 0;\n const subscription = observable.subscribe({\n next: () => {\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(update) as any;\n },\n });\n\n return () => {\n subscription.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [observable]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nconst nullResult = Object.freeze({\n data: {},\n dataState: \"partial\",\n complete: false,\n}) as useFragment.Result<any>;\n"],"names":[],"mappings":";AAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAP,CAAA,EAAY,CAAZ,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAuB,CAAvB,CAAA,CAAA,CAAA,CAAA,CAAA,CAA8B;AAiB9B,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAoB,EAAE,CAAtB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAsC,CAAtC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA2D;AAC3D,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAgC,CAAhC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsD;AACtD,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAqC,CAArC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA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C/B,CAAF,CAAA,CAAA,CAAM,EAAE,CAAR,CAAU;IACR,CAAF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAW,EAAE,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsB;IACpB,CAAF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,EAAE,CAAZ,CAAA,CAAA,CAAA,CAAiB;AACjB,CAAC;"}
|
|
1
|
+
{"version":3,"file":"useFragment.js","sources":["../../../src/react/hooks/useFragment.ts"],"sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataValue,\n DocumentNode,\n GetDataState,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type { ApolloCache, MissingTree } from \"@apollo/client/cache\";\nimport type { MaybeMasked } from \"@apollo/client/masking\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n ObjectWithFragmentInfo,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\nimport { fragmentInfoSymbol } from \"@apollo/client/utilities/internal\";\n\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\n\nexport declare namespace useFragment {\n export namespace Base {\n export interface Options<TData, TVariables extends OperationVariables> {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * An object or array containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID (uncommon).\n */\n from:\n | useFragment.FromOptionValue<TData>\n | Array<useFragment.FromOptionValue<TData> | null>\n | null;\n\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n *\n * @defaultValue true\n */\n optimistic?: boolean;\n\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;\n }\n }\n\n export type Options<\n TData,\n TVariables extends OperationVariables,\n > = Base.Options<TData, TVariables> & VariablesOption<NoInfer<TVariables>>;\n\n namespace DocumentationTypes {\n namespace useFragment {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options<TData, TVariables>,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n /**\n * Acceptable values provided to the `from` option.\n */\n export type FromOptionValue<TData> = ApolloCache.FromOptionValue<TData>;\n\n // TODO: Update this to return `null` when there is no data returned from the\n // fragment.\n export type Result<TData> =\n | ({\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: true;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: never;\n } & GetDataState<MaybeMasked<TData>, \"complete\">)\n | {\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: false;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: MissingTree;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: TData extends Array<infer TItem> ?\n Array<DataValue.Partial<TItem> | null>\n : DataValue.Partial<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"partial\";\n };\n\n export namespace DocumentationTypes {\n namespace useFragment {\n export interface Result<TData> {\n data: MaybeMasked<TData> | DataValue.Partial<MaybeMasked<TData>>;\n complete: boolean;\n /**\n * A tree of all `MissingFieldError` messages reported during fragment reading, where the branches of the tree indicate the paths of the errors within the query result.\n */\n missing?: MissingTree;\n }\n }\n }\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\n export function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >({\n fragment,\n from,\n fragmentName,\n variables,\n optimistic,\n client,\n }: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n }\n}\n\n/**\n * `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.\n *\n * Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.\n *\n * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.\n */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<useFragment.FromOptionValue<TData>>;\n }\n): useFragment.Result<Array<TData>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<null>;\n }\n): useFragment.Result<Array<null>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<useFragment.FromOptionValue<TData> | null>;\n }\n): useFragment.Result<Array<TData | null>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(options: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> | useFragment.Result<Array<TData | null>> {\n \"use no memo\";\n return wrapHook(\n \"useFragment\",\n useFragment_,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction useFragment_<TData, TVariables extends OperationVariables>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> | useFragment.Result<Array<TData | null>> {\n const client = useApolloClient(options.client);\n const { from, ...rest } = options;\n const { cache } = client;\n\n // We calculate the cache id separately because we don't want changes to non\n // key fields in the `from` property to recreate the observable. If the cache\n // identifier stays the same between renders, we want to reuse the existing\n // subscription.\n const ids = useDeepMemo(() => {\n const fromArray = Array.isArray(from) ? from : [from];\n\n const ids = fromArray.map((value) =>\n typeof value === \"string\" ? value\n : value === null ? null\n : cache.identify(value)\n );\n\n return Array.isArray(from) ? ids : ids[0];\n }, [cache, from]);\n\n // `useDeepMemo` does not compare symbol keys, so the fragment info is\n // passed as a separate dependency to recreate the observable when it changes.\n const fragmentInfo =\n Array.isArray(from) ?\n from.map(\n (value) =>\n (value as ObjectWithFragmentInfo | null)?.[fragmentInfoSymbol]\n )\n : (from as ObjectWithFragmentInfo | null)?.[fragmentInfoSymbol];\n\n const stableOptions = useDeepMemo(\n () => ({ ...rest, from }),\n [rest, ids, fragmentInfo]\n );\n\n const observable = React.useMemo(\n () => client.watchFragment(stableOptions),\n [client, stableOptions]\n ) as ApolloCache.ObservableFragment<any>;\n\n // Unfortunately we forgot to update the use case of `from: null` on\n // useFragment in 4.0 to match `useSuspenseFragment`. As such, we need to\n // fallback to data: {} with complete: false when `from` is `null` to maintain\n // backwards compatibility. We should plan to change this in v5.\n const getSnapshot = React.useCallback(\n () => (from === null ? nullResult : observable.getCurrentResult()),\n [from, observable]\n );\n\n return useSyncExternalStore(\n React.useCallback(\n (update) => {\n let lastTimeout = 0;\n const subscription = observable.subscribe({\n next: () => {\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(update) as any;\n },\n });\n\n return () => {\n subscription.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [observable]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nconst nullResult = Object.freeze({\n data: {},\n dataState: \"partial\",\n complete: false,\n}) as useFragment.Result<any>;\n"],"names":[],"mappings":";AAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAP,CAAA,EAAY,CAAZ,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAuB,CAAvB,CAAA,CAAA,CAAA,CAAA,CAAA,CAA8B;AAiB9B,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAmC,CAAnC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsE;AAEtE,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAoB,EAAE,CAAtB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAsC,CAAtC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA2D;AAC3D,C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AA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAGmB,CAAC,CAHpB,CAAA,CAAA,CAAA,CAAA,CAAA,CAG2B,CAAC,CAH5B,CAAA,CAAA,CAAA,CAAA,CAGkC,CAAC,CAChC,CAAC,CAJJ,CAAA,CAAA,CAAA,CAAA,CAAA,CAIW,CAAC;AACZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAiFM,CAAN,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAmB,CAAnB,CAAA,CAAA,CAAA,CAAA,CAAyB,CAAC,CAA1B,CAAA,CAAA,CAAA,CAAA,CAAgC,CAAC;IAC/B,CAAF,CAAA,CAAA,CAAM,EAAE,CAAR,CAAU;IACR,CAAF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAW,EAAE,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsB;IACpB,CAAF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,EAAE,CAAZ,CAAA,CAAA,CAAA,CAAiB;AACjB,CAAC;"}
|
|
@@ -67,7 +67,7 @@ export const useLazyQuery = function useLazyQuery(query, options) {
|
|
|
67
67
|
const eagerMethods = {};
|
|
68
68
|
for (const key of EAGER_METHODS) {
|
|
69
69
|
eagerMethods[key] = function (...args) {
|
|
70
|
-
invariant(resultRef.current,
|
|
70
|
+
invariant(resultRef.current, 32, key);
|
|
71
71
|
// @ts-expect-error this is just to generic to type
|
|
72
72
|
return observable[key](...args);
|
|
73
73
|
};
|
|
@@ -105,7 +105,7 @@ export const useLazyQuery = function useLazyQuery(query, options) {
|
|
|
105
105
|
options?.skipPollAttempt,
|
|
106
106
|
]);
|
|
107
107
|
const execute = React.useCallback((...args_0) => {
|
|
108
|
-
invariant(!calledDuringRender(),
|
|
108
|
+
invariant(!calledDuringRender(), 33);
|
|
109
109
|
const [executeOptions] = args_0;
|
|
110
110
|
let fetchPolicy = observable.options.fetchPolicy;
|
|
111
111
|
if (fetchPolicy === "standby") {
|
|
@@ -122,7 +122,7 @@ export const useLoadableQuery = function useLoadableQuery(query, t0) {
|
|
|
122
122
|
if ($[17] !== calledDuringRender || $[18] !== client || $[19] !== query || $[20] !== queryKey || $[21] !== suspenseCache || $[22] !== watchQueryOptions) {
|
|
123
123
|
t8 = (...t9) => {
|
|
124
124
|
const args = t9;
|
|
125
|
-
invariant(!calledDuringRender(),
|
|
125
|
+
invariant(!calledDuringRender(), 34);
|
|
126
126
|
const [variables] = args;
|
|
127
127
|
const cacheKey = [query, canonicalStringify(variables), ...[].concat(queryKey)];
|
|
128
128
|
const queryRef_0 = suspenseCache.getQueryRef(cacheKey, () => client.watchQuery({
|
|
@@ -147,7 +147,7 @@ export const useLoadableQuery = function useLoadableQuery(query, t0) {
|
|
|
147
147
|
|
|
148
148
|
if ($[24] !== internalQueryRef) {
|
|
149
149
|
t9 = options_2 => {
|
|
150
|
-
invariant(internalQueryRef,
|
|
150
|
+
invariant(internalQueryRef, 35);
|
|
151
151
|
return internalQueryRef.observable.subscribeToMore(options_2);
|
|
152
152
|
};
|
|
153
153
|
$[24] = internalQueryRef;
|
|
@@ -315,7 +315,7 @@ export function useSubscription(subscription, ...t0) {
|
|
|
315
315
|
|
|
316
316
|
if ($[32] !== observable || $[33] !== setObservable) {
|
|
317
317
|
t15 = () => {
|
|
318
|
-
invariant(!optionsRef.current.skip,
|
|
318
|
+
invariant(!optionsRef.current.skip, 36);
|
|
319
319
|
if (observable?.__.completed) {
|
|
320
320
|
setObservable(recreateRef.current());
|
|
321
321
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { canonicalStringify } from "@apollo/client/cache";
|
|
3
2
|
import { getSuspenseCache } from "@apollo/client/react/internal";
|
|
3
|
+
import { fragmentInfoSymbol } from "@apollo/client/utilities/internal";
|
|
4
4
|
import { __use } from "./internal/__use.js";
|
|
5
5
|
import { useDeepMemo, wrapHook } from "./internal/index.js";
|
|
6
6
|
import { useApolloClient } from "./useApolloClient.js";
|
|
@@ -10,15 +10,21 @@ export function useSuspenseFragment(options) {
|
|
|
10
10
|
}
|
|
11
11
|
function useSuspenseFragment_(options) {
|
|
12
12
|
const client = useApolloClient(options.client);
|
|
13
|
-
const { from,
|
|
13
|
+
const { from, ...rest } = options;
|
|
14
14
|
const { cache } = client;
|
|
15
15
|
const ids = useDeepMemo(() => {
|
|
16
16
|
return Array.isArray(from) ?
|
|
17
17
|
from.map((id) => toStringId(cache, id))
|
|
18
18
|
: toStringId(cache, from);
|
|
19
19
|
}, [cache, from]);
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
// `useDeepMemo` does not compare symbol keys, so the fragment info is
|
|
21
|
+
// passed as a separate dependency to recreate the observable when it changes.
|
|
22
|
+
const fragmentInfo = Array.isArray(from) ?
|
|
23
|
+
from.map((value) => value?.[fragmentInfoSymbol])
|
|
24
|
+
: from?.[fragmentInfoSymbol];
|
|
25
|
+
const stableOptions = useDeepMemo(() => ({ ...rest, from }), [rest, ids, fragmentInfo]);
|
|
26
|
+
const observable = React.useMemo(() => client.watchFragment(stableOptions), [client, stableOptions]);
|
|
27
|
+
const fragmentRef = getSuspenseCache(client).getFragmentRef(observable);
|
|
22
28
|
let [current, setPromise] = React.useState([fragmentRef.key, fragmentRef.promise]);
|
|
23
29
|
React.useEffect(() => {
|
|
24
30
|
const dispose = fragmentRef.retain();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useSuspenseFragment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,OAAO,EAAE,kBAAkB,EAA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AAqD;IAErD,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI;QAC/B,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI;YACtB,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAkB,CAAC;AAC7C,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataValue,\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type { ApolloCache } from \"@apollo/client/cache\";\nimport { canonicalStringify } from \"@apollo/client/cache\";\nimport type { MaybeMasked } from \"@apollo/client/masking\";\nimport type { FragmentKey } from \"@apollo/client/react/internal\";\nimport { getSuspenseCache } from \"@apollo/client/react/internal\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport { __use } from \"./internal/__use.js\";\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\nexport declare namespace useSuspenseFragment {\n import _self = useSuspenseFragment;\n export namespace Base {\n export type Options<TData, TVariables extends OperationVariables> = {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * An object or array containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID (uncommon).\n */\n from:\n | useSuspenseFragment.FromOptionValue<TData>\n | Array<useSuspenseFragment.FromOptionValue<TData> | null>\n | null;\n\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;\n };\n }\n export type Options<\n TData,\n TVariables extends OperationVariables,\n > = Base.Options<TData, TVariables> & VariablesOption<NoInfer<TVariables>>;\n\n export namespace DocumentationTypes {\n export namespace useSuspenseFragment {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options<TData, TVariables>,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n /**\n * Acceptable values provided to the `from` option.\n */\n export type FromOptionValue<TData> = ApolloCache.FromOptionValue<TData>;\n\n export interface Result<TData> {\n data: DataValue.Complete<MaybeMasked<TData>>;\n }\n export namespace DocumentationTypes {\n export namespace useSuspenseFragment {\n export interface Result<TData = unknown> extends _self.Result<TData> {}\n }\n }\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\n export function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n >(\n options: useSuspenseFragment.Options<TData, TVariables>\n ): useSuspenseFragment.Result<TData>;\n }\n}\n\n/** #TODO documentation */\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: Array<useSuspenseFragment.FromOptionValue<TData>>;\n }\n): useSuspenseFragment.Result<Array<TData>>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: Array<null>;\n }\n): useSuspenseFragment.Result<Array<null>>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: Array<useSuspenseFragment.FromOptionValue<TData> | null>;\n }\n): useSuspenseFragment.Result<Array<TData | null>>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: useSuspenseFragment.FromOptionValue<TData>;\n }\n): useSuspenseFragment.Result<TData>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: null;\n }\n): useSuspenseFragment.Result<null>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: useSuspenseFragment.FromOptionValue<TData> | null;\n }\n): useSuspenseFragment.Result<TData | null>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData>;\n\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData | null> {\n \"use no memo\";\n return wrapHook(\n \"useSuspenseFragment\",\n useSuspenseFragment_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(options);\n}\n\nfunction useSuspenseFragment_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData | null> {\n const client = useApolloClient(options.client);\n const { from, variables } = options;\n const { cache } = client;\n\n const ids = useDeepMemo(() => {\n return Array.isArray(from) ?\n from.map((id) => toStringId(cache, id))\n : toStringId(cache, from);\n }, [cache, from]);\n const idString = React.useMemo(\n () => (Array.isArray(ids) ? ids.join(\",\") : ids),\n [ids]\n );\n\n const fragmentRef = getSuspenseCache(client).getFragmentRef(\n [options.fragment, canonicalStringify(variables), idString],\n client,\n { ...options, variables: variables as TVariables, from: ids }\n );\n\n let [current, setPromise] = React.useState<\n [FragmentKey, Promise<MaybeMasked<TData> | null>]\n >([fragmentRef.key, fragmentRef.promise]);\n\n React.useEffect(() => {\n const dispose = fragmentRef.retain();\n const removeListener = fragmentRef.listen((promise) => {\n setPromise([fragmentRef.key, promise]);\n });\n\n return () => {\n dispose();\n removeListener();\n };\n }, [fragmentRef]);\n\n if (current[0] !== fragmentRef.key) {\n // eslint-disable-next-line react-hooks/immutability\n current[0] = fragmentRef.key;\n // eslint-disable-next-line react-hooks/immutability\n current[1] = fragmentRef.promise;\n }\n\n const data = __use(current[1]);\n\n return { data };\n}\n\nfunction toStringId(\n cache: ApolloCache,\n from: useSuspenseFragment.FromOptionValue<any> | null\n) {\n return (\n typeof from === \"string\" ? from\n : from === null ? null\n : cache.identify(from)) as string | null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useSuspenseFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useSuspenseFragment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAY/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAMjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAwJvD,MAAM,UAAU,mBAAmB,CAIjC,OAAuD;IAEvD,aAAa,CAAC;IACd,OAAO,QAAQ,CACb,qBAAqB,E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,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAkB,CAAC;AAC7C,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataValue,\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type { ApolloCache } from \"@apollo/client/cache\";\nimport type { MaybeMasked } from \"@apollo/client/masking\";\nimport type { FragmentKey } from \"@apollo/client/react/internal\";\nimport { getSuspenseCache } from \"@apollo/client/react/internal\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n ObjectWithFragmentInfo,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\nimport { fragmentInfoSymbol } from \"@apollo/client/utilities/internal\";\n\nimport { __use } from \"./internal/__use.js\";\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\nexport declare namespace useSuspenseFragment {\n import _self = useSuspenseFragment;\n export namespace Base {\n export type Options<TData, TVariables extends OperationVariables> = {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * An object or array containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID (uncommon).\n */\n from:\n | useSuspenseFragment.FromOptionValue<TData>\n | Array<useSuspenseFragment.FromOptionValue<TData> | null>\n | null;\n\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;\n };\n }\n export type Options<\n TData,\n TVariables extends OperationVariables,\n > = Base.Options<TData, TVariables> & VariablesOption<NoInfer<TVariables>>;\n\n export namespace DocumentationTypes {\n export namespace useSuspenseFragment {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options<TData, TVariables>,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n /**\n * Acceptable values provided to the `from` option.\n */\n export type FromOptionValue<TData> = ApolloCache.FromOptionValue<TData>;\n\n export interface Result<TData> {\n data: DataValue.Complete<MaybeMasked<TData>>;\n }\n export namespace DocumentationTypes {\n export namespace useSuspenseFragment {\n export interface Result<TData = unknown> extends _self.Result<TData> {}\n }\n }\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\n export function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n >(\n options: useSuspenseFragment.Options<TData, TVariables>\n ): useSuspenseFragment.Result<TData>;\n }\n}\n\n/** #TODO documentation */\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: Array<useSuspenseFragment.FromOptionValue<TData>>;\n }\n): useSuspenseFragment.Result<Array<TData>>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: Array<null>;\n }\n): useSuspenseFragment.Result<Array<null>>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: Array<useSuspenseFragment.FromOptionValue<TData> | null>;\n }\n): useSuspenseFragment.Result<Array<TData | null>>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: useSuspenseFragment.FromOptionValue<TData>;\n }\n): useSuspenseFragment.Result<TData>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: null;\n }\n): useSuspenseFragment.Result<null>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: useSuspenseFragment.FromOptionValue<TData> | null;\n }\n): useSuspenseFragment.Result<TData | null>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData>;\n\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData | null> {\n \"use no memo\";\n return wrapHook(\n \"useSuspenseFragment\",\n useSuspenseFragment_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(options);\n}\n\nfunction useSuspenseFragment_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData | null> {\n const client = useApolloClient(options.client);\n const { from, ...rest } = options;\n const { cache } = client;\n\n const ids = useDeepMemo(() => {\n return Array.isArray(from) ?\n from.map((id) => toStringId(cache, id))\n : toStringId(cache, from);\n }, [cache, from]);\n\n // `useDeepMemo` does not compare symbol keys, so the fragment info is\n // passed as a separate dependency to recreate the observable when it changes.\n const fragmentInfo =\n Array.isArray(from) ?\n from.map(\n (value) =>\n (value as ObjectWithFragmentInfo | null)?.[fragmentInfoSymbol]\n )\n : (from as ObjectWithFragmentInfo | null)?.[fragmentInfoSymbol];\n\n const stableOptions = useDeepMemo(\n () => ({ ...rest, from }),\n [rest, ids, fragmentInfo]\n );\n\n const observable = React.useMemo(\n () => client.watchFragment(stableOptions),\n [client, stableOptions]\n );\n const fragmentRef = getSuspenseCache(client).getFragmentRef(observable);\n\n let [current, setPromise] = React.useState<\n [FragmentKey, Promise<MaybeMasked<TData> | null>]\n >([fragmentRef.key, fragmentRef.promise]);\n\n React.useEffect(() => {\n const dispose = fragmentRef.retain();\n const removeListener = fragmentRef.listen((promise) => {\n setPromise([fragmentRef.key, promise]);\n });\n\n return () => {\n dispose();\n removeListener();\n };\n }, [fragmentRef]);\n\n if (current[0] !== fragmentRef.key) {\n // eslint-disable-next-line react-hooks/immutability\n current[0] = fragmentRef.key;\n // eslint-disable-next-line react-hooks/immutability\n current[1] = fragmentRef.promise;\n }\n\n const data = __use(current[1]);\n\n return { data };\n}\n\nfunction toStringId(\n cache: ApolloCache,\n from: useSuspenseFragment.FromOptionValue<any> | null\n) {\n return (\n typeof from === \"string\" ? from\n : from === null ? null\n : cache.identify(from)) as string | null;\n}\n"]}
|
|
@@ -46,7 +46,7 @@ export const useSyncExternalStore = realHook ||
|
|
|
46
46
|
value !== getSnapshot()) {
|
|
47
47
|
didWarnUncachedGetSnapshot = true;
|
|
48
48
|
// DEVIATION: Using invariant.error instead of console.error directly.
|
|
49
|
-
invariant.error(
|
|
49
|
+
invariant.error(37);
|
|
50
50
|
}
|
|
51
51
|
// Because updates are synchronous, we don't queue them. Instead we force a
|
|
52
52
|
// re-render whenever the subscribed state changes by updating an some
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ApolloClient
|
|
1
|
+
import type { ApolloClient } from "@apollo/client";
|
|
2
|
+
import type { ApolloCache } from "@apollo/client/cache";
|
|
2
3
|
import type { MaybeMasked } from "@apollo/client/masking";
|
|
3
4
|
import type { DecoratedPromise } from "@apollo/client/utilities/internal";
|
|
4
5
|
import type { FragmentKey } from "./types.js";
|
|
@@ -8,7 +9,7 @@ interface FragmentReferenceOptions {
|
|
|
8
9
|
autoDisposeTimeoutMs?: number;
|
|
9
10
|
onDispose?: () => void;
|
|
10
11
|
}
|
|
11
|
-
export declare class FragmentReference<TData = unknown
|
|
12
|
+
export declare class FragmentReference<TData = unknown> {
|
|
12
13
|
readonly observable: ApolloClient.ObservableFragment<TData | null>;
|
|
13
14
|
readonly key: FragmentKey;
|
|
14
15
|
promise: FragmentRefPromise<MaybeMasked<TData>>;
|
|
@@ -18,9 +19,7 @@ export declare class FragmentReference<TData = unknown, TVariables extends Opera
|
|
|
18
19
|
private listeners;
|
|
19
20
|
private autoDisposeTimeoutId?;
|
|
20
21
|
private references;
|
|
21
|
-
constructor(
|
|
22
|
-
from: string | null | Array<string | null>;
|
|
23
|
-
}, options: FragmentReferenceOptions);
|
|
22
|
+
constructor(observable: ApolloCache.ObservableFragment<TData | null>, options: FragmentReferenceOptions);
|
|
24
23
|
listen(listener: Listener<MaybeMasked<TData>>): () => void;
|
|
25
24
|
retain(): () => void;
|
|
26
25
|
private dispose;
|
|
@@ -10,11 +10,11 @@ export class FragmentReference {
|
|
|
10
10
|
listeners = new Set();
|
|
11
11
|
autoDisposeTimeoutId;
|
|
12
12
|
references = 0;
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(observable, options) {
|
|
14
14
|
this.dispose = this.dispose.bind(this);
|
|
15
15
|
this.handleNext = this.handleNext.bind(this);
|
|
16
16
|
this.handleError = this.handleError.bind(this);
|
|
17
|
-
this.observable =
|
|
17
|
+
this.observable = observable;
|
|
18
18
|
if (options.onDispose) {
|
|
19
19
|
this.onDispose = options.onDispose;
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FragmentReference.js","sourceRoot":"","sources":["../../../../src/react/internal/cache/FragmentReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"FragmentReference.js","sourceRoot":"","sources":["../../../../src/react/internal/cache/FragmentReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAOtC,OAAO,EACL,sBAAsB,EACtB,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAY3C,MAAM,OAAO,iBAAiB;IACZ,UAAU,CAAgD;IAC1D,GAAG,GAAgB,EAAE,CAAC;IAC/B,OAAO,CAA0C;IAEhD,OAAO,CAAqD;IAC5D,MAAM,CAAyC;IAE/C,YAAY,CAAgB;IAC5B,SAAS,GAAG,IAAI,GAAG,EAAgC,CAAC;IACpD,oBAAoB,CAAkB;IAEtC,UAAU,GAAG,CAAC,CAAC;IAEvB,YACE,UAAwD,EACxD,OAAiC;QAEjC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE/C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAE7B,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACtB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACrC,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;QAElD,oEAAoE;QACpE,2EAA2E;QAC3E,uEAAuE;QACvE,8BAA8B;QAC9B,MAAM,iBAAiB,GAAG,GAAG,EAAE;YAC7B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;gBACrB,IAAI,CAAC,oBAAoB,GAAG,UAAU,CACpC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AE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,CAAC;IAEO,oBAAoB;QAC1B,OAAO,eAAe,CACpB,IAAI,OAAO,CAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { equal } from \"@wry/equality\";\nimport type { Subscription } from \"rxjs\";\n\nimport type { ApolloClient } from \"@apollo/client\";\nimport type { ApolloCache } from \"@apollo/client/cache\";\nimport type { MaybeMasked } from \"@apollo/client/masking\";\nimport type { DecoratedPromise } from \"@apollo/client/utilities/internal\";\nimport {\n createFulfilledPromise,\n decoratePromise,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { FragmentKey } from \"./types.js\";\n\ntype FragmentRefPromise<TData> = DecoratedPromise<TData>;\ntype Listener<TData> = (promise: FragmentRefPromise<TData>) => void;\n\ninterface FragmentReferenceOptions {\n autoDisposeTimeoutMs?: number;\n onDispose?: () => void;\n}\n\nexport class FragmentReference<TData = unknown> {\n public readonly observable: ApolloClient.ObservableFragment<TData | null>;\n public readonly key: FragmentKey = {};\n public promise!: FragmentRefPromise<MaybeMasked<TData>>;\n\n private resolve: ((result: MaybeMasked<TData>) => void) | undefined;\n private reject: ((error: unknown) => void) | undefined;\n\n private subscription!: Subscription;\n private listeners = new Set<Listener<MaybeMasked<TData>>>();\n private autoDisposeTimeoutId?: NodeJS.Timeout;\n\n private references = 0;\n\n constructor(\n observable: ApolloCache.ObservableFragment<TData | null>,\n options: FragmentReferenceOptions\n ) {\n this.dispose = this.dispose.bind(this);\n this.handleNext = this.handleNext.bind(this);\n this.handleError = this.handleError.bind(this);\n\n this.observable = observable;\n\n if (options.onDispose) {\n this.onDispose = options.onDispose;\n }\n\n const result = this.observable.getCurrentResult();\n\n // Start a timer that will automatically dispose of the query if the\n // suspended resource does not use this fragmentRef in the given time. This\n // helps prevent memory leaks when a component has unmounted before the\n // query has finished loading.\n const startDisposeTimer = () => {\n if (!this.references) {\n this.autoDisposeTimeoutId = setTimeout(\n this.dispose,\n options.autoDisposeTimeoutMs ?? 30_000\n );\n }\n };\n\n this.promise =\n result.complete ?\n createFulfilledPromise(result.data)\n : this.createPendingPromise();\n this.subscribeToFragment();\n\n this.promise.then(startDisposeTimer, startDisposeTimer);\n }\n\n listen(listener: Listener<MaybeMasked<TData>>) {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n retain() {\n this.references++;\n clearTimeout(this.autoDisposeTimeoutId);\n let disposed = false;\n\n return () => {\n if (disposed) {\n return;\n }\n\n disposed = true;\n this.references--;\n\n setTimeout(() => {\n if (!this.references) {\n this.dispose();\n }\n });\n };\n }\n\n private dispose() {\n this.subscription.unsubscribe();\n }\n\n private onDispose() {\n // noop. overridable by options\n }\n\n private subscribeToFragment() {\n this.subscription = this.observable.subscribe(\n this.handleNext.bind(this),\n this.handleError.bind(this)\n );\n // call `onDispose` when the subscription is finalized, either because it is\n // unsubscribed as a consequence of a `dispose` call or because the\n // ObservableQuery completes because of a `ApolloClient.stop()` call.\n this.subscription.add(this.onDispose);\n }\n\n private handleNext(result: ApolloClient.WatchFragmentResult<TData | null>) {\n switch (this.promise.status) {\n case \"pending\": {\n if (result.complete) {\n return this.resolve?.(result.data);\n }\n\n this.deliver(this.promise);\n break;\n }\n case \"fulfilled\": {\n // This can occur when we already have a result written to the cache and\n // we subscribe for the first time. We create a fulfilled promise in the\n // constructor with a value that is the same as the first emitted value\n // so we want to skip delivering it.\n if (equal(this.promise.value, result.data)) {\n return;\n }\n\n this.promise =\n result.complete ?\n createFulfilledPromise(result.data)\n : this.createPendingPromise();\n\n this.deliver(this.promise);\n }\n }\n }\n\n private handleError(error: unknown) {\n this.reject?.(error);\n }\n\n private deliver(promise: FragmentRefPromise<MaybeMasked<TData>>) {\n this.listeners.forEach((listener) => listener(promise));\n }\n\n private createPendingPromise() {\n return decoratePromise(\n new Promise<MaybeMasked<TData>>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n })\n );\n }\n}\n"]}
|
|
@@ -11,7 +11,7 @@ export function wrapQueryRef(internalQueryRef) {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
export function assertWrappedQueryRef(queryRef) {
|
|
14
|
-
invariant(!queryRef || QUERY_REFERENCE_SYMBOL in queryRef,
|
|
14
|
+
invariant(!queryRef || QUERY_REFERENCE_SYMBOL in queryRef, 30);
|
|
15
15
|
}
|
|
16
16
|
export function getWrappedPromise(queryRef) {
|
|
17
17
|
const internalQueryRef = unwrapQueryRef(queryRef);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DataState, ObservableQuery } from "@apollo/client";
|
|
2
|
+
import type { ApolloCache } from "@apollo/client/cache";
|
|
2
3
|
import { FragmentReference } from "./FragmentReference.js";
|
|
3
4
|
import { InternalQueryReference } from "./QueryReference.js";
|
|
4
|
-
import type { CacheKey
|
|
5
|
+
import type { CacheKey } from "./types.js";
|
|
5
6
|
export interface SuspenseCacheOptions {
|
|
6
7
|
/**
|
|
7
8
|
* Specifies the amount of time, in milliseconds, the suspense cache will wait
|
|
@@ -21,9 +22,7 @@ export declare class SuspenseCache {
|
|
|
21
22
|
private options;
|
|
22
23
|
constructor(options?: SuspenseCacheOptions);
|
|
23
24
|
getQueryRef<TData = unknown, TStates extends DataState<TData>["dataState"] = DataState<TData>["dataState"]>(cacheKey: CacheKey, createObservable: () => ObservableQuery<TData>): InternalQueryReference<TData, TStates>;
|
|
24
|
-
getFragmentRef<TData
|
|
25
|
-
from: string | null | Array<string | null>;
|
|
26
|
-
}): FragmentReference<TData, TVariables>;
|
|
25
|
+
getFragmentRef<TData>(observable: ApolloCache.ObservableFragment<TData | null>): FragmentReference<TData>;
|
|
27
26
|
add(cacheKey: CacheKey, queryRef: InternalQueryReference<any, any>): void;
|
|
28
27
|
}
|
|
29
28
|
//# sourceMappingURL=SuspenseCache.d.ts.map
|
|
@@ -20,10 +20,10 @@ export class SuspenseCache {
|
|
|
20
20
|
}
|
|
21
21
|
return ref.current;
|
|
22
22
|
}
|
|
23
|
-
getFragmentRef(
|
|
24
|
-
const ref = this.fragmentRefs.
|
|
23
|
+
getFragmentRef(observable) {
|
|
24
|
+
const ref = this.fragmentRefs.lookup(observable);
|
|
25
25
|
if (!ref.current) {
|
|
26
|
-
ref.current = new FragmentReference(
|
|
26
|
+
ref.current = new FragmentReference(observable, {
|
|
27
27
|
autoDisposeTimeoutMs: this.options.autoDisposeTimeoutMs,
|
|
28
28
|
onDispose: () => {
|
|
29
29
|
delete ref.current;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuspenseCache.js","sourceRoot":"","sources":["../../../../src/react/internal/cache/SuspenseCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"SuspenseCache.js","sourceRoot":"","sources":["../../../../src/react/internal/cache/SuspenseCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAKjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAiB7D,MAAM,OAAO,aAAa;IAChB,SAAS,GAAG,IAAI,IAAI,EAAwC,CAAC;IAC7D,YAAY,GAAG,IAAI,IAAI,EAAmC,CAAC;IAE3D,OAAO,CAAuB;IAEtC,YAAY,UAAgC,EAAE;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,WAAW,CAIT,QAAkB,EAAE,gBAA8C;QAClE,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,CAE9C,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YACjB,GAAG,CAAC,OAAO,GAAG,IAAI,sBAAsB,CAAC,gBAAgB,EAAE,EAAE;gBAC3D,oBAAoB,EAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB;gBACvD,SAAS,EAAE,GAAG,EAAE;oBACd,OAAO,GAAG,CAAC,OAAO,CAAC;gBACrB,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,cAAc,CACZ,UAAwD;QAExD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAE9C,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YACjB,GAAG,CAAC,OAAO,GAAG,IAAI,iBAAiB,CAAC,UAAU,EAAE;gBAC9C,oBAAoB,EAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB;gBACvD,SAAS,EAAE,GAAG,EAAE;oBACd,OAAO,GAAG,CAAC,OAAO,CAAC;gBACrB,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,GAAG,CAAC,QAAkB,EAAE,QAA0C;QAChE,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACjD,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC;IACzB,CAAC;CACF","sourcesContent":["import { Trie } from \"@wry/trie\";\n\nimport type { DataState, ObservableQuery } from \"@apollo/client\";\nimport type { ApolloCache } from \"@apollo/client/cache\";\n\nimport { FragmentReference } from \"./FragmentReference.js\";\nimport { InternalQueryReference } from \"./QueryReference.js\";\nimport type { CacheKey } from \"./types.js\";\n\nexport interface SuspenseCacheOptions {\n /**\n * Specifies the amount of time, in milliseconds, the suspense cache will wait\n * for a suspended component to read from the suspense cache before it\n * automatically disposes of the query. This prevents memory leaks when a\n * component unmounts before a suspended resource finishes loading. Increase\n * the timeout if your queries take longer than than the specified time to\n * prevent your queries from suspending over and over.\n *\n * Defaults to 30 seconds.\n */\n autoDisposeTimeoutMs?: number;\n}\n\nexport class SuspenseCache {\n private queryRefs = new Trie<{ current?: InternalQueryReference }>();\n private fragmentRefs = new Trie<{ current?: FragmentReference }>();\n\n private options: SuspenseCacheOptions;\n\n constructor(options: SuspenseCacheOptions = {}) {\n this.options = options;\n }\n\n getQueryRef<\n TData = unknown,\n TStates extends\n DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n >(cacheKey: CacheKey, createObservable: () => ObservableQuery<TData>) {\n const ref = this.queryRefs.lookupArray(cacheKey) as {\n current?: InternalQueryReference<TData, TStates>;\n };\n\n if (!ref.current) {\n ref.current = new InternalQueryReference(createObservable(), {\n autoDisposeTimeoutMs: this.options.autoDisposeTimeoutMs,\n onDispose: () => {\n delete ref.current;\n },\n });\n }\n\n return ref.current;\n }\n\n getFragmentRef<TData>(\n observable: ApolloCache.ObservableFragment<TData | null>\n ) {\n const ref = this.fragmentRefs.lookup(observable) as {\n current?: FragmentReference<TData>;\n };\n\n if (!ref.current) {\n ref.current = new FragmentReference(observable, {\n autoDisposeTimeoutMs: this.options.autoDisposeTimeoutMs,\n onDispose: () => {\n delete ref.current;\n },\n });\n }\n\n return ref.current;\n }\n\n add(cacheKey: CacheKey, queryRef: InternalQueryReference<any, any>) {\n const ref = this.queryRefs.lookupArray(cacheKey);\n ref.current = queryRef;\n }\n}\n"]}
|
|
@@ -4,11 +4,6 @@ export type CacheKey = [
|
|
|
4
4
|
stringifiedVariables: string,
|
|
5
5
|
...queryKey: any[]
|
|
6
6
|
];
|
|
7
|
-
export type FragmentCacheKey = [
|
|
8
|
-
fragment: DocumentNode,
|
|
9
|
-
stringifiedVariables: string,
|
|
10
|
-
cacheId: string | null
|
|
11
|
-
];
|
|
12
7
|
export interface QueryKey {
|
|
13
8
|
__queryKey?: string;
|
|
14
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/react/internal/cache/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode } from \"graphql\";\n\nexport type CacheKey = [\n query: DocumentNode,\n stringifiedVariables: string,\n ...queryKey: any[],\n];\n\nexport
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/react/internal/cache/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode } from \"graphql\";\n\nexport type CacheKey = [\n query: DocumentNode,\n stringifiedVariables: string,\n ...queryKey: any[],\n];\n\nexport interface QueryKey {\n __queryKey?: string;\n}\n\nexport interface FragmentKey {\n __fragmentKey?: string;\n}\n"]}
|
|
@@ -53,8 +53,8 @@ export function prerenderStatic(
|
|
|
53
53
|
};
|
|
54
54
|
async function process() {
|
|
55
55
|
renderCount++;
|
|
56
|
-
invariant(renderCount <= maxRerenders,
|
|
57
|
-
invariant(!signal?.aborted,
|
|
56
|
+
invariant(renderCount <= maxRerenders, 28, maxRerenders);
|
|
57
|
+
invariant(!signal?.aborted, 29);
|
|
58
58
|
// Always re-render from the rootElement, even though it might seem
|
|
59
59
|
// better to render the children of the component responsible for the
|
|
60
60
|
// promise, because it is not possible to reconstruct the full context
|
|
@@ -6,7 +6,7 @@ import { addTypenameToDocument, print } from "@apollo/client/utilities";
|
|
|
6
6
|
import { checkDocument, cloneDeep, getDefaultValues, getOperationDefinition, isDocumentNode, makeUniqueId, removeDirectivesFromDocument, } from "@apollo/client/utilities/internal";
|
|
7
7
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
8
8
|
export function realisticDelay({ min = 20, max = 50, } = {}) {
|
|
9
|
-
invariant(max > min,
|
|
9
|
+
invariant(max > min, 24);
|
|
10
10
|
return () => Math.floor(Math.random() * (max - min) + min);
|
|
11
11
|
}
|
|
12
12
|
export class MockLink extends ApolloLink {
|
|
@@ -138,14 +138,14 @@ ${unmatchedVars.map((d) => ` ${stringifyForDebugging(d)}`).join("\n")}
|
|
|
138
138
|
}
|
|
139
139
|
function getServerQuery(query) {
|
|
140
140
|
const queryWithoutClientOnlyDirectives = removeDirectivesFromDocument([{ name: "connection" }, { name: "nonreactive" }, { name: "unmask" }], query);
|
|
141
|
-
invariant(queryWithoutClientOnlyDirectives,
|
|
141
|
+
invariant(queryWithoutClientOnlyDirectives, 25);
|
|
142
142
|
const serverQuery = removeDirectivesFromDocument([{ name: "client", remove: true }], queryWithoutClientOnlyDirectives);
|
|
143
|
-
invariant(serverQuery,
|
|
143
|
+
invariant(serverQuery, 26);
|
|
144
144
|
return serverQuery;
|
|
145
145
|
}
|
|
146
146
|
function validateMockedResponse(mock) {
|
|
147
147
|
checkDocument(mock.request.query);
|
|
148
|
-
invariant((mock.maxUsageCount ?? 1) > 0,
|
|
148
|
+
invariant((mock.maxUsageCount ?? 1) > 0, 27, mock.maxUsageCount);
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
151
|
* @internal
|
|
@@ -96,7 +96,7 @@ export class DocumentTransform {
|
|
|
96
96
|
makeCacheKey: (document) => {
|
|
97
97
|
const cacheKeys = this.getCacheKey(document);
|
|
98
98
|
if (cacheKeys) {
|
|
99
|
-
invariant(Array.isArray(cacheKeys),
|
|
99
|
+
invariant(Array.isArray(cacheKeys), 23);
|
|
100
100
|
return stableCacheKeys.lookupArray(cacheKeys);
|
|
101
101
|
}
|
|
102
102
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNonNullObject } from "./isNonNullObject.js";
|
|
2
|
-
type ReconcilerFunction = (this: DeepMerger, target: Record<
|
|
2
|
+
type ReconcilerFunction<TKey extends PropertyKey = string | number> = (this: DeepMerger, target: Record<TKey, any>, source: Record<TKey, any>, property: TKey) => any;
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@ type ReconcilerFunction = (this: DeepMerger, target: Record<string | number, any
|
|
|
8
8
|
export declare namespace DeepMerger {
|
|
9
9
|
interface Options {
|
|
10
10
|
arrayMerge?: DeepMerger.ArrayMergeStrategy;
|
|
11
|
-
|
|
11
|
+
includeSymbols?: boolean;
|
|
12
12
|
}
|
|
13
13
|
interface MergeOptions {
|
|
14
14
|
atPath?: ReadonlyArray<string | number>;
|
|
@@ -23,7 +23,17 @@ export declare namespace DeepMerger {
|
|
|
23
23
|
export declare class DeepMerger {
|
|
24
24
|
private options;
|
|
25
25
|
private reconciler;
|
|
26
|
-
constructor(options
|
|
26
|
+
constructor(options: DeepMerger.Options & {
|
|
27
|
+
includeSymbols?: false;
|
|
28
|
+
reconciler: ReconcilerFunction<string | number>;
|
|
29
|
+
});
|
|
30
|
+
constructor(options: DeepMerger.Options & {
|
|
31
|
+
includeSymbols: true;
|
|
32
|
+
reconciler: ReconcilerFunction<PropertyKey>;
|
|
33
|
+
});
|
|
34
|
+
constructor(options?: DeepMerger.Options & {
|
|
35
|
+
reconciler?: never;
|
|
36
|
+
});
|
|
27
37
|
merge(target: any, source: any, mergeOptions?: DeepMerger.MergeOptions): any;
|
|
28
38
|
isObject: typeof isNonNullObject;
|
|
29
39
|
private pastCopies;
|