@apollo/client 4.3.0-alpha.1 → 4.3.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 +285 -0
- package/__cjs/cache/core/Scalar.cjs +36 -0
- package/__cjs/cache/core/Scalar.cjs.map +1 -0
- package/__cjs/cache/core/Scalar.d.cts +20 -0
- package/__cjs/cache/core/cache.cjs +8 -1
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +16 -0
- package/__cjs/cache/index.cjs +3 -1
- package/__cjs/cache/index.cjs.map +1 -1
- package/__cjs/cache/index.d.cts +3 -2
- package/__cjs/cache/inmemory/entityStore.cjs +45 -2
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/entityStore.d.cts +3 -0
- package/__cjs/cache/inmemory/helpers.d.cts +9 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +73 -4
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +35 -3
- package/__cjs/cache/inmemory/policies.cjs +8 -1
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.d.cts +4 -1
- package/__cjs/cache/inmemory/readFromStore.cjs +16 -3
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/types.d.cts +20 -4
- package/__cjs/cache/inmemory/writeToStore.cjs +10 -6
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/core/ApolloClient.cjs +2 -2
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.cjs +1 -3
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/QueryInfo.cjs +211 -37
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +5 -2
- package/__cjs/core/QueryManager.cjs +12 -18
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +1 -3
- package/__cjs/core/index.cjs +2 -1
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +2 -2
- package/__cjs/invariantErrorCodes.cjs +12 -7
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +13 -13
- package/__cjs/utilities/index.cjs.map +1 -1
- package/__cjs/utilities/index.d.cts +1 -0
- package/__cjs/utilities/internal/collectSiblingFields.cjs +61 -0
- package/__cjs/utilities/internal/collectSiblingFields.cjs.map +1 -0
- package/__cjs/utilities/internal/collectSiblingFields.d.cts +21 -0
- package/__cjs/utilities/internal/getUnwrappedType.cjs +20 -0
- package/__cjs/utilities/internal/getUnwrappedType.cjs.map +1 -0
- package/__cjs/utilities/internal/getUnwrappedType.d.cts +8 -0
- package/__cjs/utilities/internal/index.cjs +10 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +6 -0
- package/__cjs/utilities/internal/isDeferredFragment.cjs +23 -0
- package/__cjs/utilities/internal/isDeferredFragment.cjs.map +1 -0
- package/__cjs/utilities/internal/isDeferredFragment.d.cts +4 -0
- package/__cjs/utilities/internal/isTypenameField.cjs +7 -0
- package/__cjs/utilities/internal/isTypenameField.cjs.map +1 -0
- package/__cjs/utilities/internal/isTypenameField.d.cts +3 -0
- package/__cjs/utilities/internal/types/IsLooselyEqual.cjs +3 -0
- package/__cjs/utilities/internal/types/IsLooselyEqual.cjs.map +1 -0
- package/__cjs/utilities/internal/types/IsLooselyEqual.d.cts +10 -0
- package/__cjs/utilities/policies/pagination.cjs.map +1 -1
- package/__cjs/utilities/policies/pagination.d.cts +1 -1
- package/__cjs/utilities/subscriptions/relay/index.cjs +1 -0
- package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/Scalar.d.ts +20 -0
- package/cache/core/Scalar.js +32 -0
- package/cache/core/Scalar.js.map +1 -0
- package/cache/core/cache.d.ts +16 -0
- package/cache/core/cache.js +8 -1
- package/cache/core/cache.js.map +1 -1
- package/cache/index.d.ts +3 -2
- package/cache/index.js +1 -0
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +3 -0
- package/cache/inmemory/entityStore.js +46 -3
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/helpers.d.ts +9 -1
- package/cache/inmemory/inMemoryCache.d.ts +35 -3
- package/cache/inmemory/inMemoryCache.js +74 -5
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/policies.d.ts +4 -1
- package/cache/inmemory/policies.js +8 -1
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +11 -2
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +20 -4
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.js +11 -7
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.js +2 -2
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.js +1 -3
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +5 -2
- package/core/QueryInfo.js +212 -38
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +1 -3
- package/core/QueryManager.js +12 -18
- package/core/QueryManager.js.map +1 -1
- package/core/index.d.ts +2 -2
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/invariantErrorCodes.js +12 -7
- package/package.json +1 -1
- package/react/hooks/useLazyQuery.d.ts +13 -13
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +13 -13
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/utilities/index.d.ts +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/internal/collectSiblingFields.d.ts +21 -0
- package/utilities/internal/collectSiblingFields.js +58 -0
- package/utilities/internal/collectSiblingFields.js.map +1 -0
- package/utilities/internal/getUnwrappedType.d.ts +8 -0
- package/utilities/internal/getUnwrappedType.js +17 -0
- package/utilities/internal/getUnwrappedType.js.map +1 -0
- package/utilities/internal/index.d.ts +6 -0
- package/utilities/internal/index.js +4 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/isDeferredFragment.d.ts +4 -0
- package/utilities/internal/isDeferredFragment.js +20 -0
- package/utilities/internal/isDeferredFragment.js.map +1 -0
- package/utilities/internal/isTypenameField.d.ts +3 -0
- package/utilities/internal/isTypenameField.js +4 -0
- package/utilities/internal/isTypenameField.js.map +1 -0
- package/utilities/internal/types/IsLooselyEqual.d.ts +10 -0
- package/utilities/internal/types/IsLooselyEqual.js +2 -0
- package/utilities/internal/types/IsLooselyEqual.js.map +1 -0
- package/utilities/policies/pagination.d.ts +1 -1
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/subscriptions/relay/index.js +1 -0
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/version.js +1 -1
|
@@ -3,7 +3,7 @@ import { Trie } from "@wry/trie";
|
|
|
3
3
|
import { dep } from "optimism";
|
|
4
4
|
import { isReference } from "@apollo/client/utilities";
|
|
5
5
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
6
|
-
import { DeepMerger, isNonNullObject, makeReference, maybeDeepFreeze, } from "@apollo/client/utilities/internal";
|
|
6
|
+
import { DeepMerger, isNonNullObject, isPlainObject, makeReference, maybeDeepFreeze, } from "@apollo/client/utilities/internal";
|
|
7
7
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
8
8
|
import { fieldNameFromStoreName, hasOwn } from "./helpers.js";
|
|
9
9
|
const DELETE = {};
|
|
@@ -68,12 +68,17 @@ export class EntityStore {
|
|
|
68
68
|
if (isReference(newer))
|
|
69
69
|
newer = newer.__ref;
|
|
70
70
|
const existing = typeof older === "string" ? this.lookup((dataId = older)) : older;
|
|
71
|
-
|
|
71
|
+
let incoming = typeof newer === "string" ? this.lookup((dataId = newer)) : newer;
|
|
72
72
|
// If newer was a string ID, but that ID was not defined in this store,
|
|
73
73
|
// then there are no fields to be merged, so we're done.
|
|
74
74
|
if (!incoming)
|
|
75
75
|
return;
|
|
76
76
|
invariant(typeof dataId === "string", 104);
|
|
77
|
+
// Parse all scalars before merging so that the storeObjectReconciler can
|
|
78
|
+
// deep compare the parsed value with the existing value
|
|
79
|
+
incoming = this.coerceStoreObject(incoming, (scalar, value) => scalar.coerceToParsed(value), incoming.__typename ||
|
|
80
|
+
existing?.__typename ||
|
|
81
|
+
this.policies.rootTypenamesById[dataId]);
|
|
77
82
|
const merged = new DeepMerger({
|
|
78
83
|
reconciler: storeObjectReconciler,
|
|
79
84
|
}).merge(existing, incoming);
|
|
@@ -277,7 +282,14 @@ export class EntityStore {
|
|
|
277
282
|
this.replace(null);
|
|
278
283
|
}
|
|
279
284
|
extract() {
|
|
280
|
-
|
|
285
|
+
let obj = this.toObject();
|
|
286
|
+
if (this.hasScalarConfig()) {
|
|
287
|
+
obj = Object.fromEntries(Object.entries(obj).map(([dataId, storeObject]) => [
|
|
288
|
+
dataId,
|
|
289
|
+
storeObject &&
|
|
290
|
+
this.coerceStoreObject(storeObject, (scalar, value) => scalar.coerceToSerialized(value), storeObject?.__typename || this.policies.rootTypenamesById[dataId]),
|
|
291
|
+
]));
|
|
292
|
+
}
|
|
281
293
|
const extraRootIds = [];
|
|
282
294
|
this.getRootIdSet().forEach((id) => {
|
|
283
295
|
if (!hasOwn.call(this.policies.rootTypenamesById, id)) {
|
|
@@ -289,6 +301,37 @@ export class EntityStore {
|
|
|
289
301
|
}
|
|
290
302
|
return obj;
|
|
291
303
|
}
|
|
304
|
+
hasScalarConfig() {
|
|
305
|
+
return !!this.policies.cache["config"].scalars;
|
|
306
|
+
}
|
|
307
|
+
coerceStoreObject(obj, coerce, typename = obj.__typename) {
|
|
308
|
+
if (!typename || !this.hasScalarConfig()) {
|
|
309
|
+
return obj;
|
|
310
|
+
}
|
|
311
|
+
let changed = false;
|
|
312
|
+
const entries = Object.entries(obj).map(([storeFieldName, value]) => {
|
|
313
|
+
const scalar = this.policies.getScalarForField(typename, fieldNameFromStoreName(storeFieldName));
|
|
314
|
+
const newValue = this.coerceValue(value, coerce, scalar);
|
|
315
|
+
changed ||= newValue !== value;
|
|
316
|
+
return [storeFieldName, newValue];
|
|
317
|
+
});
|
|
318
|
+
return changed ? Object.fromEntries(entries) : obj;
|
|
319
|
+
}
|
|
320
|
+
coerceValue(value, coerce, scalar) {
|
|
321
|
+
if (value == null) {
|
|
322
|
+
return value;
|
|
323
|
+
}
|
|
324
|
+
if (Array.isArray(value)) {
|
|
325
|
+
return value.map((item) => this.coerceValue(item, coerce, scalar));
|
|
326
|
+
}
|
|
327
|
+
if (scalar) {
|
|
328
|
+
return coerce(scalar, value);
|
|
329
|
+
}
|
|
330
|
+
if (isPlainObject(value) && "__typename" in value) {
|
|
331
|
+
return this.coerceStoreObject(value, coerce);
|
|
332
|
+
}
|
|
333
|
+
return value;
|
|
334
|
+
}
|
|
292
335
|
replace(newData) {
|
|
293
336
|
Object.keys(this.data).forEach((dataId) => {
|
|
294
337
|
if (!(newData && hasOwn.call(newData, dataId))) {
|