@apollo/client 4.0.10 → 4.0.12-beta.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/CHANGELOG.md +217 -0
- package/__cjs/cache/core/cache.cjs +216 -52
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +141 -25
- package/__cjs/cache/core/types/Cache.d.cts +77 -17
- package/__cjs/cache/index.cjs.map +1 -1
- package/__cjs/cache/index.d.cts +1 -1
- package/__cjs/cache/inmemory/entityStore.cjs +6 -4
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/helpers.d.cts +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +62 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +48 -0
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.cjs +56 -17
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.d.cts +30 -6
- package/__cjs/cache/inmemory/readFromStore.cjs +3 -3
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/types.d.cts +2 -0
- package/__cjs/cache/inmemory/writeToStore.cjs +24 -10
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.d.cts +2 -1
- package/__cjs/core/ApolloClient.cjs +31 -49
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +159 -18
- package/__cjs/core/ObservableQuery.cjs +173 -128
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +2 -0
- package/__cjs/core/QueryInfo.cjs +9 -1
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +2 -1
- package/__cjs/core/QueryManager.cjs +47 -25
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +18 -2
- package/__cjs/incremental/handlers/defer20220824.cjs +44 -19
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +15 -7
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +222 -0
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -0
- package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +98 -0
- package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
- package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
- package/__cjs/incremental/index.cjs +3 -1
- package/__cjs/incremental/index.cjs.map +1 -1
- package/__cjs/incremental/index.d.cts +1 -0
- package/__cjs/incremental/types.d.cts +9 -0
- package/__cjs/invariantErrorCodes.cjs +83 -61
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +13 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +1 -1
- package/__cjs/link/core/ApolloLink.cjs +3 -3
- package/__cjs/link/error/index.cjs +1 -1
- package/__cjs/link/error/index.cjs.map +1 -1
- package/__cjs/link/error/index.d.cts +1 -1
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +2 -2
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +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 +28 -14
- package/__cjs/local-state/LocalState.cjs.map +1 -1
- package/__cjs/local-state/LocalState.d.cts +3 -2
- package/__cjs/masking/types.d.cts +2 -1
- package/__cjs/react/hooks/internal/useDeepMemo.cjs +2 -0
- package/__cjs/react/hooks/internal/useDeepMemo.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.cjs +1 -3
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.cjs +38 -87
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +65 -6
- package/__cjs/react/hooks/useLazyQuery.cjs +3 -0
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.cjs +7 -1
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +13 -1
- package/__cjs/react/hooks/useQuery.cjs +8 -8
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.cjs +1 -3
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.cjs +1 -3
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.cjs +1 -1
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.cjs +16 -16
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.d.cts +33 -7
- package/__cjs/react/hooks/useSuspenseQuery.cjs +6 -4
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/internal/cache/FragmentReference.cjs +3 -22
- package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/FragmentReference.d.cts +2 -4
- package/__cjs/react/internal/cache/QueryReference.cjs +16 -0
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +5 -0
- package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
- package/__cjs/react/internal/cache/SuspenseCache.d.cts +1 -1
- package/__cjs/react/internal/cache/types.d.cts +2 -2
- package/__cjs/react/query-preloader/createQueryPreloader.cjs +41 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/ssr/useSSRQuery.cjs +1 -0
- package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
- package/__cjs/utilities/DeepPartial.cjs.map +1 -1
- package/__cjs/utilities/DeepPartial.d.cts +1 -1
- package/__cjs/utilities/internal/DeepMerger.cjs +36 -4
- package/__cjs/utilities/internal/DeepMerger.cjs.map +1 -1
- package/__cjs/utilities/internal/DeepMerger.d.cts +20 -4
- package/__cjs/utilities/internal/combineLatestBatched.cjs +71 -0
- package/__cjs/utilities/internal/combineLatestBatched.cjs.map +1 -0
- package/__cjs/utilities/internal/combineLatestBatched.d.cts +14 -0
- package/__cjs/utilities/internal/constants.cjs +29 -0
- package/__cjs/utilities/internal/constants.cjs.map +1 -0
- package/__cjs/utilities/internal/constants.d.cts +26 -0
- package/__cjs/utilities/internal/getStoreKeyName.cjs +1 -0
- package/__cjs/utilities/internal/getStoreKeyName.cjs.map +1 -1
- package/__cjs/utilities/internal/index.cjs +10 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +4 -0
- package/__cjs/utilities/internal/mapObservableFragment.cjs +27 -0
- package/__cjs/utilities/internal/mapObservableFragment.cjs.map +1 -0
- package/__cjs/utilities/internal/mapObservableFragment.d.cts +3 -0
- package/__cjs/utilities/internal/memoize.cjs +2 -2
- package/__cjs/utilities/internal/memoize.cjs.map +1 -1
- package/__cjs/utilities/internal/memoize.d.cts +2 -1
- package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.cjs +61 -0
- package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.cjs.map +1 -0
- package/__cjs/utilities/internal/ponyfills/FinalizationRegistry.d.cts +11 -0
- package/__cjs/utilities/internal/ponyfills/index.cjs +6 -0
- package/__cjs/utilities/internal/ponyfills/index.cjs.map +1 -0
- package/__cjs/utilities/internal/ponyfills/index.d.cts +3 -0
- package/__cjs/utilities/internal/ponyfills/index.react-native.cjs +6 -0
- package/__cjs/utilities/internal/ponyfills/index.react-native.cjs.map +1 -0
- package/__cjs/utilities/internal/ponyfills/index.react-native.d.cts +2 -0
- package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.cjs +3 -0
- package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.cjs.map +1 -0
- package/__cjs/utilities/internal/types/ExtensionsWithStreamDetails.d.cts +24 -0
- package/__cjs/version.cjs +1 -1
- package/__cjs/version.cjs.map +1 -1
- package/cache/core/cache.d.ts +141 -25
- package/cache/core/cache.js +219 -55
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +77 -17
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/index.d.ts +1 -1
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.js +6 -4
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/helpers.d.ts +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +48 -0
- package/cache/inmemory/inMemoryCache.js +62 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/key-extractor.js.map +1 -1
- package/cache/inmemory/policies.d.ts +30 -6
- package/cache/inmemory/policies.js +45 -7
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +3 -3
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +2 -0
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +2 -1
- package/cache/inmemory/writeToStore.js +26 -12
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +159 -18
- package/core/ApolloClient.js +32 -50
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +2 -0
- package/core/ObservableQuery.js +176 -131
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +2 -1
- package/core/QueryInfo.js +10 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +18 -2
- package/core/QueryManager.js +48 -26
- package/core/QueryManager.js.map +1 -1
- package/incremental/handlers/defer20220824.d.ts +15 -7
- package/incremental/handlers/defer20220824.js +44 -19
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.d.ts +98 -0
- package/incremental/handlers/graphql17Alpha9.js +218 -0
- package/incremental/handlers/graphql17Alpha9.js.map +1 -0
- package/incremental/handlers/notImplemented.js +1 -1
- package/incremental/handlers/notImplemented.js.map +1 -1
- package/incremental/index.d.ts +1 -0
- package/incremental/index.js +3 -2
- package/incremental/index.js.map +1 -1
- package/incremental/types.d.ts +9 -0
- package/incremental/types.js.map +1 -1
- package/invariantErrorCodes.js +83 -61
- package/legacyEntryPoints/utilities/internal/ponyfills/index.d.ts +1 -0
- package/legacyEntryPoints/utilities/internal/ponyfills/index.js +1 -0
- package/legacyEntryPoints/utilities/internal/ponyfills/ponyfills.cjs +1 -0
- package/legacyEntryPoints/utilities/internal/ponyfills/ponyfills.d.cts +1 -0
- package/link/client-awareness/ClientAwarenessLink.d.ts +1 -1
- package/link/client-awareness/ClientAwarenessLink.js +13 -1
- package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
- package/link/core/ApolloLink.js +3 -3
- package/link/error/index.d.ts +1 -1
- package/link/error/index.js +1 -1
- package/link/error/index.js.map +1 -1
- package/link/http/checkFetcher.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js +2 -2
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/ws/index.js +1 -1
- package/local-state/LocalState.d.ts +3 -2
- package/local-state/LocalState.js +28 -14
- package/local-state/LocalState.js.map +1 -1
- package/masking/types.d.ts +2 -1
- package/masking/types.js.map +1 -1
- package/package.json +15 -1
- package/react/hooks/internal/useDeepMemo.js +2 -0
- package/react/hooks/internal/useDeepMemo.js.map +1 -1
- package/react/hooks/useBackgroundQuery.js +1 -3
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.d.ts +65 -6
- package/react/hooks/useFragment.js +38 -87
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +4 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +13 -1
- package/react/hooks/useMutation.js +7 -1
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.js +9 -9
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.js +1 -3
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReadQuery.js +1 -3
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +1 -1
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseFragment.d.ts +33 -7
- package/react/hooks/useSuspenseFragment.js +17 -17
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +6 -4
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/internal/useDeepMemo.js +2 -0
- package/react/hooks-compiled/internal/useDeepMemo.js.map +1 -1
- package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js +0 -2
- package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.js +1 -3
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useFragment.d.ts +65 -6
- package/react/hooks-compiled/useFragment.js +110 -88
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.js +4 -1
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.js +69 -75
- package/react/hooks-compiled/useMutation.d.ts +13 -1
- package/react/hooks-compiled/useMutation.js +5 -13
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.js +53 -61
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.js +1 -5
- package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
- package/react/hooks-compiled/useReadQuery.js +77 -14
- package/react/hooks-compiled/useReadQuery.js.map +1 -1
- package/react/hooks-compiled/useSubscription.js +237 -93
- package/react/hooks-compiled/useSubscription.js.map +1 -1
- package/react/hooks-compiled/useSuspenseFragment.d.ts +33 -7
- package/react/hooks-compiled/useSuspenseFragment.js +17 -17
- package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.js +7 -9
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/index.compiled.d.ts +1 -1
- package/react/index.compiled.js +1 -1
- package/react/index.compiled.js.map +1 -1
- package/react/internal/cache/FragmentReference.d.ts +2 -4
- package/react/internal/cache/FragmentReference.js +3 -22
- package/react/internal/cache/FragmentReference.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +5 -0
- package/react/internal/cache/QueryReference.js +16 -0
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/cache/SuspenseCache.d.ts +1 -1
- package/react/internal/cache/SuspenseCache.js.map +1 -1
- package/react/internal/cache/types.d.ts +2 -2
- package/react/internal/cache/types.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.js +41 -1
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/ssr/useSSRQuery.js +1 -0
- package/react/ssr/useSSRQuery.js.map +1 -1
- package/utilities/DeepPartial.d.ts +1 -1
- package/utilities/DeepPartial.js.map +1 -1
- package/utilities/internal/DeepMerger.d.ts +20 -4
- package/utilities/internal/DeepMerger.js +36 -4
- package/utilities/internal/DeepMerger.js.map +1 -1
- package/utilities/internal/combineLatestBatched.d.ts +14 -0
- package/utilities/internal/combineLatestBatched.js +68 -0
- package/utilities/internal/combineLatestBatched.js.map +1 -0
- package/utilities/internal/constants.d.ts +26 -0
- package/utilities/internal/constants.js +26 -0
- package/utilities/internal/constants.js.map +1 -0
- package/utilities/internal/getStoreKeyName.js +1 -0
- package/utilities/internal/getStoreKeyName.js.map +1 -1
- package/utilities/internal/index.d.ts +4 -0
- package/utilities/internal/index.js +3 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/mapObservableFragment.d.ts +3 -0
- package/utilities/internal/mapObservableFragment.js +24 -0
- package/utilities/internal/mapObservableFragment.js.map +1 -0
- package/utilities/internal/memoize.d.ts +2 -1
- package/utilities/internal/memoize.js +2 -2
- package/utilities/internal/memoize.js.map +1 -1
- package/utilities/internal/ponyfills/FinalizationRegistry.d.ts +11 -0
- package/utilities/internal/ponyfills/FinalizationRegistry.js +57 -0
- package/utilities/internal/ponyfills/FinalizationRegistry.js.map +1 -0
- package/utilities/internal/ponyfills/index.d.ts +3 -0
- package/utilities/internal/ponyfills/index.js +3 -0
- package/utilities/internal/ponyfills/index.js.map +1 -0
- package/utilities/internal/ponyfills/index.react-native.d.ts +2 -0
- package/utilities/internal/ponyfills/index.react-native.js +2 -0
- package/utilities/internal/ponyfills/index.react-native.js.map +1 -0
- package/utilities/internal/types/ExtensionsWithStreamDetails.d.ts +24 -0
- package/utilities/internal/types/ExtensionsWithStreamDetails.js +2 -0
- package/utilities/internal/types/ExtensionsWithStreamDetails.js.map +1 -0
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionsWithStreamDetails.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Trie } from "@wry/trie";
|
|
2
|
+
import type { Incremental } from "@apollo/client/incremental";
|
|
3
|
+
import type { streamDetailsSymbol } from "../constants.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*
|
|
7
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
8
|
+
*/
|
|
9
|
+
export interface ExtensionsWithStreamDetails extends Record<string, unknown> {
|
|
10
|
+
[streamDetailsSymbol]?: {
|
|
11
|
+
current: Trie<{
|
|
12
|
+
current: Incremental.StreamFieldInfo;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*
|
|
19
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
20
|
+
*/
|
|
21
|
+
export interface WithExtensionsWithStreamDetails {
|
|
22
|
+
extensions?: ExtensionsWithStreamDetails;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=ExtensionsWithStreamDetails.d.cts.map
|
package/__cjs/version.cjs
CHANGED
package/__cjs/version.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.cjs","sources":["../../src/version.ts"],"sourcesContent":["export const version = \"local\" as string;\nexport const build = \"source\" as \"source\" | \"esm\" | \"cjs\";\n"],"names":[],"mappings":";;;AAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,
|
|
1
|
+
{"version":3,"file":"version.cjs","sources":["../../src/version.ts"],"sourcesContent":["export const version = \"local\" as string;\nexport const build = \"source\" as \"source\" | \"esm\" | \"cjs\";\n"],"names":[],"mappings":";;;AAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,iBAAwC;AAC3B,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAb,CAAA,CAAA,CAAA,EAAA,OAAyD;"}
|
package/cache/core/cache.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import type { DocumentNode, FragmentDefinitionNode, InlineFragmentNode } from "graphql";
|
|
2
2
|
import { Observable } from "rxjs";
|
|
3
|
-
import type { GetDataState, OperationVariables, TypedDocumentNode } from "@apollo/client";
|
|
3
|
+
import type { DataValue, GetDataState, OperationVariables, TypedDocumentNode } from "@apollo/client";
|
|
4
4
|
import type { FragmentType, Unmasked } from "@apollo/client/masking";
|
|
5
5
|
import type { Reference, StoreObject } from "@apollo/client/utilities";
|
|
6
|
-
import type { NoInfer } from "@apollo/client/utilities/internal";
|
|
6
|
+
import type { IsAny, NoInfer, Prettify } from "@apollo/client/utilities/internal";
|
|
7
7
|
import { getApolloCacheMemoryInternals } from "@apollo/client/utilities/internal";
|
|
8
8
|
import type { Cache } from "./types/Cache.js";
|
|
9
9
|
import type { MissingTree } from "./types/common.js";
|
|
10
10
|
export type Transaction = (c: ApolloCache) => void;
|
|
11
11
|
export declare namespace ApolloCache {
|
|
12
|
+
/**
|
|
13
|
+
* Acceptable values provided to the `from` option.
|
|
14
|
+
*/
|
|
15
|
+
type FromOptionValue<TData> = StoreObject | Reference | FragmentType<NoInfer<TData>> | string;
|
|
12
16
|
/**
|
|
13
17
|
* Watched fragment options.
|
|
14
18
|
*/
|
|
@@ -28,7 +32,7 @@ export declare namespace ApolloCache {
|
|
|
28
32
|
*
|
|
29
33
|
* @docGroup 1. Required options
|
|
30
34
|
*/
|
|
31
|
-
from:
|
|
35
|
+
from: ApolloCache.FromOptionValue<TData> | Array<ApolloCache.FromOptionValue<TData> | null> | null;
|
|
32
36
|
/**
|
|
33
37
|
* Any variables that the GraphQL fragment may depend on.
|
|
34
38
|
*
|
|
@@ -56,13 +60,51 @@ export declare namespace ApolloCache {
|
|
|
56
60
|
/**
|
|
57
61
|
* Watched fragment results.
|
|
58
62
|
*/
|
|
59
|
-
type WatchFragmentResult<TData = unknown> = ({
|
|
63
|
+
type WatchFragmentResult<TData = unknown> = true extends IsAny<TData> ? ({
|
|
64
|
+
complete: true;
|
|
65
|
+
missing?: never;
|
|
66
|
+
} & GetDataState<any, "complete">) | ({
|
|
67
|
+
complete: false;
|
|
68
|
+
missing?: MissingTree;
|
|
69
|
+
} & GetDataState<any, "partial">) : TData extends null | null[] ? Prettify<{
|
|
70
|
+
complete: true;
|
|
71
|
+
missing?: never;
|
|
72
|
+
} & GetDataState<TData, "complete">> : Prettify<{
|
|
60
73
|
complete: true;
|
|
61
74
|
missing?: never;
|
|
62
|
-
} & GetDataState<TData, "complete"
|
|
75
|
+
} & GetDataState<TData, "complete">> | {
|
|
63
76
|
complete: false;
|
|
64
|
-
missing
|
|
65
|
-
|
|
77
|
+
missing?: MissingTree;
|
|
78
|
+
/**
|
|
79
|
+
* An object containing the result of your GraphQL query after it completes.
|
|
80
|
+
*
|
|
81
|
+
* This value might be `undefined` if a query results in one or more errors (depending on the query's `errorPolicy`).
|
|
82
|
+
*
|
|
83
|
+
* @docGroup 1. Operation data
|
|
84
|
+
*/
|
|
85
|
+
data: TData extends Array<infer TItem> ? Array<DataValue.Partial<TItem> | null> : DataValue.Partial<TData>;
|
|
86
|
+
/**
|
|
87
|
+
* Describes the completeness of `data`.
|
|
88
|
+
*
|
|
89
|
+
* - `empty`: No data could be fulfilled from the cache or the result is
|
|
90
|
+
* incomplete. `data` is `undefined`.
|
|
91
|
+
* - `partial`: Some data could be fulfilled from the cache but `data` is
|
|
92
|
+
* incomplete. This is only possible when `returnPartialData` is `true`.
|
|
93
|
+
* - `streaming`: `data` is incomplete as a result of a deferred query and
|
|
94
|
+
* the result is still streaming in.
|
|
95
|
+
* - `complete`: `data` is a fully satisfied query result fulfilled
|
|
96
|
+
* either from the cache or network.
|
|
97
|
+
*
|
|
98
|
+
* @docGroup 1. Operation data
|
|
99
|
+
*/
|
|
100
|
+
dataState: "partial";
|
|
101
|
+
};
|
|
102
|
+
interface ObservableFragment<TData = unknown> extends Observable<ApolloCache.WatchFragmentResult<TData>> {
|
|
103
|
+
/**
|
|
104
|
+
* Return the current result for the fragment.
|
|
105
|
+
*/
|
|
106
|
+
getCurrentResult: () => ApolloCache.WatchFragmentResult<TData>;
|
|
107
|
+
}
|
|
66
108
|
}
|
|
67
109
|
export declare abstract class ApolloCache {
|
|
68
110
|
readonly assumeImmutableResults: boolean;
|
|
@@ -98,6 +140,72 @@ export declare abstract class ApolloCache {
|
|
|
98
140
|
abstract removeOptimistic(id: string): void;
|
|
99
141
|
abstract fragmentMatches(fragment: InlineFragmentNode | FragmentDefinitionNode, typename: string): boolean;
|
|
100
142
|
lookupFragment(fragmentName: string): FragmentDefinitionNode | null;
|
|
143
|
+
/**
|
|
144
|
+
* Determines whether a `@client` field can be resolved by the cache. Used
|
|
145
|
+
* when `LocalState` does not have a local resolver that can resolve the
|
|
146
|
+
* field.
|
|
147
|
+
*
|
|
148
|
+
* @remarks Cache implementations should return `true` if a mechanism in the
|
|
149
|
+
* cache is expected to provide a value for the field. `LocalState` will set
|
|
150
|
+
* the value of the field to `undefined` in order for the cache to handle it.
|
|
151
|
+
*
|
|
152
|
+
* Cache implementations should return `false` to indicate that it cannot
|
|
153
|
+
* handle resolving the field (either because it doesn't have a mechanism to
|
|
154
|
+
* do so, or because the user hasn't provided enough information to resolve
|
|
155
|
+
* the field). Returning `false` will emit a warning and set the value of the
|
|
156
|
+
* field to `null`.
|
|
157
|
+
*
|
|
158
|
+
* A cache that doesn't implement `resolvesClientField` will be treated the
|
|
159
|
+
* same as returning `false`.
|
|
160
|
+
*/
|
|
161
|
+
resolvesClientField?(typename: string, fieldName: string): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Executes multiple cache operations as a single batch, ensuring that
|
|
164
|
+
* watchers are only notified once after all operations complete. This is
|
|
165
|
+
* useful for improving performance when making multiple cache updates, as it
|
|
166
|
+
* prevents unnecessary re-renders or query refetches between individual
|
|
167
|
+
* operations.
|
|
168
|
+
*
|
|
169
|
+
* The `batch` method supports both optimistic and non-optimistic updates, and
|
|
170
|
+
* provides fine-grained control over which cache layer receives the updates
|
|
171
|
+
* and when watchers are notified.
|
|
172
|
+
*
|
|
173
|
+
* For usage instructions, see [Interacting with cached data: `cache.batch`](https://www.apollographql.com/docs/react/caching/cache-interaction#using-cachebatch).
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
*
|
|
177
|
+
* ```js
|
|
178
|
+
* cache.batch({
|
|
179
|
+
* update(cache) {
|
|
180
|
+
* cache.writeQuery({
|
|
181
|
+
* query: GET_TODOS,
|
|
182
|
+
* data: { todos: updatedTodos },
|
|
183
|
+
* });
|
|
184
|
+
* cache.evict({ id: "Todo:123" });
|
|
185
|
+
* },
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
*
|
|
191
|
+
* ```js
|
|
192
|
+
* // Optimistic update with a custom layer ID
|
|
193
|
+
* cache.batch({
|
|
194
|
+
* optimistic: "add-todo-optimistic",
|
|
195
|
+
* update(cache) {
|
|
196
|
+
* cache.modify({
|
|
197
|
+
* fields: {
|
|
198
|
+
* todos(existing = []) {
|
|
199
|
+
* return [...existing, newTodoRef];
|
|
200
|
+
* },
|
|
201
|
+
* },
|
|
202
|
+
* });
|
|
203
|
+
* },
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @returns The return value of the `update` function.
|
|
208
|
+
*/
|
|
101
209
|
batch<U>(options: Cache.BatchOptions<this, U>): U;
|
|
102
210
|
abstract performTransaction(transaction: Transaction, optimisticId?: string | null): void;
|
|
103
211
|
recordOptimisticTransaction(transaction: Transaction, optimisticId: string): void;
|
|
@@ -119,28 +227,35 @@ export declare abstract class ApolloCache {
|
|
|
119
227
|
* instead of passing it as a separate option.
|
|
120
228
|
*/
|
|
121
229
|
optimistic: boolean): Unmasked<TData> | null;
|
|
230
|
+
private fragmentWatches;
|
|
231
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
232
|
+
from: Array<ApolloCache.FromOptionValue<TData>>;
|
|
233
|
+
}): ApolloCache.ObservableFragment<Array<Unmasked<TData>>>;
|
|
234
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
235
|
+
from: Array<null>;
|
|
236
|
+
}): ApolloCache.ObservableFragment<Array<null>>;
|
|
237
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
238
|
+
from: Array<ApolloCache.FromOptionValue<TData> | null>;
|
|
239
|
+
}): ApolloCache.ObservableFragment<Array<Unmasked<TData> | null>>;
|
|
240
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
241
|
+
from: null;
|
|
242
|
+
}): ApolloCache.ObservableFragment<null>;
|
|
243
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
244
|
+
from: ApolloCache.FromOptionValue<TData>;
|
|
245
|
+
}): ApolloCache.ObservableFragment<Unmasked<TData>>;
|
|
246
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables>): ApolloCache.ObservableFragment<Unmasked<TData> | null>;
|
|
122
247
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
* with multiple fragments that represent what you are reading. If you pass
|
|
130
|
-
* in a document with multiple fragments then you must also specify a
|
|
131
|
-
* `fragmentName`.
|
|
132
|
-
*
|
|
133
|
-
* @since 3.10.0
|
|
134
|
-
* @param options - An object of type `WatchFragmentOptions` that allows
|
|
135
|
-
* the cache to identify the fragment and optionally specify whether to react
|
|
136
|
-
* to optimistic updates.
|
|
137
|
-
*/
|
|
138
|
-
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables>): Observable<ApolloCache.WatchFragmentResult<Unmasked<TData>>>;
|
|
248
|
+
* Can be overridden by subclasses to delay calling the provided callback
|
|
249
|
+
* until after all broadcasts have been completed - e.g. in a cache scenario
|
|
250
|
+
* where many watchers are notified in parallel.
|
|
251
|
+
*/
|
|
252
|
+
protected onAfterBroadcast: (cb: () => void) => void;
|
|
253
|
+
private watchSingleFragment;
|
|
139
254
|
private getFragmentDoc;
|
|
140
255
|
/**
|
|
141
256
|
* Read data from the cache for the specified fragment.
|
|
142
257
|
*/
|
|
143
|
-
readFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ fragment, variables, fragmentName, id, optimistic, returnPartialData, }: Cache.ReadFragmentOptions<TData, TVariables>): Unmasked<TData> | null;
|
|
258
|
+
readFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ fragment, variables, fragmentName, id, from, optimistic, returnPartialData, }: Cache.ReadFragmentOptions<TData, TVariables>): Unmasked<TData> | null;
|
|
144
259
|
readFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: Cache.ReadFragmentOptions<TData, TVariables>,
|
|
145
260
|
/**
|
|
146
261
|
* @deprecated Pass the `optimistic` argument as part of the first argument
|
|
@@ -158,9 +273,10 @@ export declare abstract class ApolloCache {
|
|
|
158
273
|
* fragment to validate that the shape of the data you’re writing to the cache
|
|
159
274
|
* is the same as the shape of the data required by the fragment.
|
|
160
275
|
*/
|
|
161
|
-
writeFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ data, fragment, fragmentName, variables, overwrite, id, broadcast, }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
|
|
276
|
+
writeFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ data, fragment, fragmentName, variables, overwrite, id, from, broadcast, }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
|
|
162
277
|
updateQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: Cache.UpdateQueryOptions<TData, TVariables>, update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void): Unmasked<TData> | null;
|
|
163
278
|
updateFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: Cache.UpdateFragmentOptions<TData, TVariables>, update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void): Unmasked<TData> | null;
|
|
279
|
+
private toCacheId;
|
|
164
280
|
/**
|
|
165
281
|
* @experimental
|
|
166
282
|
* @internal
|
package/cache/core/cache.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { WeakCache } from "@wry/caches";
|
|
2
|
+
import { equal } from "@wry/equality";
|
|
3
|
+
import { Trie } from "@wry/trie";
|
|
2
4
|
import { wrap } from "optimism";
|
|
3
|
-
import { Observable } from "rxjs";
|
|
4
|
-
import { cacheSizes } from "@apollo/client/utilities";
|
|
5
|
+
import { distinctUntilChanged, map, Observable, ReplaySubject, share, shareReplay, tap, timer, } from "rxjs";
|
|
6
|
+
import { cacheSizes, canonicalStringify } from "@apollo/client/utilities";
|
|
5
7
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
6
|
-
import { equalByQuery, getApolloCacheMemoryInternals, getFragmentDefinition, getFragmentQueryDocument, } from "@apollo/client/utilities/internal";
|
|
8
|
+
import { combineLatestBatched, equalByQuery, getApolloCacheMemoryInternals, getFragmentDefinition, getFragmentQueryDocument, mapObservableFragmentMemoized, } from "@apollo/client/utilities/internal";
|
|
7
9
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
8
10
|
export class ApolloCache {
|
|
9
11
|
assumeImmutableResults = false;
|
|
@@ -14,11 +16,53 @@ export class ApolloCache {
|
|
|
14
16
|
return null;
|
|
15
17
|
}
|
|
16
18
|
// Transactional API
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Executes multiple cache operations as a single batch, ensuring that
|
|
21
|
+
* watchers are only notified once after all operations complete. This is
|
|
22
|
+
* useful for improving performance when making multiple cache updates, as it
|
|
23
|
+
* prevents unnecessary re-renders or query refetches between individual
|
|
24
|
+
* operations.
|
|
25
|
+
*
|
|
26
|
+
* The `batch` method supports both optimistic and non-optimistic updates, and
|
|
27
|
+
* provides fine-grained control over which cache layer receives the updates
|
|
28
|
+
* and when watchers are notified.
|
|
29
|
+
*
|
|
30
|
+
* For usage instructions, see [Interacting with cached data: `cache.batch`](https://www.apollographql.com/docs/react/caching/cache-interaction#using-cachebatch).
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
*
|
|
34
|
+
* ```js
|
|
35
|
+
* cache.batch({
|
|
36
|
+
* update(cache) {
|
|
37
|
+
* cache.writeQuery({
|
|
38
|
+
* query: GET_TODOS,
|
|
39
|
+
* data: { todos: updatedTodos },
|
|
40
|
+
* });
|
|
41
|
+
* cache.evict({ id: "Todo:123" });
|
|
42
|
+
* },
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
*
|
|
48
|
+
* ```js
|
|
49
|
+
* // Optimistic update with a custom layer ID
|
|
50
|
+
* cache.batch({
|
|
51
|
+
* optimistic: "add-todo-optimistic",
|
|
52
|
+
* update(cache) {
|
|
53
|
+
* cache.modify({
|
|
54
|
+
* fields: {
|
|
55
|
+
* todos(existing = []) {
|
|
56
|
+
* return [...existing, newTodoRef];
|
|
57
|
+
* },
|
|
58
|
+
* },
|
|
59
|
+
* });
|
|
60
|
+
* },
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @returns The return value of the `update` function.
|
|
65
|
+
*/
|
|
22
66
|
batch(options) {
|
|
23
67
|
const optimisticId = typeof options.optimistic === "string" ? options.optimistic
|
|
24
68
|
: options.optimistic === false ? null
|
|
@@ -57,6 +101,7 @@ export class ApolloCache {
|
|
|
57
101
|
optimistic,
|
|
58
102
|
});
|
|
59
103
|
}
|
|
104
|
+
fragmentWatches = new Trie(true);
|
|
60
105
|
/**
|
|
61
106
|
* Watches the cache store of the fragment according to the options specified
|
|
62
107
|
* and returns an `Observable`. We can subscribe to this
|
|
@@ -74,61 +119,159 @@ export class ApolloCache {
|
|
|
74
119
|
* to optimistic updates.
|
|
75
120
|
*/
|
|
76
121
|
watchFragment(options) {
|
|
77
|
-
const { fragment, fragmentName, from
|
|
122
|
+
const { fragment, fragmentName, from } = options;
|
|
78
123
|
const query = this.getFragmentDoc(fragment, fragmentName);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
: this.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
124
|
+
const fromArray = Array.isArray(from) ? from : [from];
|
|
125
|
+
const ids = fromArray.map((value) => {
|
|
126
|
+
// While our TypeScript types do not allow for `undefined` as a valid
|
|
127
|
+
// `from`, its possible `useFragment` gives us an `undefined` since it
|
|
128
|
+
// calls` cache.identify` and provides that value to `from`. We are
|
|
129
|
+
// adding this fix here however to ensure those using plain JavaScript
|
|
130
|
+
// and using `cache.identify` themselves will avoid seeing the obscure
|
|
131
|
+
// warning.
|
|
132
|
+
const id = value == null ? value : this.toCacheId(value);
|
|
133
|
+
if (__DEV__) {
|
|
134
|
+
const actualFragmentName = fragmentName || getFragmentDefinition(fragment).name.value;
|
|
135
|
+
if (id === undefined) {
|
|
136
|
+
__DEV__ && invariant.warn(113, actualFragmentName);
|
|
137
|
+
}
|
|
92
138
|
}
|
|
139
|
+
return id;
|
|
140
|
+
});
|
|
141
|
+
if (!Array.isArray(from)) {
|
|
142
|
+
const observable = this.watchSingleFragment(ids[0], query, options);
|
|
143
|
+
// Unfortunately we forgot to allow for `null` on watchFragment in 4.0
|
|
144
|
+
// when `from` is a single record. As such, we need to fallback to {}
|
|
145
|
+
// when diff.result is null to maintain backwards compatibility. We
|
|
146
|
+
// should plan to change this in v5. We do however support `null` if
|
|
147
|
+
// `from` is explicitly `null`.
|
|
148
|
+
//
|
|
149
|
+
// NOTE: Using `from` with an array will maintain `null` properly
|
|
150
|
+
// without the need for a similar fallback since watchFragment with
|
|
151
|
+
// arrays is new functionality in v4.1.
|
|
152
|
+
return from === null ? observable : (mapObservableFragmentMemoized(observable, Symbol.for("apollo.transform.individualResult"), (result) => ({
|
|
153
|
+
...result,
|
|
154
|
+
data: result.data ?? {},
|
|
155
|
+
})));
|
|
93
156
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
157
|
+
let currentResult;
|
|
158
|
+
function toResult(results) {
|
|
159
|
+
const result = results.reduce((memo, result, idx) => {
|
|
160
|
+
memo.data.push(result.data);
|
|
161
|
+
memo.complete &&= result.complete;
|
|
162
|
+
memo.dataState = memo.complete ? "complete" : "partial";
|
|
163
|
+
if (result.missing) {
|
|
164
|
+
memo.missing ||= {};
|
|
165
|
+
memo.missing[idx] = result.missing;
|
|
166
|
+
}
|
|
167
|
+
return memo;
|
|
168
|
+
}, {
|
|
169
|
+
data: [],
|
|
170
|
+
dataState: "complete",
|
|
171
|
+
complete: true,
|
|
172
|
+
});
|
|
173
|
+
if (!equal(currentResult, result)) {
|
|
174
|
+
currentResult = result;
|
|
175
|
+
}
|
|
176
|
+
return currentResult;
|
|
177
|
+
}
|
|
178
|
+
if (ids.length === 0) {
|
|
179
|
+
return emptyArrayObservable;
|
|
180
|
+
}
|
|
181
|
+
let subscribed = false;
|
|
182
|
+
const observables = ids.map((id) => this.watchSingleFragment(id, query, options));
|
|
183
|
+
const observable = combineLatestBatched(observables).pipe(map(toResult), tap({
|
|
184
|
+
subscribe: () => (subscribed = true),
|
|
185
|
+
unsubscribe: () => (subscribed = false),
|
|
186
|
+
}), shareReplay({ bufferSize: 1, refCount: true }));
|
|
187
|
+
return Object.assign(observable, {
|
|
188
|
+
getCurrentResult: () => {
|
|
189
|
+
if (subscribed && currentResult) {
|
|
190
|
+
return currentResult;
|
|
191
|
+
}
|
|
192
|
+
const results = observables.map((observable) => observable.getCurrentResult());
|
|
193
|
+
return toResult(results);
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Can be overridden by subclasses to delay calling the provided callback
|
|
199
|
+
* until after all broadcasts have been completed - e.g. in a cache scenario
|
|
200
|
+
* where many watchers are notified in parallel.
|
|
201
|
+
*/
|
|
202
|
+
onAfterBroadcast = (cb) => cb();
|
|
203
|
+
watchSingleFragment(id, fragmentQuery, options) {
|
|
204
|
+
if (id === null) {
|
|
205
|
+
return nullObservable;
|
|
206
|
+
}
|
|
207
|
+
const { optimistic = true, variables } = options;
|
|
208
|
+
const cacheKey = [
|
|
209
|
+
fragmentQuery,
|
|
210
|
+
canonicalStringify({ id, optimistic, variables }),
|
|
211
|
+
];
|
|
212
|
+
const cacheEntry = this.fragmentWatches.lookupArray(cacheKey);
|
|
213
|
+
if (!cacheEntry.observable) {
|
|
214
|
+
let subscribed = false;
|
|
215
|
+
let currentResult;
|
|
216
|
+
function getNewestResult(diff) {
|
|
217
|
+
const data = diff.result;
|
|
218
|
+
if (!currentResult ||
|
|
219
|
+
!equalByQuery(fragmentQuery, { data: currentResult.data }, { data }, options.variables)) {
|
|
220
|
+
currentResult = {
|
|
120
221
|
data,
|
|
121
222
|
dataState: diff.complete ? "complete" : "partial",
|
|
122
|
-
complete:
|
|
223
|
+
complete: diff.complete,
|
|
123
224
|
};
|
|
124
225
|
if (diff.missing) {
|
|
125
|
-
|
|
226
|
+
currentResult.missing = diff.missing.missing;
|
|
126
227
|
}
|
|
127
|
-
|
|
128
|
-
|
|
228
|
+
}
|
|
229
|
+
return currentResult;
|
|
230
|
+
}
|
|
231
|
+
const observable = new Observable((observer) => {
|
|
232
|
+
subscribed = true;
|
|
233
|
+
const cleanup = this.watch({
|
|
234
|
+
variables,
|
|
235
|
+
returnPartialData: true,
|
|
236
|
+
id,
|
|
237
|
+
query: fragmentQuery,
|
|
238
|
+
optimistic,
|
|
239
|
+
immediate: true,
|
|
240
|
+
callback: (diff) => {
|
|
241
|
+
observable.dirty = true;
|
|
242
|
+
this.onAfterBroadcast(() => {
|
|
243
|
+
observer.next(getNewestResult(diff));
|
|
244
|
+
observable.dirty = false;
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
return () => {
|
|
249
|
+
subscribed = false;
|
|
250
|
+
cleanup();
|
|
251
|
+
this.fragmentWatches.removeArray(cacheKey);
|
|
252
|
+
};
|
|
253
|
+
}).pipe(distinctUntilChanged(), share({
|
|
254
|
+
connector: () => new ReplaySubject(1),
|
|
255
|
+
// debounce so a synchronous unsubscribe+resubscribe doesn't tear down the watch and create a new one
|
|
256
|
+
resetOnRefCountZero: () => timer(0),
|
|
257
|
+
}));
|
|
258
|
+
cacheEntry.observable = Object.assign(observable, {
|
|
259
|
+
dirty: false,
|
|
260
|
+
getCurrentResult: () => {
|
|
261
|
+
if (subscribed && currentResult) {
|
|
262
|
+
return currentResult;
|
|
263
|
+
}
|
|
264
|
+
return getNewestResult(this.diff({
|
|
265
|
+
id,
|
|
266
|
+
query: fragmentQuery,
|
|
267
|
+
returnPartialData: true,
|
|
268
|
+
optimistic,
|
|
269
|
+
variables,
|
|
270
|
+
}));
|
|
129
271
|
},
|
|
130
272
|
});
|
|
131
|
-
}
|
|
273
|
+
}
|
|
274
|
+
return cacheEntry.observable;
|
|
132
275
|
}
|
|
133
276
|
// Make sure we compute the same (===) fragment query document every
|
|
134
277
|
// time we receive the same fragment in readFragment.
|
|
@@ -138,10 +281,11 @@ export class ApolloCache {
|
|
|
138
281
|
cache: WeakCache,
|
|
139
282
|
});
|
|
140
283
|
readFragment(options, optimistic = !!options.optimistic) {
|
|
284
|
+
const id = options.from !== undefined ? this.toCacheId(options.from) : options.id;
|
|
141
285
|
return this.read({
|
|
142
286
|
...options,
|
|
143
287
|
query: this.getFragmentDoc(options.fragment, options.fragmentName),
|
|
144
|
-
rootId:
|
|
288
|
+
rootId: id,
|
|
145
289
|
optimistic,
|
|
146
290
|
});
|
|
147
291
|
}
|
|
@@ -151,7 +295,8 @@ export class ApolloCache {
|
|
|
151
295
|
result: data,
|
|
152
296
|
}));
|
|
153
297
|
}
|
|
154
|
-
writeFragment({
|
|
298
|
+
writeFragment({ data, fragment, fragmentName, ...options }) {
|
|
299
|
+
const id = options.from !== undefined ? this.toCacheId(options.from) : options.id;
|
|
155
300
|
return this.write(Object.assign(options, {
|
|
156
301
|
query: this.getFragmentDoc(fragment, fragmentName),
|
|
157
302
|
dataId: id,
|
|
@@ -182,8 +327,27 @@ export class ApolloCache {
|
|
|
182
327
|
},
|
|
183
328
|
});
|
|
184
329
|
}
|
|
330
|
+
toCacheId(from) {
|
|
331
|
+
return typeof from === "string" ? from : this.identify(from);
|
|
332
|
+
}
|
|
185
333
|
}
|
|
186
334
|
if (__DEV__) {
|
|
187
335
|
ApolloCache.prototype.getMemoryInternals = getApolloCacheMemoryInternals;
|
|
188
336
|
}
|
|
337
|
+
const nullResult = Object.freeze({
|
|
338
|
+
data: null,
|
|
339
|
+
dataState: "complete",
|
|
340
|
+
complete: true,
|
|
341
|
+
});
|
|
342
|
+
const nullObservable = Object.assign(new Observable((observer) => {
|
|
343
|
+
observer.next(nullResult);
|
|
344
|
+
}), { dirty: false, getCurrentResult: () => nullResult });
|
|
345
|
+
const emptyArrayResult = Object.freeze({
|
|
346
|
+
data: [],
|
|
347
|
+
dataState: "complete",
|
|
348
|
+
complete: true,
|
|
349
|
+
});
|
|
350
|
+
const emptyArrayObservable = Object.assign(new Observable((observer) => {
|
|
351
|
+
observer.next(emptyArrayResult);
|
|
352
|
+
}), { getCurrentResult: () => emptyArrayResult });
|
|
189
353
|
//# sourceMappingURL=cache.js.map
|