@apollo/client 4.1.0-alpha.2 → 4.1.0-alpha.4
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 +94 -0
- package/__cjs/cache/core/cache.cjs +148 -50
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +72 -23
- package/__cjs/cache/core/types/common.cjs.map +1 -1
- package/__cjs/cache/core/types/common.d.cts +1 -1
- package/__cjs/cache/inmemory/fragmentRegistry.cjs +1 -1
- package/__cjs/cache/inmemory/fragmentRegistry.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +12 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/core/ApolloClient.cjs +24 -27
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +94 -5
- package/__cjs/core/ObservableQuery.cjs +8 -4
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +2 -2
- package/__cjs/core/QueryManager.cjs +1 -1
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/dev/setErrorMessageHandler.cjs.map +1 -1
- package/__cjs/dev/setErrorMessageHandler.d.cts +1 -1
- package/__cjs/incremental/handlers/defer20220824.cjs +6 -2
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +0 -2
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +9 -3
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
- package/__cjs/link/schema/index.cjs +1 -1
- package/__cjs/link/schema/index.cjs.map +1 -1
- package/__cjs/link/schema/index.d.cts +1 -1
- package/__cjs/link/subscriptions/index.cjs +2 -1
- package/__cjs/link/subscriptions/index.cjs.map +1 -1
- package/__cjs/masking/maskDefinition.cjs +1 -1
- package/__cjs/masking/maskDefinition.cjs.map +1 -1
- package/__cjs/masking/types.d.cts +2 -1
- package/__cjs/react/hooks/internal/index.cjs +3 -1
- package/__cjs/react/hooks/internal/index.cjs.map +1 -1
- package/__cjs/react/hooks/internal/index.d.cts +1 -0
- package/__cjs/react/hooks/internal/useDeepMemo.cjs +2 -0
- package/__cjs/react/hooks/internal/useDeepMemo.cjs.map +1 -1
- package/__cjs/react/hooks/internal/useRenderGuard.cjs +1 -1
- package/__cjs/react/hooks/internal/useRenderGuard.cjs.map +1 -1
- package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.cjs +28 -0
- package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.cjs.map +1 -0
- package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.d.cts +11 -0
- package/__cjs/react/hooks/useBackgroundQuery.cjs +3 -11
- 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/useLazyQuery.d.cts +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +3 -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 +2 -2
- package/__cjs/react/hooks/useQueryRefHandlers.cjs +1 -3
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useReactiveVar.cjs +2 -1
- package/__cjs/react/hooks/useReactiveVar.cjs.map +1 -1
- package/__cjs/react/hooks/useReactiveVar.d.cts +2 -1
- package/__cjs/react/hooks/useReadQuery.cjs +1 -3
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.d.cts +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 -12
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +1 -1
- package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
- package/__cjs/react/hooks/useSyncExternalStore.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 +1 -1
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +4 -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/ssr/useSSRQuery.cjs +1 -0
- package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
- package/__cjs/react/types/types.documentation.d.cts +4 -16
- package/__cjs/testing/core/mocking/mockLink.cjs +2 -2
- package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockLink.d.cts +3 -1
- package/__cjs/utilities/DeepPartial.cjs.map +1 -1
- package/__cjs/utilities/DeepPartial.d.cts +1 -1
- 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/getMemoryInternals.cjs.map +1 -1
- package/__cjs/utilities/internal/index.cjs +4 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +1 -0
- package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +72 -23
- package/cache/core/cache.js +151 -53
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/common.d.ts +1 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/fragmentRegistry.js +1 -1
- package/cache/inmemory/fragmentRegistry.js.map +1 -1
- package/cache/inmemory/inMemoryCache.js +12 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/core/ApolloClient.d.ts +94 -5
- package/core/ApolloClient.js +24 -27
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +2 -2
- package/core/ObservableQuery.js +8 -4
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.js +1 -1
- package/core/QueryManager.js.map +1 -1
- package/dev/setErrorMessageHandler.d.ts +1 -1
- package/dev/setErrorMessageHandler.js.map +1 -1
- package/incremental/handlers/defer20220824.d.ts +0 -2
- package/incremental/handlers/defer20220824.js +6 -2
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.js +9 -3
- package/incremental/handlers/graphql17Alpha9.js.map +1 -1
- package/link/schema/index.d.ts +1 -1
- package/link/schema/index.js +1 -1
- package/link/schema/index.js.map +1 -1
- package/link/subscriptions/index.js +2 -1
- package/link/subscriptions/index.js.map +1 -1
- package/masking/internal/types.js.map +1 -1
- package/masking/maskDefinition.js +1 -1
- package/masking/maskDefinition.js.map +1 -1
- package/masking/types.d.ts +2 -1
- package/masking/types.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/internal/index.d.ts +1 -0
- package/react/hooks/internal/index.js +1 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useDeepMemo.js +2 -0
- package/react/hooks/internal/useDeepMemo.js.map +1 -1
- package/react/hooks/internal/useRenderGuard.js +1 -1
- package/react/hooks/internal/useRenderGuard.js.map +1 -1
- package/react/hooks/internal/useSuspenseHookCacheKey.d.ts +11 -0
- package/react/hooks/internal/useSuspenseHookCacheKey.js +24 -0
- package/react/hooks/internal/useSuspenseHookCacheKey.js.map +1 -0
- package/react/hooks/useBackgroundQuery.js +4 -12
- 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.d.ts +1 -1
- package/react/hooks/useLazyQuery.js +2 -0
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +3 -1
- package/react/hooks/useQuery.d.ts +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/useReactiveVar.d.ts +2 -1
- package/react/hooks/useReactiveVar.js +2 -1
- package/react/hooks/useReactiveVar.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +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.d.ts +1 -1
- package/react/hooks/useSuspenseQuery.js +7 -13
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/hooks/useSyncExternalStore.js.map +1 -1
- package/react/hooks-compiled/internal/index.d.ts +1 -0
- package/react/hooks-compiled/internal/index.js +1 -0
- package/react/hooks-compiled/internal/index.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/useRenderGuard.js +1 -1
- package/react/hooks-compiled/internal/useRenderGuard.js.map +1 -1
- package/react/hooks-compiled/internal/useSuspenseHookCacheKey.d.ts +11 -0
- package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js +71 -0
- package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js.map +1 -0
- package/react/hooks-compiled/useBackgroundQuery.js +6 -14
- 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.d.ts +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 +3 -1
- package/react/hooks-compiled/useMutation.js +0 -12
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +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/useReactiveVar.d.ts +2 -1
- package/react/hooks-compiled/useReactiveVar.js +2 -1
- package/react/hooks-compiled/useReactiveVar.js.map +1 -1
- package/react/hooks-compiled/useReadQuery.d.ts +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.d.ts +1 -1
- package/react/hooks-compiled/useSuspenseQuery.js +9 -19
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js +1 -1
- package/react/hooks-compiled/useSyncExternalStore.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 +4 -0
- package/react/internal/cache/QueryReference.js +1 -1
- 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/ssr/useSSRQuery.js +1 -0
- package/react/ssr/useSSRQuery.js.map +1 -1
- package/react/types/types.documentation.d.ts +4 -16
- package/react/types/types.documentation.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +3 -1
- package/testing/core/mocking/mockLink.js +2 -2
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/utilities/DeepPartial.d.ts +1 -1
- package/utilities/DeepPartial.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/getMemoryInternals.js.map +1 -1
- package/utilities/internal/globals/global.js +2 -2
- package/utilities/internal/globals/global.js.map +1 -1
- package/utilities/internal/index.d.ts +1 -0
- package/utilities/internal/index.js +1 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/types/DocumentationTypes.d.ts +1 -1
- package/version.js +1 -1
|
@@ -214,7 +214,9 @@ export declare namespace ApolloClient {
|
|
|
214
214
|
} & VariablesOption<NoInfer<TVariables>>;
|
|
215
215
|
interface MutateResult<TData = unknown> {
|
|
216
216
|
/**
|
|
217
|
-
* The data returned from your mutation. Can be `undefined` if `
|
|
217
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
218
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
219
|
+
* but not `data` or a network error is returned.
|
|
218
220
|
*/
|
|
219
221
|
data: TData | undefined;
|
|
220
222
|
/**
|
|
@@ -275,7 +277,7 @@ export declare namespace ApolloClient {
|
|
|
275
277
|
*/
|
|
276
278
|
data: TData | undefined;
|
|
277
279
|
/**
|
|
278
|
-
* A single ErrorLike object describing the error that
|
|
280
|
+
* A single ErrorLike object describing the error that occurred during the latest
|
|
279
281
|
* query execution.
|
|
280
282
|
*
|
|
281
283
|
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
@@ -365,7 +367,9 @@ export declare namespace ApolloClient {
|
|
|
365
367
|
} & VariablesOption<NoInfer<TVariables>>;
|
|
366
368
|
interface SubscribeResult<TData = unknown> {
|
|
367
369
|
/**
|
|
368
|
-
* The data returned from your mutation. Can be `undefined` if `
|
|
370
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
371
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
372
|
+
* but not `data` or a network error is returned.
|
|
369
373
|
*/
|
|
370
374
|
data: TData | undefined;
|
|
371
375
|
/**
|
|
@@ -380,7 +384,13 @@ export declare namespace ApolloClient {
|
|
|
380
384
|
extensions?: Record<string, unknown>;
|
|
381
385
|
}
|
|
382
386
|
type WatchFragmentOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables> = ApolloCache.WatchFragmentOptions<TData, TVariables>;
|
|
383
|
-
type WatchFragmentResult<TData = unknown> = ApolloCache.WatchFragmentResult<TData
|
|
387
|
+
type WatchFragmentResult<TData = unknown> = ApolloCache.WatchFragmentResult<MaybeMasked<TData>>;
|
|
388
|
+
interface ObservableFragment<TData = unknown> extends Observable<ApolloClient.WatchFragmentResult<TData>> {
|
|
389
|
+
/**
|
|
390
|
+
* Return the current result for the fragment.
|
|
391
|
+
*/
|
|
392
|
+
getCurrentResult: () => ApolloClient.WatchFragmentResult<TData>;
|
|
393
|
+
}
|
|
384
394
|
/**
|
|
385
395
|
* Watched query options.
|
|
386
396
|
*/
|
|
@@ -819,7 +829,86 @@ export declare class ApolloClient {
|
|
|
819
829
|
* the cache to identify the fragment and optionally specify whether to react
|
|
820
830
|
* to optimistic updates.
|
|
821
831
|
*/
|
|
822
|
-
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables>
|
|
832
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
|
|
833
|
+
from: Array<NonNullable<ApolloCache.WatchFragmentFromValue<TData>>>;
|
|
834
|
+
}): ApolloClient.ObservableFragment<Array<TData>>;
|
|
835
|
+
/**
|
|
836
|
+
* Watches the cache store of the fragment according to the options specified
|
|
837
|
+
* and returns an `Observable`. We can subscribe to this
|
|
838
|
+
* `Observable` and receive updated results through an
|
|
839
|
+
* observer when the cache store changes.
|
|
840
|
+
*
|
|
841
|
+
* You must pass in a GraphQL document with a single fragment or a document
|
|
842
|
+
* with multiple fragments that represent what you are reading. If you pass
|
|
843
|
+
* in a document with multiple fragments then you must also specify a
|
|
844
|
+
* `fragmentName`.
|
|
845
|
+
*
|
|
846
|
+
* @since 3.10.0
|
|
847
|
+
* @param options - An object of type `WatchFragmentOptions` that allows
|
|
848
|
+
* the cache to identify the fragment and optionally specify whether to react
|
|
849
|
+
* to optimistic updates.
|
|
850
|
+
*/
|
|
851
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
|
|
852
|
+
from: Array<null>;
|
|
853
|
+
}): ApolloClient.ObservableFragment<Array<null>>;
|
|
854
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
|
|
855
|
+
from: Array<ApolloCache.WatchFragmentFromValue<TData>>;
|
|
856
|
+
}): ApolloClient.ObservableFragment<Array<TData | null>>;
|
|
857
|
+
/**
|
|
858
|
+
* Watches the cache store of the fragment according to the options specified
|
|
859
|
+
* and returns an `Observable`. We can subscribe to this
|
|
860
|
+
* `Observable` and receive updated results through an
|
|
861
|
+
* observer when the cache store changes.
|
|
862
|
+
*
|
|
863
|
+
* You must pass in a GraphQL document with a single fragment or a document
|
|
864
|
+
* with multiple fragments that represent what you are reading. If you pass
|
|
865
|
+
* in a document with multiple fragments then you must also specify a
|
|
866
|
+
* `fragmentName`.
|
|
867
|
+
*
|
|
868
|
+
* @since 3.10.0
|
|
869
|
+
* @param options - An object of type `WatchFragmentOptions` that allows
|
|
870
|
+
* the cache to identify the fragment and optionally specify whether to react
|
|
871
|
+
* to optimistic updates.
|
|
872
|
+
*/
|
|
873
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
|
|
874
|
+
from: null;
|
|
875
|
+
}): ApolloClient.ObservableFragment<null>;
|
|
876
|
+
/**
|
|
877
|
+
* Watches the cache store of the fragment according to the options specified
|
|
878
|
+
* and returns an `Observable`. We can subscribe to this
|
|
879
|
+
* `Observable` and receive updated results through an
|
|
880
|
+
* observer when the cache store changes.
|
|
881
|
+
*
|
|
882
|
+
* You must pass in a GraphQL document with a single fragment or a document
|
|
883
|
+
* with multiple fragments that represent what you are reading. If you pass
|
|
884
|
+
* in a document with multiple fragments then you must also specify a
|
|
885
|
+
* `fragmentName`.
|
|
886
|
+
*
|
|
887
|
+
* @since 3.10.0
|
|
888
|
+
* @param options - An object of type `WatchFragmentOptions` that allows
|
|
889
|
+
* the cache to identify the fragment and optionally specify whether to react
|
|
890
|
+
* to optimistic updates.
|
|
891
|
+
*/
|
|
892
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables> & {
|
|
893
|
+
from: NonNullable<ApolloCache.WatchFragmentFromValue<TData>>;
|
|
894
|
+
}): ApolloClient.ObservableFragment<TData>;
|
|
895
|
+
/**
|
|
896
|
+
* Watches the cache store of the fragment according to the options specified
|
|
897
|
+
* and returns an `Observable`. We can subscribe to this
|
|
898
|
+
* `Observable` and receive updated results through an
|
|
899
|
+
* observer when the cache store changes.
|
|
900
|
+
*
|
|
901
|
+
* You must pass in a GraphQL document with a single fragment or a document
|
|
902
|
+
* with multiple fragments that represent what you are reading. If you pass
|
|
903
|
+
* in a document with multiple fragments then you must also specify a
|
|
904
|
+
* `fragmentName`.
|
|
905
|
+
*
|
|
906
|
+
* @since 3.10.0
|
|
907
|
+
* @param options - An object of type `WatchFragmentOptions` that allows
|
|
908
|
+
* the cache to identify the fragment and optionally specify whether to react
|
|
909
|
+
* to optimistic updates.
|
|
910
|
+
*/
|
|
911
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloClient.WatchFragmentOptions<TData, TVariables>): ApolloClient.ObservableFragment<TData | null>;
|
|
823
912
|
/**
|
|
824
913
|
* Tries to read some data from the store in the shape of the provided
|
|
825
914
|
* GraphQL fragment without making a network request. This method will read a
|
|
@@ -284,7 +284,7 @@ class ObservableQuery {
|
|
|
284
284
|
// not be notified about future cache changes with an equal `diff`.
|
|
285
285
|
// That would be the case if we are working with client-only fields
|
|
286
286
|
// that are forced or with `exports` fields that might change, causing
|
|
287
|
-
// local
|
|
287
|
+
// local resolvers to return a new result.
|
|
288
288
|
// This is based on an implementation detail of `InMemoryCache`, which
|
|
289
289
|
// is not optimal - but the only alternative to this would be to
|
|
290
290
|
// resubscribe to the cache asynchonouly, which would bear the risk of
|
|
@@ -464,6 +464,9 @@ class ObservableQuery {
|
|
|
464
464
|
finalize();
|
|
465
465
|
}
|
|
466
466
|
if (isCached) {
|
|
467
|
+
// Separately getting a diff here before the batch - `onWatchUpdated` might be
|
|
468
|
+
// called with an `undefined` `lastDiff` on the watcher if the cache was just subscribed to.
|
|
469
|
+
const lastDiff = this.getCacheDiff();
|
|
467
470
|
// Performing this cache update inside a cache.batch transaction ensures
|
|
468
471
|
// any affected cache.watch watchers are notified at most once about any
|
|
469
472
|
// updates. Most watchers will be using the QueryInfo class, which
|
|
@@ -496,7 +499,8 @@ class ObservableQuery {
|
|
|
496
499
|
}
|
|
497
500
|
},
|
|
498
501
|
onWatchUpdated: (watch, diff) => {
|
|
499
|
-
if (watch.watcher === this
|
|
502
|
+
if (watch.watcher === this &&
|
|
503
|
+
!(0, equality_1.equal)(diff.result, lastDiff.result)) {
|
|
500
504
|
wasUpdated = true;
|
|
501
505
|
const lastResult = this.getCurrentResult();
|
|
502
506
|
// Let the cache watch from resubscribeCache handle the final
|
|
@@ -1021,7 +1025,7 @@ class ObservableQuery {
|
|
|
1021
1025
|
.then((result) => (0, internal_1.toQueryResult)(this.maskResult(result)))
|
|
1022
1026
|
.finally(() => {
|
|
1023
1027
|
if (!this.hasObservers() && this.activeOperations.size === 0) {
|
|
1024
|
-
// If `reobserve` was called on a query without any
|
|
1028
|
+
// If `reobserve` was called on a query without any observers,
|
|
1025
1029
|
// the teardown logic would never be called, so we need to
|
|
1026
1030
|
// call it here to ensure the query is properly torn down.
|
|
1027
1031
|
this.tearDownQuery();
|
|
@@ -1129,7 +1133,7 @@ class ObservableQuery {
|
|
|
1129
1133
|
!this.activeOperations.size)) {
|
|
1130
1134
|
const diff = this.getCacheDiff();
|
|
1131
1135
|
if (
|
|
1132
|
-
// `fromOptimisticTransaction` is not
|
|
1136
|
+
// `fromOptimisticTransaction` is not available through the `cache.diff`
|
|
1133
1137
|
// code path, so we need to check it this way
|
|
1134
1138
|
(0, equality_1.equal)(diff.result, this.getCacheDiff({ optimistic: false }).result)) {
|
|
1135
1139
|
//If this diff did not come from an optimistic transaction
|