@apollo/client 4.1.0-alpha.1 → 4.1.0-alpha.3
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 +83 -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/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 +87 -2
- 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/incremental/handlers/notImplemented.cjs +1 -1
- package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
- package/__cjs/invariantErrorCodes.cjs +2 -2
- package/__cjs/react/hooks/useFragment.cjs +37 -84
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +65 -6
- 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.d.cts +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.cjs +13 -12
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.d.cts +33 -7
- 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/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/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/index.cjs +4 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +1 -0
- 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/inmemory/inMemoryCache.js +12 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/core/ApolloClient.d.ts +87 -2
- package/core/ApolloClient.js +24 -27
- package/core/ApolloClient.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/incremental/handlers/notImplemented.js +1 -1
- package/incremental/handlers/notImplemented.js.map +1 -1
- package/invariantErrorCodes.js +2 -2
- package/package.json +1 -1
- package/react/hooks/useFragment.d.ts +65 -6
- package/react/hooks/useFragment.js +37 -84
- package/react/hooks/useFragment.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/useSuspenseFragment.d.ts +33 -7
- package/react/hooks/useSuspenseFragment.js +14 -13
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks-compiled/useFragment.d.ts +65 -6
- package/react/hooks-compiled/useFragment.js +111 -85
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +13 -1
- package/react/hooks-compiled/useMutation.js +5 -1
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useSuspenseFragment.d.ts +33 -7
- package/react/hooks-compiled/useSuspenseFragment.js +14 -13
- package/react/hooks-compiled/useSuspenseFragment.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/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/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/index.d.ts +1 -0
- package/utilities/internal/index.js +1 -0
- package/utilities/internal/index.js.map +1 -1
- package/version.js +1 -1
|
@@ -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.cjs";
|
|
9
9
|
import type { MissingTree } from "./types/common.cjs";
|
|
10
10
|
export type Transaction = (c: ApolloCache) => void;
|
|
11
11
|
export declare namespace ApolloCache {
|
|
12
|
+
/**
|
|
13
|
+
* Acceptable values provided to the `from` option for `watchFragment`.
|
|
14
|
+
*/
|
|
15
|
+
type WatchFragmentFromValue<TData> = StoreObject | Reference | FragmentType<NoInfer<TData>> | string | null;
|
|
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.WatchFragmentFromValue<TData> | Array<ApolloCache.WatchFragmentFromValue<TData>>;
|
|
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;
|
|
@@ -138,23 +180,30 @@ export declare abstract class ApolloCache {
|
|
|
138
180
|
* instead of passing it as a separate option.
|
|
139
181
|
*/
|
|
140
182
|
optimistic: boolean): Unmasked<TData> | null;
|
|
183
|
+
private fragmentWatches;
|
|
184
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
185
|
+
from: Array<NonNullable<ApolloCache.WatchFragmentFromValue<TData>>>;
|
|
186
|
+
}): ApolloCache.ObservableFragment<Array<Unmasked<TData>>>;
|
|
187
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
188
|
+
from: Array<null>;
|
|
189
|
+
}): ApolloCache.ObservableFragment<Array<null>>;
|
|
190
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
191
|
+
from: Array<ApolloCache.WatchFragmentFromValue<TData>>;
|
|
192
|
+
}): ApolloCache.ObservableFragment<Array<Unmasked<TData> | null>>;
|
|
193
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
194
|
+
from: null;
|
|
195
|
+
}): ApolloCache.ObservableFragment<null>;
|
|
196
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
197
|
+
from: NonNullable<ApolloCache.WatchFragmentFromValue<TData>>;
|
|
198
|
+
}): ApolloCache.ObservableFragment<Unmasked<TData>>;
|
|
199
|
+
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables>): ApolloCache.ObservableFragment<Unmasked<TData> | null>;
|
|
141
200
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
* with multiple fragments that represent what you are reading. If you pass
|
|
149
|
-
* in a document with multiple fragments then you must also specify a
|
|
150
|
-
* `fragmentName`.
|
|
151
|
-
*
|
|
152
|
-
* @since 3.10.0
|
|
153
|
-
* @param options - An object of type `WatchFragmentOptions` that allows
|
|
154
|
-
* the cache to identify the fragment and optionally specify whether to react
|
|
155
|
-
* to optimistic updates.
|
|
156
|
-
*/
|
|
157
|
-
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables>): Observable<ApolloCache.WatchFragmentResult<Unmasked<TData>>>;
|
|
201
|
+
* Can be overridden by subclasses to delay calling the provided callback
|
|
202
|
+
* until after all broadcasts have been completed - e.g. in a cache scenario
|
|
203
|
+
* where many watchers are notified in parallel.
|
|
204
|
+
*/
|
|
205
|
+
protected onAfterBroadcast: (cb: () => void) => void;
|
|
206
|
+
private watchSingleFragment;
|
|
158
207
|
private getFragmentDoc;
|
|
159
208
|
/**
|
|
160
209
|
* Read data from the cache for the specified fragment.
|
|
@@ -411,7 +411,18 @@ class InMemoryCache extends cache_js_1.ApolloCache {
|
|
|
411
411
|
}
|
|
412
412
|
broadcastWatches(options) {
|
|
413
413
|
if (!this.txCount) {
|
|
414
|
-
|
|
414
|
+
const prevOnAfter = this.onAfterBroadcast;
|
|
415
|
+
const callbacks = new Set();
|
|
416
|
+
this.onAfterBroadcast = (cb) => {
|
|
417
|
+
callbacks.add(cb);
|
|
418
|
+
};
|
|
419
|
+
try {
|
|
420
|
+
this.watches.forEach((c) => this.maybeBroadcastWatch(c, options));
|
|
421
|
+
callbacks.forEach((cb) => cb());
|
|
422
|
+
}
|
|
423
|
+
finally {
|
|
424
|
+
this.onAfterBroadcast = prevOnAfter;
|
|
425
|
+
}
|
|
415
426
|
}
|
|
416
427
|
}
|
|
417
428
|
addFragmentsToDocument(document) {
|