@apollo/client 4.0.11 → 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 +204 -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 +143 -17
- package/__cjs/core/ObservableQuery.cjs +162 -128
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +1 -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 +46 -24
- 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 +78 -62
- 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 +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 +2 -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 +1 -4
- 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 +4 -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 +17 -1
- package/__cjs/utilities/internal/constants.cjs.map +1 -1
- package/__cjs/utilities/internal/constants.d.cts +16 -0
- package/__cjs/utilities/internal/getStoreKeyName.cjs +1 -0
- package/__cjs/utilities/internal/getStoreKeyName.cjs.map +1 -1
- package/__cjs/utilities/internal/index.cjs +8 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +4 -1
- 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 +143 -17
- package/core/ApolloClient.js +32 -50
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +1 -0
- package/core/ObservableQuery.js +165 -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 +47 -25
- 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 +78 -62
- 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 +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 +2 -0
- 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 +1 -4
- 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 +4 -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 +2 -0
- 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 +44 -56
- 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 +4 -8
- 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 +16 -0
- package/utilities/internal/constants.js +16 -0
- package/utilities/internal/constants.js.map +1 -1
- package/utilities/internal/getStoreKeyName.js +1 -0
- package/utilities/internal/getStoreKeyName.js.map +1 -1
- package/utilities/internal/index.d.ts +4 -1
- package/utilities/internal/index.js +3 -1
- 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
package/core/ObservableQuery.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { equal } from "@wry/equality";
|
|
2
|
-
import { BehaviorSubject, Observable, share, Subject, tap } from "rxjs";
|
|
3
|
-
import { isNetworkRequestInFlight } from "@apollo/client/utilities";
|
|
2
|
+
import { BehaviorSubject, filter, Observable, share, Subject, tap } from "rxjs";
|
|
3
|
+
import { isNetworkRequestInFlight, isNetworkRequestSettled, } from "@apollo/client/utilities";
|
|
4
4
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
5
|
-
import { compact, equalByQuery, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
|
|
5
|
+
import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
|
|
6
6
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
7
7
|
import { NetworkStatus } from "./networkStatus.js";
|
|
8
8
|
const { assign, hasOwnProperty } = Object;
|
|
@@ -61,6 +61,9 @@ export class ObservableQuery {
|
|
|
61
61
|
get networkStatus() {
|
|
62
62
|
return this.subject.getValue().result.networkStatus;
|
|
63
63
|
}
|
|
64
|
+
get cache() {
|
|
65
|
+
return this.queryManager.cache;
|
|
66
|
+
}
|
|
64
67
|
constructor({ queryManager, options, transformedQuery = queryManager.transform(options.query), }) {
|
|
65
68
|
this.queryManager = queryManager;
|
|
66
69
|
// active state
|
|
@@ -73,7 +76,7 @@ export class ObservableQuery {
|
|
|
73
76
|
// Make sure we don't store "standby" as the initialFetchPolicy.
|
|
74
77
|
initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
|
|
75
78
|
if (options[variablesUnknownSymbol]) {
|
|
76
|
-
invariant(fetchPolicy === "standby",
|
|
79
|
+
invariant(fetchPolicy === "standby", 80);
|
|
77
80
|
this.variablesUnknown = true;
|
|
78
81
|
}
|
|
79
82
|
this.lastQuery = transformedQuery;
|
|
@@ -202,7 +205,7 @@ export class ObservableQuery {
|
|
|
202
205
|
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
203
206
|
*/
|
|
204
207
|
getCacheDiff({ optimistic = true } = {}) {
|
|
205
|
-
return this.
|
|
208
|
+
return this.cache.diff({
|
|
206
209
|
query: this.query,
|
|
207
210
|
variables: this.variables,
|
|
208
211
|
returnPartialData: true,
|
|
@@ -313,7 +316,7 @@ export class ObservableQuery {
|
|
|
313
316
|
}
|
|
314
317
|
},
|
|
315
318
|
};
|
|
316
|
-
const cancelWatch = this.
|
|
319
|
+
const cancelWatch = this.cache.watch(watch);
|
|
317
320
|
this.unsubscribeFromCache = Object.assign(() => {
|
|
318
321
|
this.unsubscribeFromCache = undefined;
|
|
319
322
|
cancelWatch();
|
|
@@ -377,7 +380,7 @@ export class ObservableQuery {
|
|
|
377
380
|
const queryDef = getQueryDefinition(this.query);
|
|
378
381
|
const vars = queryDef.variableDefinitions;
|
|
379
382
|
if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
|
|
380
|
-
__DEV__ && invariant.warn(
|
|
383
|
+
__DEV__ && invariant.warn(81, variables, queryDef.name?.value || queryDef);
|
|
381
384
|
}
|
|
382
385
|
}
|
|
383
386
|
if (variables && !equal(this.variables, variables)) {
|
|
@@ -393,7 +396,7 @@ export class ObservableQuery {
|
|
|
393
396
|
fetchMore({ query, variables, context, errorPolicy, updateQuery, }) {
|
|
394
397
|
invariant(
|
|
395
398
|
this.options.fetchPolicy !== "cache-only",
|
|
396
|
-
|
|
399
|
+
82,
|
|
397
400
|
getOperationName(this.query, "(anonymous)")
|
|
398
401
|
);
|
|
399
402
|
const combinedOptions = {
|
|
@@ -427,7 +430,7 @@ export class ObservableQuery {
|
|
|
427
430
|
let wasUpdated = false;
|
|
428
431
|
const isCached = this.options.fetchPolicy !== "no-cache";
|
|
429
432
|
if (!isCached) {
|
|
430
|
-
invariant(updateQuery,
|
|
433
|
+
invariant(updateQuery, 83);
|
|
431
434
|
}
|
|
432
435
|
const { finalize, pushNotification } = this.pushOperation(NetworkStatus.fetchMore);
|
|
433
436
|
pushNotification({
|
|
@@ -435,109 +438,149 @@ export class ObservableQuery {
|
|
|
435
438
|
kind: "N",
|
|
436
439
|
value: {},
|
|
437
440
|
}, { shouldEmit: 3 /* EmitBehavior.networkStatusChange */ });
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
441
|
+
const { promise, operator } = getTrackingOperatorPromise();
|
|
442
|
+
const { observable } = this.queryManager.fetchObservableWithInfo(combinedOptions, { networkStatus: NetworkStatus.fetchMore, exposeExtensions: true });
|
|
443
|
+
const subscription = observable
|
|
444
|
+
.pipe(operator, filter((notification) => notification.kind === "N" && notification.source === "network"))
|
|
445
|
+
.subscribe({
|
|
446
|
+
next: (notification) => {
|
|
447
|
+
wasUpdated = false;
|
|
448
|
+
const fetchMoreResult = notification.value;
|
|
449
|
+
const extensions = fetchMoreResult[extensionsSymbol];
|
|
450
|
+
if (isNetworkRequestSettled(notification.value.networkStatus)) {
|
|
451
|
+
finalize();
|
|
452
|
+
}
|
|
453
|
+
if (isCached) {
|
|
454
|
+
// Separately getting a diff here before the batch - `onWatchUpdated` might be
|
|
455
|
+
// called with an `undefined` `lastDiff` on the watcher if the cache was just subscribed to.
|
|
456
|
+
const lastDiff = this.getCacheDiff();
|
|
457
|
+
// Performing this cache update inside a cache.batch transaction ensures
|
|
458
|
+
// any affected cache.watch watchers are notified at most once about any
|
|
459
|
+
// updates. Most watchers will be using the QueryInfo class, which
|
|
460
|
+
// responds to notifications by calling reobserveCacheFirst to deliver
|
|
461
|
+
// fetchMore cache results back to this ObservableQuery.
|
|
462
|
+
this.cache.batch({
|
|
463
|
+
update: (cache) => {
|
|
464
|
+
if (updateQuery) {
|
|
465
|
+
cache.updateQuery({
|
|
466
|
+
query: this.query,
|
|
467
|
+
variables: this.variables,
|
|
468
|
+
returnPartialData: true,
|
|
469
|
+
optimistic: false,
|
|
470
|
+
extensions,
|
|
471
|
+
}, (previous) => updateQuery(previous, {
|
|
472
|
+
fetchMoreResult: fetchMoreResult.data,
|
|
473
|
+
variables: combinedOptions.variables,
|
|
474
|
+
}));
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
// If we're using a field policy instead of updateQuery, the only
|
|
478
|
+
// thing we need to do is write the new data to the cache using
|
|
479
|
+
// combinedOptions.variables (instead of this.variables, which is
|
|
480
|
+
// what this.updateQuery uses, because it works by abusing the
|
|
481
|
+
// original field value, keyed by the original variables).
|
|
482
|
+
cache.writeQuery({
|
|
483
|
+
query: combinedOptions.query,
|
|
484
|
+
variables: combinedOptions.variables,
|
|
485
|
+
data: fetchMoreResult.data,
|
|
486
|
+
extensions,
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
onWatchUpdated: (watch, diff) => {
|
|
491
|
+
if (watch.watcher === this &&
|
|
492
|
+
!equal(diff.result, lastDiff.result)) {
|
|
493
|
+
wasUpdated = true;
|
|
494
|
+
const lastResult = this.getCurrentResult();
|
|
495
|
+
// Let the cache watch from resubscribeCache handle the final
|
|
496
|
+
// result
|
|
497
|
+
if (isNetworkRequestInFlight(fetchMoreResult.networkStatus)) {
|
|
498
|
+
pushNotification({
|
|
499
|
+
kind: "N",
|
|
500
|
+
source: "network",
|
|
501
|
+
value: {
|
|
502
|
+
...lastResult,
|
|
503
|
+
networkStatus: (fetchMoreResult.networkStatus ===
|
|
504
|
+
NetworkStatus.error) ?
|
|
505
|
+
NetworkStatus.ready
|
|
506
|
+
: fetchMoreResult.networkStatus,
|
|
507
|
+
// will be overwritten anyways, just here for types sake
|
|
508
|
+
loading: false,
|
|
509
|
+
data: diff.result,
|
|
510
|
+
dataState: fetchMoreResult.dataState === "streaming" ?
|
|
511
|
+
"streaming"
|
|
512
|
+
: "complete",
|
|
513
|
+
},
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
},
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
// There is a possibility `lastResult` may not be set when
|
|
522
|
+
// `fetchMore` is called which would cause this to crash. This should
|
|
523
|
+
// only happen if we haven't previously reported a result. We don't
|
|
524
|
+
// quite know what the right behavior should be here since this block
|
|
525
|
+
// of code runs after the fetch result has executed on the network.
|
|
526
|
+
// We plan to let it crash in the meantime.
|
|
527
|
+
//
|
|
528
|
+
// If we get bug reports due to the `data` property access on
|
|
529
|
+
// undefined, this should give us a real-world scenario that we can
|
|
530
|
+
// use to test against and determine the right behavior. If we do end
|
|
531
|
+
// up changing this behavior, this may require, for example, an
|
|
532
|
+
// adjustment to the types on `updateQuery` since that function
|
|
533
|
+
// expects that the first argument always contains previous result
|
|
534
|
+
// data, but not `undefined`.
|
|
535
|
+
const lastResult = this.getCurrentResult();
|
|
536
|
+
const data = updateQuery(lastResult.data, {
|
|
537
|
+
fetchMoreResult: fetchMoreResult.data,
|
|
538
|
+
variables: combinedOptions.variables,
|
|
539
|
+
});
|
|
540
|
+
pushNotification({
|
|
541
|
+
kind: "N",
|
|
542
|
+
value: {
|
|
543
|
+
...lastResult,
|
|
544
|
+
networkStatus: NetworkStatus.ready,
|
|
545
|
+
// will be overwritten anyways, just here for types sake
|
|
546
|
+
loading: false,
|
|
547
|
+
data: data,
|
|
548
|
+
dataState: lastResult.dataState === "streaming" ?
|
|
549
|
+
"streaming"
|
|
550
|
+
: "complete",
|
|
551
|
+
},
|
|
552
|
+
source: "network",
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
return preventUnhandledRejection(promise
|
|
558
|
+
.then((result) => toQueryResult(this.maskResult(result)))
|
|
525
559
|
.finally(() => {
|
|
526
|
-
|
|
560
|
+
subscription.unsubscribe();
|
|
527
561
|
finalize();
|
|
528
|
-
// In case the cache writes above did not generate a broadcast
|
|
529
|
-
// notification (which would have been intercepted by onWatchUpdated),
|
|
530
|
-
// likely because the written data were the same as what was already in
|
|
531
|
-
// the cache, we still want fetchMore to deliver its final loading:false
|
|
532
|
-
// result with the unchanged data.
|
|
533
562
|
if (isCached && !wasUpdated) {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
563
|
+
const lastResult = this.getCurrentResult();
|
|
564
|
+
if (lastResult.dataState === "streaming") {
|
|
565
|
+
pushNotification({
|
|
566
|
+
kind: "N",
|
|
567
|
+
source: "network",
|
|
568
|
+
value: {
|
|
569
|
+
...lastResult,
|
|
570
|
+
dataState: "complete",
|
|
571
|
+
networkStatus: NetworkStatus.ready,
|
|
572
|
+
},
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
pushNotification({
|
|
577
|
+
kind: "N",
|
|
578
|
+
source: "newNetworkStatus",
|
|
579
|
+
value: {},
|
|
580
|
+
}, { shouldEmit: 1 /* EmitBehavior.force */ });
|
|
581
|
+
}
|
|
539
582
|
}
|
|
540
|
-
});
|
|
583
|
+
}));
|
|
541
584
|
}
|
|
542
585
|
// XXX the subscription variables are separate from the query variables.
|
|
543
586
|
// if you want to update subscription variables, right now you have to do that separately,
|
|
@@ -563,7 +606,7 @@ export class ObservableQuery {
|
|
|
563
606
|
onError(error);
|
|
564
607
|
}
|
|
565
608
|
else {
|
|
566
|
-
invariant.error(
|
|
609
|
+
invariant.error(84, error);
|
|
567
610
|
}
|
|
568
611
|
return;
|
|
569
612
|
}
|
|
@@ -641,7 +684,7 @@ export class ObservableQuery {
|
|
|
641
684
|
previousData: result,
|
|
642
685
|
});
|
|
643
686
|
if (newResult) {
|
|
644
|
-
|
|
687
|
+
this.cache.writeQuery({
|
|
645
688
|
query: this.options.query,
|
|
646
689
|
data: newResult,
|
|
647
690
|
variables: this.variables,
|
|
@@ -807,7 +850,7 @@ export class ObservableQuery {
|
|
|
807
850
|
if (!this.didWarnCacheOnlyPolling &&
|
|
808
851
|
pollInterval &&
|
|
809
852
|
fetchPolicy === "cache-only") {
|
|
810
|
-
__DEV__ && invariant.warn(
|
|
853
|
+
__DEV__ && invariant.warn(85, getOperationName(this.query, "(anonymous)"));
|
|
811
854
|
this.didWarnCacheOnlyPolling = true;
|
|
812
855
|
}
|
|
813
856
|
}
|
|
@@ -948,15 +991,7 @@ export class ObservableQuery {
|
|
|
948
991
|
this.cancelPolling();
|
|
949
992
|
}
|
|
950
993
|
this.resubscribeCache();
|
|
951
|
-
const { promise, operator: promiseOperator } = getTrackingOperatorPromise(
|
|
952
|
-
switch (value.kind) {
|
|
953
|
-
case "E":
|
|
954
|
-
throw value.error;
|
|
955
|
-
case "N":
|
|
956
|
-
if (value.source !== "newNetworkStatus" && !value.value.loading)
|
|
957
|
-
return value.value;
|
|
958
|
-
}
|
|
959
|
-
},
|
|
994
|
+
const { promise, operator: promiseOperator } = getTrackingOperatorPromise(
|
|
960
995
|
// This default value should only be used when using a `fetchPolicy` of
|
|
961
996
|
// `standby` since that fetch policy completes without emitting a
|
|
962
997
|
// result. Since we are converting this to a QueryResult type, we
|
|
@@ -1078,8 +1113,8 @@ export class ObservableQuery {
|
|
|
1078
1113
|
const { dirty } = this;
|
|
1079
1114
|
this.resetNotifications();
|
|
1080
1115
|
if (dirty &&
|
|
1081
|
-
(this.options.fetchPolicy
|
|
1082
|
-
this.options.fetchPolicy
|
|
1116
|
+
(this.options.fetchPolicy === "cache-only" ||
|
|
1117
|
+
this.options.fetchPolicy === "cache-and-network" ||
|
|
1083
1118
|
!this.activeOperations.size)) {
|
|
1084
1119
|
const diff = this.getCacheDiff();
|
|
1085
1120
|
if (
|
|
@@ -1309,13 +1344,13 @@ export class ObservableQuery {
|
|
|
1309
1344
|
}
|
|
1310
1345
|
export function logMissingFieldErrors(missing) {
|
|
1311
1346
|
if (__DEV__ && missing) {
|
|
1312
|
-
__DEV__ && invariant.debug(
|
|
1347
|
+
__DEV__ && invariant.debug(86, missing);
|
|
1313
1348
|
}
|
|
1314
1349
|
}
|
|
1315
1350
|
function isEqualQuery(a, b) {
|
|
1316
1351
|
return !!(a && b && a.query === b.query && equal(a.variables, b.variables));
|
|
1317
1352
|
}
|
|
1318
|
-
function getTrackingOperatorPromise(
|
|
1353
|
+
function getTrackingOperatorPromise(defaultValue) {
|
|
1319
1354
|
let lastValue = defaultValue, resolve, reject;
|
|
1320
1355
|
const promise = new Promise((res, rej) => {
|
|
1321
1356
|
resolve = res;
|
|
@@ -1323,14 +1358,13 @@ function getTrackingOperatorPromise(filterMapCb, defaultValue) {
|
|
|
1323
1358
|
});
|
|
1324
1359
|
const operator = tap({
|
|
1325
1360
|
next(value) {
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
if (newValue !== undefined) {
|
|
1329
|
-
lastValue = newValue;
|
|
1330
|
-
}
|
|
1361
|
+
if (value.kind === "E") {
|
|
1362
|
+
return reject(value.error);
|
|
1331
1363
|
}
|
|
1332
|
-
|
|
1333
|
-
|
|
1364
|
+
if (value.kind === "N" &&
|
|
1365
|
+
value.source !== "newNetworkStatus" &&
|
|
1366
|
+
!value.value.loading) {
|
|
1367
|
+
lastValue = value.value;
|
|
1334
1368
|
}
|
|
1335
1369
|
},
|
|
1336
1370
|
finalize: () => {
|