@apollo/client 4.1.0-alpha.5 → 4.1.0-alpha.7
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 +12 -0
- package/__cjs/cache/core/cache.cjs +102 -76
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +9 -8
- package/__cjs/cache/core/types/Cache.d.cts +40 -18
- package/__cjs/core/ApolloClient.cjs +8 -24
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +42 -18
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +4 -4
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.d.cts +6 -6
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +9 -8
- package/cache/core/cache.js +102 -76
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +40 -18
- package/cache/core/types/Cache.js.map +1 -1
- package/core/ApolloClient.d.ts +42 -18
- package/core/ApolloClient.js +8 -24
- package/core/ApolloClient.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/useFragment.d.ts +4 -4
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useSuspenseFragment.d.ts +6 -6
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks-compiled/useFragment.d.ts +4 -4
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useSuspenseFragment.d.ts +6 -6
- package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
- package/version.js +1 -1
|
@@ -10,9 +10,9 @@ import type { MissingTree } from "./types/common.cjs";
|
|
|
10
10
|
export type Transaction = (c: ApolloCache) => void;
|
|
11
11
|
export declare namespace ApolloCache {
|
|
12
12
|
/**
|
|
13
|
-
* Acceptable values provided to the `from` option
|
|
13
|
+
* Acceptable values provided to the `from` option.
|
|
14
14
|
*/
|
|
15
|
-
type
|
|
15
|
+
type FromOptionValue<TData> = StoreObject | Reference | FragmentType<NoInfer<TData>> | string;
|
|
16
16
|
/**
|
|
17
17
|
* Watched fragment options.
|
|
18
18
|
*/
|
|
@@ -32,7 +32,7 @@ export declare namespace ApolloCache {
|
|
|
32
32
|
*
|
|
33
33
|
* @docGroup 1. Required options
|
|
34
34
|
*/
|
|
35
|
-
from: ApolloCache.
|
|
35
|
+
from: ApolloCache.FromOptionValue<TData> | Array<ApolloCache.FromOptionValue<TData> | null> | null;
|
|
36
36
|
/**
|
|
37
37
|
* Any variables that the GraphQL fragment may depend on.
|
|
38
38
|
*
|
|
@@ -182,19 +182,19 @@ export declare abstract class ApolloCache {
|
|
|
182
182
|
optimistic: boolean): Unmasked<TData> | null;
|
|
183
183
|
private fragmentWatches;
|
|
184
184
|
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
185
|
-
from: Array<
|
|
185
|
+
from: Array<ApolloCache.FromOptionValue<TData>>;
|
|
186
186
|
}): ApolloCache.ObservableFragment<Array<Unmasked<TData>>>;
|
|
187
187
|
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
188
188
|
from: Array<null>;
|
|
189
189
|
}): ApolloCache.ObservableFragment<Array<null>>;
|
|
190
190
|
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
191
|
-
from: Array<ApolloCache.
|
|
191
|
+
from: Array<ApolloCache.FromOptionValue<TData> | null>;
|
|
192
192
|
}): ApolloCache.ObservableFragment<Array<Unmasked<TData> | null>>;
|
|
193
193
|
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
194
194
|
from: null;
|
|
195
195
|
}): ApolloCache.ObservableFragment<null>;
|
|
196
196
|
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables> & {
|
|
197
|
-
from:
|
|
197
|
+
from: ApolloCache.FromOptionValue<TData>;
|
|
198
198
|
}): ApolloCache.ObservableFragment<Unmasked<TData>>;
|
|
199
199
|
watchFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: ApolloCache.WatchFragmentOptions<TData, TVariables>): ApolloCache.ObservableFragment<Unmasked<TData> | null>;
|
|
200
200
|
/**
|
|
@@ -208,7 +208,7 @@ export declare abstract class ApolloCache {
|
|
|
208
208
|
/**
|
|
209
209
|
* Read data from the cache for the specified fragment.
|
|
210
210
|
*/
|
|
211
|
-
readFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ fragment, variables, fragmentName, id, optimistic, returnPartialData, }: Cache.ReadFragmentOptions<TData, TVariables>): Unmasked<TData> | null;
|
|
211
|
+
readFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ fragment, variables, fragmentName, id, from, optimistic, returnPartialData, }: Cache.ReadFragmentOptions<TData, TVariables>): Unmasked<TData> | null;
|
|
212
212
|
readFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: Cache.ReadFragmentOptions<TData, TVariables>,
|
|
213
213
|
/**
|
|
214
214
|
* @deprecated Pass the `optimistic` argument as part of the first argument
|
|
@@ -226,9 +226,10 @@ export declare abstract class ApolloCache {
|
|
|
226
226
|
* fragment to validate that the shape of the data you’re writing to the cache
|
|
227
227
|
* is the same as the shape of the data required by the fragment.
|
|
228
228
|
*/
|
|
229
|
-
writeFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ data, fragment, fragmentName, variables, overwrite, id, broadcast, }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
|
|
229
|
+
writeFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>({ data, fragment, fragmentName, variables, overwrite, id, from, broadcast, }: Cache.WriteFragmentOptions<TData, TVariables>): Reference | undefined;
|
|
230
230
|
updateQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: Cache.UpdateQueryOptions<TData, TVariables>, update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void): Unmasked<TData> | null;
|
|
231
231
|
updateFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: Cache.UpdateFragmentOptions<TData, TVariables>, update: (data: Unmasked<TData> | null) => Unmasked<TData> | null | void): Unmasked<TData> | null;
|
|
232
|
+
private toCacheId;
|
|
232
233
|
/**
|
|
233
234
|
* @experimental
|
|
234
235
|
* @internal
|
|
@@ -110,13 +110,7 @@ export declare namespace Cache {
|
|
|
110
110
|
*/
|
|
111
111
|
optimistic?: boolean;
|
|
112
112
|
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* The root id to be used. This id should take the same form as the
|
|
116
|
-
* value returned by the `cache.identify` function. If a value with your
|
|
117
|
-
* id does not exist in the store, `null` will be returned.
|
|
118
|
-
*/
|
|
119
|
-
id?: string;
|
|
113
|
+
type ReadFragmentOptions<TData, TVariables extends OperationVariables> = {
|
|
120
114
|
/**
|
|
121
115
|
* A GraphQL document created using the `gql` template string tag from
|
|
122
116
|
* `graphql-tag` with one or more fragments which will be used to determine
|
|
@@ -147,7 +141,7 @@ export declare namespace Cache {
|
|
|
147
141
|
* @defaultValue false
|
|
148
142
|
*/
|
|
149
143
|
optimistic?: boolean;
|
|
150
|
-
}
|
|
144
|
+
} & Cache.CacheIdentifierOption<TData>;
|
|
151
145
|
interface WriteQueryOptions<TData, TVariables extends OperationVariables> {
|
|
152
146
|
/**
|
|
153
147
|
* The GraphQL query shape to be used constructed using the `gql` template
|
|
@@ -181,13 +175,7 @@ export declare namespace Cache {
|
|
|
181
175
|
*/
|
|
182
176
|
overwrite?: boolean;
|
|
183
177
|
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* The root id to be used. This id should take the same form as the
|
|
187
|
-
* value returned by the `cache.identify` function. If a value with your
|
|
188
|
-
* id does not exist in the store, `null` will be returned.
|
|
189
|
-
*/
|
|
190
|
-
id?: string;
|
|
178
|
+
type WriteFragmentOptions<TData, TVariables extends OperationVariables> = {
|
|
191
179
|
/**
|
|
192
180
|
* A GraphQL document created using the `gql` template string
|
|
193
181
|
* with one or more fragments which will be used to determine
|
|
@@ -221,11 +209,10 @@ export declare namespace Cache {
|
|
|
221
209
|
* @defaultValue false
|
|
222
210
|
*/
|
|
223
211
|
overwrite?: boolean;
|
|
224
|
-
}
|
|
212
|
+
} & Cache.CacheIdentifierOption<TData>;
|
|
225
213
|
interface UpdateQueryOptions<TData, TVariables extends OperationVariables> extends Omit<ReadQueryOptions<TData, TVariables> & WriteQueryOptions<TData, TVariables>, "data"> {
|
|
226
214
|
}
|
|
227
|
-
|
|
228
|
-
}
|
|
215
|
+
type UpdateFragmentOptions<TData, TVariables extends OperationVariables> = Omit<ReadFragmentOptions<TData, TVariables> & WriteFragmentOptions<TData, TVariables>, "data" | "id" | "from"> & Cache.CacheIdentifierOption<TData>;
|
|
229
216
|
type DiffResult<TData> = {
|
|
230
217
|
result: DataValue.Complete<TData>;
|
|
231
218
|
complete: true;
|
|
@@ -237,5 +224,40 @@ export declare namespace Cache {
|
|
|
237
224
|
missing?: MissingFieldError;
|
|
238
225
|
fromOptimisticTransaction?: boolean;
|
|
239
226
|
};
|
|
227
|
+
type CacheIdentifierOption<TData> = {
|
|
228
|
+
/**
|
|
229
|
+
* The root id to be used. This id should take the same form as the
|
|
230
|
+
* value returned by the `cache.identify` function. If a value with your
|
|
231
|
+
* id does not exist in the store, `null` will be returned.
|
|
232
|
+
*/
|
|
233
|
+
id?: string;
|
|
234
|
+
/**
|
|
235
|
+
* An object containing a `__typename` and primary key fields
|
|
236
|
+
* (such as `id`) identifying the entity object from which the fragment will
|
|
237
|
+
* be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID
|
|
238
|
+
* (uncommon).
|
|
239
|
+
*
|
|
240
|
+
* @remarks
|
|
241
|
+
* `from` is given precedence over `id` when both are provided.
|
|
242
|
+
*/
|
|
243
|
+
from?: never;
|
|
244
|
+
} | {
|
|
245
|
+
/**
|
|
246
|
+
* The root id to be used. This id should take the same form as the
|
|
247
|
+
* value returned by the `cache.identify` function. If a value with your
|
|
248
|
+
* id does not exist in the store, `null` will be returned.
|
|
249
|
+
*/
|
|
250
|
+
id?: never;
|
|
251
|
+
/**
|
|
252
|
+
* An object containing a `__typename` and primary key fields
|
|
253
|
+
* (such as `id`) identifying the entity object from which the fragment will
|
|
254
|
+
* be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID
|
|
255
|
+
* (uncommon).
|
|
256
|
+
*
|
|
257
|
+
* @remarks
|
|
258
|
+
* `from` is given precedence over `id` when both are provided.
|
|
259
|
+
*/
|
|
260
|
+
from?: ApolloCache.FromOptionValue<TData>;
|
|
261
|
+
};
|
|
240
262
|
}
|
|
241
263
|
//# sourceMappingURL=Cache.d.cts.map
|
|
@@ -295,11 +295,7 @@ class ApolloClient {
|
|
|
295
295
|
}
|
|
296
296
|
watchFragment(options) {
|
|
297
297
|
const dataMasking = this.queryManager.dataMasking;
|
|
298
|
-
const
|
|
299
|
-
...options,
|
|
300
|
-
fragment: this.transform(options.fragment, dataMasking),
|
|
301
|
-
});
|
|
302
|
-
const mask = (result) => {
|
|
298
|
+
const mask = (data) => {
|
|
303
299
|
// The transform will remove fragment spreads from the fragment
|
|
304
300
|
// document when dataMasking is enabled. The `mask` function
|
|
305
301
|
// remains to apply warnings to fragments marked as
|
|
@@ -307,29 +303,17 @@ class ApolloClient {
|
|
|
307
303
|
// in dev, we can skip the masking algorithm entirely for production.
|
|
308
304
|
if (environment_1.__DEV__) {
|
|
309
305
|
if (dataMasking) {
|
|
310
|
-
return {
|
|
311
|
-
...result,
|
|
312
|
-
data: this.queryManager.maskFragment({
|
|
313
|
-
...options,
|
|
314
|
-
data: result.data,
|
|
315
|
-
}),
|
|
316
|
-
};
|
|
306
|
+
return this.queryManager.maskFragment({ ...options, data });
|
|
317
307
|
}
|
|
318
308
|
}
|
|
319
|
-
return
|
|
309
|
+
return data;
|
|
320
310
|
};
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const result = observable.getCurrentResult();
|
|
326
|
-
if (result !== currentResult) {
|
|
327
|
-
currentResult = result;
|
|
328
|
-
stableMaskedResult = mask(currentResult);
|
|
329
|
-
}
|
|
330
|
-
return stableMaskedResult;
|
|
331
|
-
},
|
|
311
|
+
const observable = this.cache.watchFragment({
|
|
312
|
+
...options,
|
|
313
|
+
fragment: this.transform(options.fragment, dataMasking),
|
|
314
|
+
[Symbol.for("apollo.transformData")]: mask,
|
|
332
315
|
});
|
|
316
|
+
return observable;
|
|
333
317
|
}
|
|
334
318
|
readFragment(options, optimistic = false) {
|
|
335
319
|
return this.cache.readFragment({ ...options, fragment: this.transform(options.fragment) }, optimistic);
|