@apollo/client 3.5.0-rc.1 → 3.5.1
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/apollo-client.cjs +554 -486
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +526 -458
- package/cache/cache.cjs.map +1 -1
- package/cache/inmemory/key-extractor.d.ts +9 -0
- package/cache/inmemory/key-extractor.d.ts.map +1 -0
- package/cache/inmemory/key-extractor.js +118 -0
- package/cache/inmemory/key-extractor.js.map +1 -0
- package/cache/inmemory/policies.d.ts +11 -8
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +42 -156
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +8 -3
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +162 -93
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +1 -0
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ObservableQuery.d.ts +1 -0
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/QueryInfo.d.ts +2 -2
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryManager.d.ts +1 -0
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +1 -1
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +2 -2
- package/core/core.cjs.map +1 -1
- package/invariantErrorCodes.js +5 -5
- package/link/batch/batchLink.d.ts +1 -0
- package/link/batch/batchLink.d.ts.map +1 -1
- package/link/batch/batching.d.ts +1 -0
- package/link/batch/batching.d.ts.map +1 -1
- package/link/batch-http/batchHttpLink.d.ts +1 -0
- package/link/batch-http/batchHttpLink.d.ts.map +1 -1
- package/link/core/ApolloLink.d.ts +1 -0
- package/link/core/ApolloLink.d.ts.map +1 -1
- package/link/core/types.d.ts +5 -6
- package/link/core/types.d.ts.map +1 -1
- package/link/core/types.js.map +1 -1
- package/link/error/index.d.ts +1 -0
- package/link/error/index.d.ts.map +1 -1
- package/link/retry/retryLink.d.ts +1 -0
- package/link/retry/retryLink.d.ts.map +1 -1
- package/link/schema/index.d.ts +1 -0
- package/link/schema/index.d.ts.map +1 -1
- package/link/schema/index.js +8 -1
- package/link/schema/index.js.map +1 -1
- package/link/schema/schema.cjs +8 -1
- package/link/schema/schema.cjs.map +1 -1
- package/link/utils/fromError.d.ts +1 -0
- package/link/utils/fromError.d.ts.map +1 -1
- package/link/utils/fromPromise.d.ts +1 -0
- package/link/utils/fromPromise.d.ts.map +1 -1
- package/link/utils/toPromise.d.ts +1 -0
- package/link/utils/toPromise.d.ts.map +1 -1
- package/link/ws/index.d.ts +1 -0
- package/link/ws/index.d.ts.map +1 -1
- package/package.json +20 -21
- package/react/types/types.d.ts +1 -0
- package/react/types/types.d.ts.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +1 -0
- package/testing/core/mocking/mockLink.d.ts.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +2 -3
- package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -1
- package/utilities/common/errorHandling.d.ts +1 -1
- package/utilities/common/errorHandling.d.ts.map +1 -1
- package/utilities/common/errorHandling.js.map +1 -1
- package/utilities/graphql/fragments.d.ts.map +1 -1
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/observables/Concast.d.ts +1 -0
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/asyncMap.d.ts +1 -0
- package/utilities/observables/asyncMap.d.ts.map +1 -1
- package/utilities/observables/subclassing.d.ts +1 -0
- package/utilities/observables/subclassing.d.ts.map +1 -1
- package/version.js +1 -1
package/apollo-client.cjs
CHANGED
|
@@ -1291,7 +1291,7 @@ var concat = ApolloLink.concat;
|
|
|
1291
1291
|
|
|
1292
1292
|
var execute = ApolloLink.execute;
|
|
1293
1293
|
|
|
1294
|
-
var version = '3.5.
|
|
1294
|
+
var version = '3.5.1';
|
|
1295
1295
|
|
|
1296
1296
|
var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
1297
1297
|
function parseAndCheckHttpResponse(operations) {
|
|
@@ -2574,330 +2574,6 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
2574
2574
|
}
|
|
2575
2575
|
}
|
|
2576
2576
|
|
|
2577
|
-
var StoreWriter = (function () {
|
|
2578
|
-
function StoreWriter(cache, reader) {
|
|
2579
|
-
this.cache = cache;
|
|
2580
|
-
this.reader = reader;
|
|
2581
|
-
}
|
|
2582
|
-
StoreWriter.prototype.writeToStore = function (store, _a) {
|
|
2583
|
-
var _this = this;
|
|
2584
|
-
var query = _a.query, result = _a.result, dataId = _a.dataId, variables = _a.variables, overwrite = _a.overwrite;
|
|
2585
|
-
var operationDefinition = getOperationDefinition(query);
|
|
2586
|
-
var merger = makeProcessedFieldsMerger();
|
|
2587
|
-
variables = tslib.__assign(tslib.__assign({}, getDefaultValues(operationDefinition)), variables);
|
|
2588
|
-
var context = {
|
|
2589
|
-
store: store,
|
|
2590
|
-
written: Object.create(null),
|
|
2591
|
-
merge: function (existing, incoming) {
|
|
2592
|
-
return merger.merge(existing, incoming);
|
|
2593
|
-
},
|
|
2594
|
-
variables: variables,
|
|
2595
|
-
varString: canonicalStringify(variables),
|
|
2596
|
-
fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
|
|
2597
|
-
overwrite: !!overwrite,
|
|
2598
|
-
incomingById: new Map,
|
|
2599
|
-
clientOnly: false,
|
|
2600
|
-
};
|
|
2601
|
-
var ref = this.processSelectionSet({
|
|
2602
|
-
result: result || Object.create(null),
|
|
2603
|
-
dataId: dataId,
|
|
2604
|
-
selectionSet: operationDefinition.selectionSet,
|
|
2605
|
-
mergeTree: { map: new Map },
|
|
2606
|
-
context: context,
|
|
2607
|
-
});
|
|
2608
|
-
if (!isReference(ref)) {
|
|
2609
|
-
throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(6);
|
|
2610
|
-
}
|
|
2611
|
-
context.incomingById.forEach(function (_a, dataId) {
|
|
2612
|
-
var fields = _a.fields, mergeTree = _a.mergeTree, selections = _a.selections;
|
|
2613
|
-
var entityRef = makeReference(dataId);
|
|
2614
|
-
if (mergeTree && mergeTree.map.size) {
|
|
2615
|
-
var applied = _this.applyMerges(mergeTree, entityRef, fields, context);
|
|
2616
|
-
if (isReference(applied)) {
|
|
2617
|
-
return;
|
|
2618
|
-
}
|
|
2619
|
-
fields = applied;
|
|
2620
|
-
}
|
|
2621
|
-
if (__DEV__ && !context.overwrite) {
|
|
2622
|
-
var hasSelectionSet_1 = function (storeFieldName) {
|
|
2623
|
-
return fieldsWithSelectionSets_1.has(fieldNameFromStoreName(storeFieldName));
|
|
2624
|
-
};
|
|
2625
|
-
var fieldsWithSelectionSets_1 = new Set();
|
|
2626
|
-
selections.forEach(function (selection) {
|
|
2627
|
-
if (isField(selection) && selection.selectionSet) {
|
|
2628
|
-
fieldsWithSelectionSets_1.add(selection.name.value);
|
|
2629
|
-
}
|
|
2630
|
-
});
|
|
2631
|
-
var hasMergeFunction_1 = function (storeFieldName) {
|
|
2632
|
-
var childTree = mergeTree && mergeTree.map.get(storeFieldName);
|
|
2633
|
-
return Boolean(childTree && childTree.info && childTree.info.merge);
|
|
2634
|
-
};
|
|
2635
|
-
Object.keys(fields).forEach(function (storeFieldName) {
|
|
2636
|
-
if (hasSelectionSet_1(storeFieldName) &&
|
|
2637
|
-
!hasMergeFunction_1(storeFieldName)) {
|
|
2638
|
-
warnAboutDataLoss(entityRef, fields, storeFieldName, context.store);
|
|
2639
|
-
}
|
|
2640
|
-
});
|
|
2641
|
-
}
|
|
2642
|
-
store.merge(dataId, fields);
|
|
2643
|
-
});
|
|
2644
|
-
store.retain(ref.__ref);
|
|
2645
|
-
return ref;
|
|
2646
|
-
};
|
|
2647
|
-
StoreWriter.prototype.processSelectionSet = function (_a) {
|
|
2648
|
-
var _this = this;
|
|
2649
|
-
var dataId = _a.dataId, result = _a.result, selectionSet = _a.selectionSet, context = _a.context, mergeTree = _a.mergeTree;
|
|
2650
|
-
var policies = this.cache.policies;
|
|
2651
|
-
var _b = policies.identify(result, selectionSet, context.fragmentMap), id = _b[0], keyObject = _b[1];
|
|
2652
|
-
dataId = dataId || id;
|
|
2653
|
-
if ("string" === typeof dataId) {
|
|
2654
|
-
var sets = context.written[dataId] || (context.written[dataId] = []);
|
|
2655
|
-
var ref = makeReference(dataId);
|
|
2656
|
-
if (sets.indexOf(selectionSet) >= 0)
|
|
2657
|
-
return ref;
|
|
2658
|
-
sets.push(selectionSet);
|
|
2659
|
-
if (this.reader && this.reader.isFresh(result, ref, selectionSet, context)) {
|
|
2660
|
-
return ref;
|
|
2661
|
-
}
|
|
2662
|
-
}
|
|
2663
|
-
var incomingFields = Object.create(null);
|
|
2664
|
-
if (keyObject) {
|
|
2665
|
-
incomingFields = context.merge(incomingFields, keyObject);
|
|
2666
|
-
}
|
|
2667
|
-
var typename = (dataId && policies.rootTypenamesById[dataId]) ||
|
|
2668
|
-
getTypenameFromResult(result, selectionSet, context.fragmentMap) ||
|
|
2669
|
-
(dataId && context.store.get(dataId, "__typename"));
|
|
2670
|
-
if ("string" === typeof typename) {
|
|
2671
|
-
incomingFields.__typename = typename;
|
|
2672
|
-
}
|
|
2673
|
-
var selections = new Set(selectionSet.selections);
|
|
2674
|
-
selections.forEach(function (selection) {
|
|
2675
|
-
var _a;
|
|
2676
|
-
if (!shouldInclude(selection, context.variables))
|
|
2677
|
-
return;
|
|
2678
|
-
if (isField(selection)) {
|
|
2679
|
-
var resultFieldKey = resultKeyNameFromField(selection);
|
|
2680
|
-
var value = result[resultFieldKey];
|
|
2681
|
-
var wasClientOnly = context.clientOnly;
|
|
2682
|
-
context.clientOnly = wasClientOnly || !!(selection.directives &&
|
|
2683
|
-
selection.directives.some(function (d) { return d.name.value === "client"; }));
|
|
2684
|
-
if (value !== void 0) {
|
|
2685
|
-
var storeFieldName = policies.getStoreFieldName({
|
|
2686
|
-
typename: typename,
|
|
2687
|
-
fieldName: selection.name.value,
|
|
2688
|
-
field: selection,
|
|
2689
|
-
variables: context.variables,
|
|
2690
|
-
});
|
|
2691
|
-
var childTree = getChildMergeTree(mergeTree, storeFieldName);
|
|
2692
|
-
var incomingValue = _this.processFieldValue(value, selection, context, childTree);
|
|
2693
|
-
var childTypename = void 0;
|
|
2694
|
-
if (selection.selectionSet) {
|
|
2695
|
-
childTypename = context.store.getFieldValue(incomingValue, "__typename");
|
|
2696
|
-
if (!childTypename && isReference(incomingValue)) {
|
|
2697
|
-
var info = context.incomingById.get(incomingValue.__ref);
|
|
2698
|
-
childTypename = info && info.fields.__typename;
|
|
2699
|
-
}
|
|
2700
|
-
}
|
|
2701
|
-
var merge = policies.getMergeFunction(typename, selection.name.value, childTypename);
|
|
2702
|
-
if (merge) {
|
|
2703
|
-
childTree.info = {
|
|
2704
|
-
field: selection,
|
|
2705
|
-
typename: typename,
|
|
2706
|
-
merge: merge,
|
|
2707
|
-
};
|
|
2708
|
-
}
|
|
2709
|
-
else {
|
|
2710
|
-
maybeRecycleChildMergeTree(mergeTree, storeFieldName);
|
|
2711
|
-
}
|
|
2712
|
-
incomingFields = context.merge(incomingFields, (_a = {},
|
|
2713
|
-
_a[storeFieldName] = incomingValue,
|
|
2714
|
-
_a));
|
|
2715
|
-
}
|
|
2716
|
-
else if (__DEV__ &&
|
|
2717
|
-
!context.clientOnly &&
|
|
2718
|
-
!addTypenameToDocument.added(selection) &&
|
|
2719
|
-
!policies.getReadFunction(typename, selection.name.value)) {
|
|
2720
|
-
__DEV__ && tsInvariant.invariant.error(("Missing field '" + resultKeyNameFromField(selection) + "' while writing result " + JSON.stringify(result, null, 2)).substring(0, 1000));
|
|
2721
|
-
}
|
|
2722
|
-
context.clientOnly = wasClientOnly;
|
|
2723
|
-
}
|
|
2724
|
-
else {
|
|
2725
|
-
var fragment = getFragmentFromSelection(selection, context.fragmentMap);
|
|
2726
|
-
if (fragment &&
|
|
2727
|
-
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
2728
|
-
fragment.selectionSet.selections.forEach(selections.add, selections);
|
|
2729
|
-
}
|
|
2730
|
-
}
|
|
2731
|
-
});
|
|
2732
|
-
if ("string" === typeof dataId) {
|
|
2733
|
-
var previous = context.incomingById.get(dataId);
|
|
2734
|
-
if (previous) {
|
|
2735
|
-
previous.fields = context.merge(previous.fields, incomingFields);
|
|
2736
|
-
previous.mergeTree = mergeMergeTrees(previous.mergeTree, mergeTree);
|
|
2737
|
-
previous.selections.forEach(selections.add, selections);
|
|
2738
|
-
previous.selections = selections;
|
|
2739
|
-
}
|
|
2740
|
-
else {
|
|
2741
|
-
context.incomingById.set(dataId, {
|
|
2742
|
-
fields: incomingFields,
|
|
2743
|
-
mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
|
|
2744
|
-
selections: selections,
|
|
2745
|
-
});
|
|
2746
|
-
}
|
|
2747
|
-
return makeReference(dataId);
|
|
2748
|
-
}
|
|
2749
|
-
return incomingFields;
|
|
2750
|
-
};
|
|
2751
|
-
StoreWriter.prototype.processFieldValue = function (value, field, context, mergeTree) {
|
|
2752
|
-
var _this = this;
|
|
2753
|
-
if (!field.selectionSet || value === null) {
|
|
2754
|
-
return __DEV__ ? cloneDeep(value) : value;
|
|
2755
|
-
}
|
|
2756
|
-
if (Array.isArray(value)) {
|
|
2757
|
-
return value.map(function (item, i) {
|
|
2758
|
-
var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
|
|
2759
|
-
maybeRecycleChildMergeTree(mergeTree, i);
|
|
2760
|
-
return value;
|
|
2761
|
-
});
|
|
2762
|
-
}
|
|
2763
|
-
return this.processSelectionSet({
|
|
2764
|
-
result: value,
|
|
2765
|
-
selectionSet: field.selectionSet,
|
|
2766
|
-
context: context,
|
|
2767
|
-
mergeTree: mergeTree,
|
|
2768
|
-
});
|
|
2769
|
-
};
|
|
2770
|
-
StoreWriter.prototype.applyMerges = function (mergeTree, existing, incoming, context, getStorageArgs) {
|
|
2771
|
-
var _a;
|
|
2772
|
-
var _this = this;
|
|
2773
|
-
if (mergeTree.map.size && !isReference(incoming)) {
|
|
2774
|
-
var e_1 = (!Array.isArray(incoming) &&
|
|
2775
|
-
(isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
|
|
2776
|
-
var i_1 = incoming;
|
|
2777
|
-
if (e_1 && !getStorageArgs) {
|
|
2778
|
-
getStorageArgs = [isReference(e_1) ? e_1.__ref : e_1];
|
|
2779
|
-
}
|
|
2780
|
-
var changedFields_1;
|
|
2781
|
-
var getValue_1 = function (from, name) {
|
|
2782
|
-
return Array.isArray(from)
|
|
2783
|
-
? (typeof name === "number" ? from[name] : void 0)
|
|
2784
|
-
: context.store.getFieldValue(from, String(name));
|
|
2785
|
-
};
|
|
2786
|
-
mergeTree.map.forEach(function (childTree, storeFieldName) {
|
|
2787
|
-
var eVal = getValue_1(e_1, storeFieldName);
|
|
2788
|
-
var iVal = getValue_1(i_1, storeFieldName);
|
|
2789
|
-
if (void 0 === iVal)
|
|
2790
|
-
return;
|
|
2791
|
-
if (getStorageArgs) {
|
|
2792
|
-
getStorageArgs.push(storeFieldName);
|
|
2793
|
-
}
|
|
2794
|
-
var aVal = _this.applyMerges(childTree, eVal, iVal, context, getStorageArgs);
|
|
2795
|
-
if (aVal !== iVal) {
|
|
2796
|
-
changedFields_1 = changedFields_1 || new Map;
|
|
2797
|
-
changedFields_1.set(storeFieldName, aVal);
|
|
2798
|
-
}
|
|
2799
|
-
if (getStorageArgs) {
|
|
2800
|
-
tsInvariant.invariant(getStorageArgs.pop() === storeFieldName);
|
|
2801
|
-
}
|
|
2802
|
-
});
|
|
2803
|
-
if (changedFields_1) {
|
|
2804
|
-
incoming = (Array.isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
|
|
2805
|
-
changedFields_1.forEach(function (value, name) {
|
|
2806
|
-
incoming[name] = value;
|
|
2807
|
-
});
|
|
2808
|
-
}
|
|
2809
|
-
}
|
|
2810
|
-
if (mergeTree.info) {
|
|
2811
|
-
return this.cache.policies.runMergeFunction(existing, incoming, mergeTree.info, context, getStorageArgs && (_a = context.store).getStorage.apply(_a, getStorageArgs));
|
|
2812
|
-
}
|
|
2813
|
-
return incoming;
|
|
2814
|
-
};
|
|
2815
|
-
return StoreWriter;
|
|
2816
|
-
}());
|
|
2817
|
-
var emptyMergeTreePool = [];
|
|
2818
|
-
function getChildMergeTree(_a, name) {
|
|
2819
|
-
var map = _a.map;
|
|
2820
|
-
if (!map.has(name)) {
|
|
2821
|
-
map.set(name, emptyMergeTreePool.pop() || { map: new Map });
|
|
2822
|
-
}
|
|
2823
|
-
return map.get(name);
|
|
2824
|
-
}
|
|
2825
|
-
function mergeMergeTrees(left, right) {
|
|
2826
|
-
if (left === right || !right || mergeTreeIsEmpty(right))
|
|
2827
|
-
return left;
|
|
2828
|
-
if (!left || mergeTreeIsEmpty(left))
|
|
2829
|
-
return right;
|
|
2830
|
-
var info = left.info && right.info ? tslib.__assign(tslib.__assign({}, left.info), right.info) : left.info || right.info;
|
|
2831
|
-
var needToMergeMaps = left.map.size && right.map.size;
|
|
2832
|
-
var map = needToMergeMaps ? new Map :
|
|
2833
|
-
left.map.size ? left.map : right.map;
|
|
2834
|
-
var merged = { info: info, map: map };
|
|
2835
|
-
if (needToMergeMaps) {
|
|
2836
|
-
var remainingRightKeys_1 = new Set(right.map.keys());
|
|
2837
|
-
left.map.forEach(function (leftTree, key) {
|
|
2838
|
-
merged.map.set(key, mergeMergeTrees(leftTree, right.map.get(key)));
|
|
2839
|
-
remainingRightKeys_1.delete(key);
|
|
2840
|
-
});
|
|
2841
|
-
remainingRightKeys_1.forEach(function (key) {
|
|
2842
|
-
merged.map.set(key, mergeMergeTrees(right.map.get(key), left.map.get(key)));
|
|
2843
|
-
});
|
|
2844
|
-
}
|
|
2845
|
-
return merged;
|
|
2846
|
-
}
|
|
2847
|
-
function mergeTreeIsEmpty(tree) {
|
|
2848
|
-
return !tree || !(tree.info || tree.map.size);
|
|
2849
|
-
}
|
|
2850
|
-
function maybeRecycleChildMergeTree(_a, name) {
|
|
2851
|
-
var map = _a.map;
|
|
2852
|
-
var childTree = map.get(name);
|
|
2853
|
-
if (childTree && mergeTreeIsEmpty(childTree)) {
|
|
2854
|
-
emptyMergeTreePool.push(childTree);
|
|
2855
|
-
map.delete(name);
|
|
2856
|
-
}
|
|
2857
|
-
}
|
|
2858
|
-
var warnings = new Set();
|
|
2859
|
-
function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
2860
|
-
var getChild = function (objOrRef) {
|
|
2861
|
-
var child = store.getFieldValue(objOrRef, storeFieldName);
|
|
2862
|
-
return typeof child === "object" && child;
|
|
2863
|
-
};
|
|
2864
|
-
var existing = getChild(existingRef);
|
|
2865
|
-
if (!existing)
|
|
2866
|
-
return;
|
|
2867
|
-
var incoming = getChild(incomingObj);
|
|
2868
|
-
if (!incoming)
|
|
2869
|
-
return;
|
|
2870
|
-
if (isReference(existing))
|
|
2871
|
-
return;
|
|
2872
|
-
if (equality.equal(existing, incoming))
|
|
2873
|
-
return;
|
|
2874
|
-
if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
|
|
2875
|
-
return;
|
|
2876
|
-
}
|
|
2877
|
-
var parentType = store.getFieldValue(existingRef, "__typename") ||
|
|
2878
|
-
store.getFieldValue(incomingObj, "__typename");
|
|
2879
|
-
var fieldName = fieldNameFromStoreName(storeFieldName);
|
|
2880
|
-
var typeDotName = parentType + "." + fieldName;
|
|
2881
|
-
if (warnings.has(typeDotName))
|
|
2882
|
-
return;
|
|
2883
|
-
warnings.add(typeDotName);
|
|
2884
|
-
var childTypenames = [];
|
|
2885
|
-
if (!Array.isArray(existing) &&
|
|
2886
|
-
!Array.isArray(incoming)) {
|
|
2887
|
-
[existing, incoming].forEach(function (child) {
|
|
2888
|
-
var typename = store.getFieldValue(child, "__typename");
|
|
2889
|
-
if (typeof typename === "string" &&
|
|
2890
|
-
!childTypenames.includes(typename)) {
|
|
2891
|
-
childTypenames.push(typename);
|
|
2892
|
-
}
|
|
2893
|
-
});
|
|
2894
|
-
}
|
|
2895
|
-
__DEV__ && tsInvariant.invariant.warn("Cache data may be lost when replacing the " + fieldName + " field of a " + parentType + " object.\n\nTo address this problem (which is not a bug in Apollo Client), " + (childTypenames.length
|
|
2896
|
-
? "either ensure all objects of type " +
|
|
2897
|
-
childTypenames.join(" and ") + " have an ID or a custom merge function, or "
|
|
2898
|
-
: "") + "define a custom merge function for the " + typeDotName + " field, so InMemoryCache can safely merge these objects:\n\n existing: " + JSON.stringify(existing).slice(0, 1000) + "\n incoming: " + JSON.stringify(incoming).slice(0, 1000) + "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n");
|
|
2899
|
-
}
|
|
2900
|
-
|
|
2901
2577
|
var cacheSlot = new context.Slot();
|
|
2902
2578
|
var cacheInfoMap = new WeakMap();
|
|
2903
2579
|
function getCacheInfo(cache) {
|
|
@@ -2961,6 +2637,121 @@ function broadcast(cache) {
|
|
|
2961
2637
|
}
|
|
2962
2638
|
}
|
|
2963
2639
|
|
|
2640
|
+
var specifierInfoCache = Object.create(null);
|
|
2641
|
+
function lookupSpecifierInfo(spec) {
|
|
2642
|
+
var cacheKey = JSON.stringify(spec);
|
|
2643
|
+
return specifierInfoCache[cacheKey] ||
|
|
2644
|
+
(specifierInfoCache[cacheKey] = Object.create(null));
|
|
2645
|
+
}
|
|
2646
|
+
function keyFieldsFnFromSpecifier(specifier) {
|
|
2647
|
+
var info = lookupSpecifierInfo(specifier);
|
|
2648
|
+
return info.keyFieldsFn || (info.keyFieldsFn = function (object, context) {
|
|
2649
|
+
var extract = function (from, key) { return context.readField(key, from); };
|
|
2650
|
+
var keyObject = context.keyObject = collectSpecifierPaths(specifier, function (schemaKeyPath) {
|
|
2651
|
+
var extracted = extractKeyPath(context.storeObject, schemaKeyPath, extract);
|
|
2652
|
+
if (extracted === void 0 &&
|
|
2653
|
+
object !== context.storeObject &&
|
|
2654
|
+
hasOwn.call(object, schemaKeyPath[0])) {
|
|
2655
|
+
extracted = extractKeyPath(object, schemaKeyPath, extractKey);
|
|
2656
|
+
}
|
|
2657
|
+
__DEV__ ? tsInvariant.invariant(extracted !== void 0, "Missing field '" + schemaKeyPath.join('.') + "' while extracting keyFields from " + JSON.stringify(object)) : tsInvariant.invariant(extracted !== void 0, 2);
|
|
2658
|
+
return extracted;
|
|
2659
|
+
});
|
|
2660
|
+
return context.typename + ":" + JSON.stringify(keyObject);
|
|
2661
|
+
});
|
|
2662
|
+
}
|
|
2663
|
+
function keyArgsFnFromSpecifier(specifier) {
|
|
2664
|
+
var info = lookupSpecifierInfo(specifier);
|
|
2665
|
+
return info.keyArgsFn || (info.keyArgsFn = function (args, _a) {
|
|
2666
|
+
var field = _a.field, variables = _a.variables, fieldName = _a.fieldName;
|
|
2667
|
+
var collected = collectSpecifierPaths(specifier, function (keyPath) {
|
|
2668
|
+
var firstKey = keyPath[0];
|
|
2669
|
+
var firstChar = firstKey.charAt(0);
|
|
2670
|
+
if (firstChar === "@") {
|
|
2671
|
+
if (field && isNonEmptyArray(field.directives)) {
|
|
2672
|
+
var directiveName_1 = firstKey.slice(1);
|
|
2673
|
+
var d = field.directives.find(function (d) { return d.name.value === directiveName_1; });
|
|
2674
|
+
var directiveArgs = d && argumentsObjectFromField(d, variables);
|
|
2675
|
+
return directiveArgs && extractKeyPath(directiveArgs, keyPath.slice(1));
|
|
2676
|
+
}
|
|
2677
|
+
return;
|
|
2678
|
+
}
|
|
2679
|
+
if (firstChar === "$") {
|
|
2680
|
+
var variableName = firstKey.slice(1);
|
|
2681
|
+
if (variables && hasOwn.call(variables, variableName)) {
|
|
2682
|
+
var varKeyPath = keyPath.slice(0);
|
|
2683
|
+
varKeyPath[0] = variableName;
|
|
2684
|
+
return extractKeyPath(variables, varKeyPath);
|
|
2685
|
+
}
|
|
2686
|
+
return;
|
|
2687
|
+
}
|
|
2688
|
+
if (args) {
|
|
2689
|
+
return extractKeyPath(args, keyPath);
|
|
2690
|
+
}
|
|
2691
|
+
});
|
|
2692
|
+
var suffix = JSON.stringify(collected);
|
|
2693
|
+
if (args || suffix !== "{}") {
|
|
2694
|
+
fieldName += ":" + suffix;
|
|
2695
|
+
}
|
|
2696
|
+
return fieldName;
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
function collectSpecifierPaths(specifier, extractor) {
|
|
2700
|
+
var merger = new DeepMerger;
|
|
2701
|
+
return getSpecifierPaths(specifier).reduce(function (collected, path) {
|
|
2702
|
+
var _a;
|
|
2703
|
+
var toMerge = extractor(path);
|
|
2704
|
+
if (toMerge !== void 0) {
|
|
2705
|
+
for (var i = path.length - 1; i >= 0; --i) {
|
|
2706
|
+
toMerge = (_a = {}, _a[path[i]] = toMerge, _a);
|
|
2707
|
+
}
|
|
2708
|
+
collected = merger.merge(collected, toMerge);
|
|
2709
|
+
}
|
|
2710
|
+
return collected;
|
|
2711
|
+
}, Object.create(null));
|
|
2712
|
+
}
|
|
2713
|
+
function getSpecifierPaths(spec) {
|
|
2714
|
+
var info = lookupSpecifierInfo(spec);
|
|
2715
|
+
if (!info.paths) {
|
|
2716
|
+
var paths_1 = info.paths = [];
|
|
2717
|
+
var currentPath_1 = [];
|
|
2718
|
+
spec.forEach(function (s, i) {
|
|
2719
|
+
if (Array.isArray(s)) {
|
|
2720
|
+
getSpecifierPaths(s).forEach(function (p) { return paths_1.push(currentPath_1.concat(p)); });
|
|
2721
|
+
currentPath_1.length = 0;
|
|
2722
|
+
}
|
|
2723
|
+
else {
|
|
2724
|
+
currentPath_1.push(s);
|
|
2725
|
+
if (!Array.isArray(spec[i + 1])) {
|
|
2726
|
+
paths_1.push(currentPath_1.slice(0));
|
|
2727
|
+
currentPath_1.length = 0;
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
return info.paths;
|
|
2733
|
+
}
|
|
2734
|
+
function extractKey(object, key) {
|
|
2735
|
+
return object[key];
|
|
2736
|
+
}
|
|
2737
|
+
function extractKeyPath(object, path, extract) {
|
|
2738
|
+
extract = extract || extractKey;
|
|
2739
|
+
return normalize(path.reduce(function reducer(obj, key) {
|
|
2740
|
+
return Array.isArray(obj)
|
|
2741
|
+
? obj.map(function (child) { return reducer(child, key); })
|
|
2742
|
+
: obj && extract(obj, key);
|
|
2743
|
+
}, object));
|
|
2744
|
+
}
|
|
2745
|
+
function normalize(value) {
|
|
2746
|
+
if (isNonNullObject(value)) {
|
|
2747
|
+
if (Array.isArray(value)) {
|
|
2748
|
+
return value.map(normalize);
|
|
2749
|
+
}
|
|
2750
|
+
return collectSpecifierPaths(Object.keys(value).sort(), function (path) { return extractKeyPath(value, path); });
|
|
2751
|
+
}
|
|
2752
|
+
return value;
|
|
2753
|
+
}
|
|
2754
|
+
|
|
2964
2755
|
getStoreKeyName.setStringify(canonicalStringify);
|
|
2965
2756
|
function argsFromFieldSpecifier(spec) {
|
|
2966
2757
|
return spec.args !== void 0 ? spec.args :
|
|
@@ -2995,18 +2786,22 @@ var Policies = (function () {
|
|
|
2995
2786
|
this.addTypePolicies(config.typePolicies);
|
|
2996
2787
|
}
|
|
2997
2788
|
}
|
|
2998
|
-
Policies.prototype.identify = function (object,
|
|
2999
|
-
var
|
|
3000
|
-
|
|
3001
|
-
|
|
2789
|
+
Policies.prototype.identify = function (object, partialContext) {
|
|
2790
|
+
var _a;
|
|
2791
|
+
var policies = this;
|
|
2792
|
+
var typename = partialContext && (partialContext.typename ||
|
|
2793
|
+
((_a = partialContext.storeObject) === null || _a === void 0 ? void 0 : _a.__typename)) || object.__typename;
|
|
3002
2794
|
if (typename === this.rootTypenamesById.ROOT_QUERY) {
|
|
3003
2795
|
return ["ROOT_QUERY"];
|
|
3004
2796
|
}
|
|
3005
|
-
var
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
2797
|
+
var storeObject = partialContext && partialContext.storeObject || object;
|
|
2798
|
+
var context = tslib.__assign(tslib.__assign({}, partialContext), { typename: typename, storeObject: storeObject, readField: partialContext && partialContext.readField || function () {
|
|
2799
|
+
var options = normalizeReadFieldOptions(arguments, storeObject);
|
|
2800
|
+
return policies.readField(options, {
|
|
2801
|
+
store: policies.cache["data"],
|
|
2802
|
+
variables: options.variables,
|
|
2803
|
+
});
|
|
2804
|
+
} });
|
|
3010
2805
|
var id;
|
|
3011
2806
|
var policy = typename && this.getTypePolicy(typename);
|
|
3012
2807
|
var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
|
|
@@ -3088,7 +2883,7 @@ var Policies = (function () {
|
|
|
3088
2883
|
var rootId = "ROOT_" + which.toUpperCase();
|
|
3089
2884
|
var old = this.rootTypenamesById[rootId];
|
|
3090
2885
|
if (typename !== old) {
|
|
3091
|
-
__DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which,
|
|
2886
|
+
__DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which, 3);
|
|
3092
2887
|
if (old)
|
|
3093
2888
|
delete this.rootIdsByTypename[old];
|
|
3094
2889
|
this.rootIdsByTypename[typename] = rootId;
|
|
@@ -3304,183 +3099,456 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
|
|
|
3304
3099
|
storage: storage,
|
|
3305
3100
|
cache: policies.cache,
|
|
3306
3101
|
canRead: canRead,
|
|
3307
|
-
readField: function (
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3102
|
+
readField: function () {
|
|
3103
|
+
return policies.readField(normalizeReadFieldOptions(arguments, objectOrReference, context), context);
|
|
3104
|
+
},
|
|
3105
|
+
mergeObjects: makeMergeObjectsFunction(context.store),
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables) {
|
|
3109
|
+
var fieldNameOrOptions = readFieldArgs[0], from = readFieldArgs[1], argc = readFieldArgs.length;
|
|
3110
|
+
var options;
|
|
3111
|
+
if (typeof fieldNameOrOptions === "string") {
|
|
3112
|
+
options = {
|
|
3113
|
+
fieldName: fieldNameOrOptions,
|
|
3114
|
+
from: argc > 1 ? from : objectOrReference,
|
|
3115
|
+
};
|
|
3116
|
+
}
|
|
3117
|
+
else {
|
|
3118
|
+
options = tslib.__assign({}, fieldNameOrOptions);
|
|
3119
|
+
if (!hasOwn.call(options, "from")) {
|
|
3120
|
+
options.from = objectOrReference;
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
if (__DEV__ && options.from === void 0) {
|
|
3124
|
+
__DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments " + stringifyForDisplay(Array.from(readFieldArgs)));
|
|
3125
|
+
}
|
|
3126
|
+
if (void 0 === options.variables) {
|
|
3127
|
+
options.variables = variables;
|
|
3128
|
+
}
|
|
3129
|
+
return options;
|
|
3130
|
+
}
|
|
3131
|
+
function makeMergeObjectsFunction(store) {
|
|
3132
|
+
return function mergeObjects(existing, incoming) {
|
|
3133
|
+
if (Array.isArray(existing) || Array.isArray(incoming)) {
|
|
3134
|
+
throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
|
|
3135
|
+
}
|
|
3136
|
+
if (isNonNullObject(existing) &&
|
|
3137
|
+
isNonNullObject(incoming)) {
|
|
3138
|
+
var eType = store.getFieldValue(existing, "__typename");
|
|
3139
|
+
var iType = store.getFieldValue(incoming, "__typename");
|
|
3140
|
+
var typesDiffer = eType && iType && eType !== iType;
|
|
3141
|
+
if (typesDiffer) {
|
|
3142
|
+
return incoming;
|
|
3143
|
+
}
|
|
3144
|
+
if (isReference(existing) &&
|
|
3145
|
+
storeValueIsStoreObject(incoming)) {
|
|
3146
|
+
store.merge(existing.__ref, incoming);
|
|
3147
|
+
return existing;
|
|
3148
|
+
}
|
|
3149
|
+
if (storeValueIsStoreObject(existing) &&
|
|
3150
|
+
isReference(incoming)) {
|
|
3151
|
+
store.merge(existing, incoming.__ref);
|
|
3152
|
+
return incoming;
|
|
3153
|
+
}
|
|
3154
|
+
if (storeValueIsStoreObject(existing) &&
|
|
3155
|
+
storeValueIsStoreObject(incoming)) {
|
|
3156
|
+
return tslib.__assign(tslib.__assign({}, existing), incoming);
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
return incoming;
|
|
3160
|
+
};
|
|
3161
|
+
}
|
|
3162
|
+
|
|
3163
|
+
function getContextFlavor(context, clientOnly, deferred) {
|
|
3164
|
+
var key = "" + clientOnly + deferred;
|
|
3165
|
+
var flavored = context.flavors.get(key);
|
|
3166
|
+
if (!flavored) {
|
|
3167
|
+
context.flavors.set(key, flavored = (context.clientOnly === clientOnly &&
|
|
3168
|
+
context.deferred === deferred) ? context : tslib.__assign(tslib.__assign({}, context), { clientOnly: clientOnly, deferred: deferred }));
|
|
3169
|
+
}
|
|
3170
|
+
return flavored;
|
|
3171
|
+
}
|
|
3172
|
+
var StoreWriter = (function () {
|
|
3173
|
+
function StoreWriter(cache, reader) {
|
|
3174
|
+
this.cache = cache;
|
|
3175
|
+
this.reader = reader;
|
|
3176
|
+
}
|
|
3177
|
+
StoreWriter.prototype.writeToStore = function (store, _a) {
|
|
3178
|
+
var _this = this;
|
|
3179
|
+
var query = _a.query, result = _a.result, dataId = _a.dataId, variables = _a.variables, overwrite = _a.overwrite;
|
|
3180
|
+
var operationDefinition = getOperationDefinition(query);
|
|
3181
|
+
var merger = makeProcessedFieldsMerger();
|
|
3182
|
+
variables = tslib.__assign(tslib.__assign({}, getDefaultValues(operationDefinition)), variables);
|
|
3183
|
+
var context = {
|
|
3184
|
+
store: store,
|
|
3185
|
+
written: Object.create(null),
|
|
3186
|
+
merge: function (existing, incoming) {
|
|
3187
|
+
return merger.merge(existing, incoming);
|
|
3188
|
+
},
|
|
3189
|
+
variables: variables,
|
|
3190
|
+
varString: canonicalStringify(variables),
|
|
3191
|
+
fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
|
|
3192
|
+
overwrite: !!overwrite,
|
|
3193
|
+
incomingById: new Map,
|
|
3194
|
+
clientOnly: false,
|
|
3195
|
+
deferred: false,
|
|
3196
|
+
flavors: new Map,
|
|
3197
|
+
};
|
|
3198
|
+
var ref = this.processSelectionSet({
|
|
3199
|
+
result: result || Object.create(null),
|
|
3200
|
+
dataId: dataId,
|
|
3201
|
+
selectionSet: operationDefinition.selectionSet,
|
|
3202
|
+
mergeTree: { map: new Map },
|
|
3203
|
+
context: context,
|
|
3204
|
+
});
|
|
3205
|
+
if (!isReference(ref)) {
|
|
3206
|
+
throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(6);
|
|
3207
|
+
}
|
|
3208
|
+
context.incomingById.forEach(function (_a, dataId) {
|
|
3209
|
+
var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
|
|
3210
|
+
var entityRef = makeReference(dataId);
|
|
3211
|
+
if (mergeTree && mergeTree.map.size) {
|
|
3212
|
+
var applied = _this.applyMerges(mergeTree, entityRef, storeObject, context);
|
|
3213
|
+
if (isReference(applied)) {
|
|
3214
|
+
return;
|
|
3215
|
+
}
|
|
3216
|
+
storeObject = applied;
|
|
3217
|
+
}
|
|
3218
|
+
if (__DEV__ && !context.overwrite) {
|
|
3219
|
+
var fieldsWithSelectionSets_1 = Object.create(null);
|
|
3220
|
+
fieldNodeSet.forEach(function (field) {
|
|
3221
|
+
if (field.selectionSet) {
|
|
3222
|
+
fieldsWithSelectionSets_1[field.name.value] = true;
|
|
3223
|
+
}
|
|
3224
|
+
});
|
|
3225
|
+
var hasSelectionSet_1 = function (storeFieldName) {
|
|
3226
|
+
return fieldsWithSelectionSets_1[fieldNameFromStoreName(storeFieldName)] === true;
|
|
3227
|
+
};
|
|
3228
|
+
var hasMergeFunction_1 = function (storeFieldName) {
|
|
3229
|
+
var childTree = mergeTree && mergeTree.map.get(storeFieldName);
|
|
3230
|
+
return Boolean(childTree && childTree.info && childTree.info.merge);
|
|
3313
3231
|
};
|
|
3232
|
+
Object.keys(storeObject).forEach(function (storeFieldName) {
|
|
3233
|
+
if (hasSelectionSet_1(storeFieldName) &&
|
|
3234
|
+
!hasMergeFunction_1(storeFieldName)) {
|
|
3235
|
+
warnAboutDataLoss(entityRef, storeObject, storeFieldName, context.store);
|
|
3236
|
+
}
|
|
3237
|
+
});
|
|
3314
3238
|
}
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3239
|
+
store.merge(dataId, storeObject);
|
|
3240
|
+
});
|
|
3241
|
+
store.retain(ref.__ref);
|
|
3242
|
+
return ref;
|
|
3243
|
+
};
|
|
3244
|
+
StoreWriter.prototype.processSelectionSet = function (_a) {
|
|
3245
|
+
var _this = this;
|
|
3246
|
+
var dataId = _a.dataId, result = _a.result, selectionSet = _a.selectionSet, context = _a.context, mergeTree = _a.mergeTree;
|
|
3247
|
+
var policies = this.cache.policies;
|
|
3248
|
+
var incoming = Object.create(null);
|
|
3249
|
+
var typename = (dataId && policies.rootTypenamesById[dataId]) ||
|
|
3250
|
+
getTypenameFromResult(result, selectionSet, context.fragmentMap) ||
|
|
3251
|
+
(dataId && context.store.get(dataId, "__typename"));
|
|
3252
|
+
if ("string" === typeof typename) {
|
|
3253
|
+
incoming.__typename = typename;
|
|
3254
|
+
}
|
|
3255
|
+
var readField = function () {
|
|
3256
|
+
var options = normalizeReadFieldOptions(arguments, incoming, context.variables);
|
|
3257
|
+
if (isReference(options.from)) {
|
|
3258
|
+
var info = context.incomingById.get(options.from.__ref);
|
|
3259
|
+
if (info) {
|
|
3260
|
+
var result_1 = policies.readField(tslib.__assign(tslib.__assign({}, options), { from: info.storeObject }), context);
|
|
3261
|
+
if (result_1 !== void 0) {
|
|
3262
|
+
return result_1;
|
|
3263
|
+
}
|
|
3319
3264
|
}
|
|
3320
3265
|
}
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3266
|
+
return policies.readField(options, context);
|
|
3267
|
+
};
|
|
3268
|
+
var fieldNodeSet = new Set();
|
|
3269
|
+
this.flattenFields(selectionSet, result, context, typename).forEach(function (context, field) {
|
|
3270
|
+
var _a;
|
|
3271
|
+
var resultFieldKey = resultKeyNameFromField(field);
|
|
3272
|
+
var value = result[resultFieldKey];
|
|
3273
|
+
fieldNodeSet.add(field);
|
|
3274
|
+
if (value !== void 0) {
|
|
3275
|
+
var storeFieldName = policies.getStoreFieldName({
|
|
3276
|
+
typename: typename,
|
|
3277
|
+
fieldName: field.name.value,
|
|
3278
|
+
field: field,
|
|
3279
|
+
variables: context.variables,
|
|
3280
|
+
});
|
|
3281
|
+
var childTree = getChildMergeTree(mergeTree, storeFieldName);
|
|
3282
|
+
var incomingValue = _this.processFieldValue(value, field, field.selectionSet
|
|
3283
|
+
? getContextFlavor(context, false, false)
|
|
3284
|
+
: context, childTree);
|
|
3285
|
+
var childTypename = void 0;
|
|
3286
|
+
if (field.selectionSet &&
|
|
3287
|
+
(isReference(incomingValue) ||
|
|
3288
|
+
storeValueIsStoreObject(incomingValue))) {
|
|
3289
|
+
childTypename = readField("__typename", incomingValue);
|
|
3290
|
+
}
|
|
3291
|
+
var merge = policies.getMergeFunction(typename, field.name.value, childTypename);
|
|
3292
|
+
if (merge) {
|
|
3293
|
+
childTree.info = {
|
|
3294
|
+
field: field,
|
|
3295
|
+
typename: typename,
|
|
3296
|
+
merge: merge,
|
|
3297
|
+
};
|
|
3298
|
+
}
|
|
3299
|
+
else {
|
|
3300
|
+
maybeRecycleChildMergeTree(mergeTree, storeFieldName);
|
|
3301
|
+
}
|
|
3302
|
+
incoming = context.merge(incoming, (_a = {},
|
|
3303
|
+
_a[storeFieldName] = incomingValue,
|
|
3304
|
+
_a));
|
|
3324
3305
|
}
|
|
3325
|
-
if (__DEV__ &&
|
|
3326
|
-
|
|
3306
|
+
else if (__DEV__ &&
|
|
3307
|
+
!context.clientOnly &&
|
|
3308
|
+
!context.deferred &&
|
|
3309
|
+
!addTypenameToDocument.added(field) &&
|
|
3310
|
+
!policies.getReadFunction(typename, field.name.value)) {
|
|
3311
|
+
__DEV__ && tsInvariant.invariant.error(("Missing field '" + resultKeyNameFromField(field) + "' while writing result " + JSON.stringify(result, null, 2)).substring(0, 1000));
|
|
3327
3312
|
}
|
|
3328
|
-
|
|
3329
|
-
|
|
3313
|
+
});
|
|
3314
|
+
try {
|
|
3315
|
+
var _b = policies.identify(result, {
|
|
3316
|
+
typename: typename,
|
|
3317
|
+
selectionSet: selectionSet,
|
|
3318
|
+
fragmentMap: context.fragmentMap,
|
|
3319
|
+
storeObject: incoming,
|
|
3320
|
+
readField: readField,
|
|
3321
|
+
}), id = _b[0], keyObject = _b[1];
|
|
3322
|
+
dataId = dataId || id;
|
|
3323
|
+
if (keyObject) {
|
|
3324
|
+
incoming = context.merge(incoming, keyObject);
|
|
3330
3325
|
}
|
|
3331
|
-
return policies.readField(options, context);
|
|
3332
|
-
},
|
|
3333
|
-
mergeObjects: makeMergeObjectsFunction(context.store),
|
|
3334
|
-
};
|
|
3335
|
-
}
|
|
3336
|
-
function makeMergeObjectsFunction(store) {
|
|
3337
|
-
return function mergeObjects(existing, incoming) {
|
|
3338
|
-
if (Array.isArray(existing) || Array.isArray(incoming)) {
|
|
3339
|
-
throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(3);
|
|
3340
3326
|
}
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
return
|
|
3327
|
+
catch (e) {
|
|
3328
|
+
if (!dataId)
|
|
3329
|
+
throw e;
|
|
3330
|
+
}
|
|
3331
|
+
if ("string" === typeof dataId) {
|
|
3332
|
+
var dataRef = makeReference(dataId);
|
|
3333
|
+
var sets = context.written[dataId] || (context.written[dataId] = []);
|
|
3334
|
+
if (sets.indexOf(selectionSet) >= 0)
|
|
3335
|
+
return dataRef;
|
|
3336
|
+
sets.push(selectionSet);
|
|
3337
|
+
if (this.reader && this.reader.isFresh(result, dataRef, selectionSet, context)) {
|
|
3338
|
+
return dataRef;
|
|
3353
3339
|
}
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3340
|
+
var previous_1 = context.incomingById.get(dataId);
|
|
3341
|
+
if (previous_1) {
|
|
3342
|
+
previous_1.storeObject = context.merge(previous_1.storeObject, incoming);
|
|
3343
|
+
previous_1.mergeTree = mergeMergeTrees(previous_1.mergeTree, mergeTree);
|
|
3344
|
+
fieldNodeSet.forEach(function (field) { return previous_1.fieldNodeSet.add(field); });
|
|
3358
3345
|
}
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3346
|
+
else {
|
|
3347
|
+
context.incomingById.set(dataId, {
|
|
3348
|
+
storeObject: incoming,
|
|
3349
|
+
mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
|
|
3350
|
+
fieldNodeSet: fieldNodeSet,
|
|
3351
|
+
});
|
|
3362
3352
|
}
|
|
3353
|
+
return dataRef;
|
|
3363
3354
|
}
|
|
3364
3355
|
return incoming;
|
|
3365
3356
|
};
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
var suffix = JSON.stringify(computeKeyArgsObject(specifier, context.field, args, context.variables));
|
|
3371
|
-
if (args || suffix !== "{}") {
|
|
3372
|
-
key += ":" + suffix;
|
|
3357
|
+
StoreWriter.prototype.processFieldValue = function (value, field, context, mergeTree) {
|
|
3358
|
+
var _this = this;
|
|
3359
|
+
if (!field.selectionSet || value === null) {
|
|
3360
|
+
return __DEV__ ? cloneDeep(value) : value;
|
|
3373
3361
|
}
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
var aliasMap;
|
|
3381
|
-
if (context.selectionSet && context.fragmentMap) {
|
|
3382
|
-
var info = trie$1.lookupArray([
|
|
3383
|
-
context.selectionSet,
|
|
3384
|
-
context.fragmentMap,
|
|
3385
|
-
]);
|
|
3386
|
-
aliasMap = info.aliasMap || (info.aliasMap = makeAliasMap(context.selectionSet, context.fragmentMap));
|
|
3362
|
+
if (Array.isArray(value)) {
|
|
3363
|
+
return value.map(function (item, i) {
|
|
3364
|
+
var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
|
|
3365
|
+
maybeRecycleChildMergeTree(mergeTree, i);
|
|
3366
|
+
return value;
|
|
3367
|
+
});
|
|
3387
3368
|
}
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3369
|
+
return this.processSelectionSet({
|
|
3370
|
+
result: value,
|
|
3371
|
+
selectionSet: field.selectionSet,
|
|
3372
|
+
context: context,
|
|
3373
|
+
mergeTree: mergeTree,
|
|
3374
|
+
});
|
|
3391
3375
|
};
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3376
|
+
StoreWriter.prototype.flattenFields = function (selectionSet, result, context, typename) {
|
|
3377
|
+
if (typename === void 0) { typename = getTypenameFromResult(result, selectionSet, context.fragmentMap); }
|
|
3378
|
+
var fieldMap = new Map();
|
|
3379
|
+
var policies = this.cache.policies;
|
|
3380
|
+
var limitingTrie = new trie.Trie(false);
|
|
3381
|
+
(function flatten(selectionSet, inheritedContext) {
|
|
3382
|
+
var visitedNode = limitingTrie.lookup(selectionSet, inheritedContext.clientOnly, inheritedContext.deferred);
|
|
3383
|
+
if (visitedNode.visited)
|
|
3384
|
+
return;
|
|
3385
|
+
visitedNode.visited = true;
|
|
3386
|
+
selectionSet.selections.forEach(function (selection) {
|
|
3387
|
+
if (!shouldInclude(selection, context.variables))
|
|
3388
|
+
return;
|
|
3389
|
+
var clientOnly = inheritedContext.clientOnly, deferred = inheritedContext.deferred;
|
|
3390
|
+
if (!(clientOnly && deferred) &&
|
|
3391
|
+
isNonEmptyArray(selection.directives)) {
|
|
3392
|
+
selection.directives.forEach(function (dir) {
|
|
3393
|
+
var name = dir.name.value;
|
|
3394
|
+
if (name === "client")
|
|
3395
|
+
clientOnly = true;
|
|
3396
|
+
if (name === "defer") {
|
|
3397
|
+
var args = argumentsObjectFromField(dir, context.variables);
|
|
3398
|
+
if (!args || args.if !== false) {
|
|
3399
|
+
deferred = true;
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
});
|
|
3403
|
+
}
|
|
3404
|
+
if (isField(selection)) {
|
|
3405
|
+
var existing = fieldMap.get(selection);
|
|
3406
|
+
if (existing) {
|
|
3407
|
+
clientOnly = clientOnly && existing.clientOnly;
|
|
3408
|
+
deferred = deferred && existing.deferred;
|
|
3405
3409
|
}
|
|
3410
|
+
fieldMap.set(selection, getContextFlavor(context, clientOnly, deferred));
|
|
3406
3411
|
}
|
|
3407
|
-
|
|
3408
|
-
var
|
|
3409
|
-
|
|
3410
|
-
|
|
3412
|
+
else {
|
|
3413
|
+
var fragment = getFragmentFromSelection(selection, context.fragmentMap);
|
|
3414
|
+
if (fragment &&
|
|
3415
|
+
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
3416
|
+
flatten(fragment.selectionSet, getContextFlavor(context, clientOnly, deferred));
|
|
3417
|
+
}
|
|
3411
3418
|
}
|
|
3419
|
+
});
|
|
3420
|
+
})(selectionSet, context);
|
|
3421
|
+
return fieldMap;
|
|
3422
|
+
};
|
|
3423
|
+
StoreWriter.prototype.applyMerges = function (mergeTree, existing, incoming, context, getStorageArgs) {
|
|
3424
|
+
var _a;
|
|
3425
|
+
var _this = this;
|
|
3426
|
+
if (mergeTree.map.size && !isReference(incoming)) {
|
|
3427
|
+
var e_1 = (!Array.isArray(incoming) &&
|
|
3428
|
+
(isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
|
|
3429
|
+
var i_1 = incoming;
|
|
3430
|
+
if (e_1 && !getStorageArgs) {
|
|
3431
|
+
getStorageArgs = [isReference(e_1) ? e_1.__ref : e_1];
|
|
3412
3432
|
}
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3433
|
+
var changedFields_1;
|
|
3434
|
+
var getValue_1 = function (from, name) {
|
|
3435
|
+
return Array.isArray(from)
|
|
3436
|
+
? (typeof name === "number" ? from[name] : void 0)
|
|
3437
|
+
: context.store.getFieldValue(from, String(name));
|
|
3438
|
+
};
|
|
3439
|
+
mergeTree.map.forEach(function (childTree, storeFieldName) {
|
|
3440
|
+
var eVal = getValue_1(e_1, storeFieldName);
|
|
3441
|
+
var iVal = getValue_1(i_1, storeFieldName);
|
|
3442
|
+
if (void 0 === iVal)
|
|
3443
|
+
return;
|
|
3444
|
+
if (getStorageArgs) {
|
|
3445
|
+
getStorageArgs.push(storeFieldName);
|
|
3417
3446
|
}
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
}
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
typeof lastResponseKey === "string") {
|
|
3433
|
-
keyObj[lastActualKey] = computeKeyFieldsObject(s, response[lastResponseKey], subsets && subsets[lastActualKey]);
|
|
3447
|
+
var aVal = _this.applyMerges(childTree, eVal, iVal, context, getStorageArgs);
|
|
3448
|
+
if (aVal !== iVal) {
|
|
3449
|
+
changedFields_1 = changedFields_1 || new Map;
|
|
3450
|
+
changedFields_1.set(storeFieldName, aVal);
|
|
3451
|
+
}
|
|
3452
|
+
if (getStorageArgs) {
|
|
3453
|
+
tsInvariant.invariant(getStorageArgs.pop() === storeFieldName);
|
|
3454
|
+
}
|
|
3455
|
+
});
|
|
3456
|
+
if (changedFields_1) {
|
|
3457
|
+
incoming = (Array.isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
|
|
3458
|
+
changedFields_1.forEach(function (value, name) {
|
|
3459
|
+
incoming[name] = value;
|
|
3460
|
+
});
|
|
3434
3461
|
}
|
|
3435
3462
|
}
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
__DEV__ ? tsInvariant.invariant(hasOwn.call(response, responseKey), "Missing field '" + responseKey + "' while extracting keyFields from " + JSON.stringify(response)) : tsInvariant.invariant(hasOwn.call(response, responseKey), 4);
|
|
3439
|
-
keyObj[lastActualKey = s] = response[lastResponseKey = responseKey];
|
|
3463
|
+
if (mergeTree.info) {
|
|
3464
|
+
return this.cache.policies.runMergeFunction(existing, incoming, mergeTree.info, context, getStorageArgs && (_a = context.store).getStorage.apply(_a, getStorageArgs));
|
|
3440
3465
|
}
|
|
3441
|
-
|
|
3442
|
-
|
|
3466
|
+
return incoming;
|
|
3467
|
+
};
|
|
3468
|
+
return StoreWriter;
|
|
3469
|
+
}());
|
|
3470
|
+
var emptyMergeTreePool = [];
|
|
3471
|
+
function getChildMergeTree(_a, name) {
|
|
3472
|
+
var map = _a.map;
|
|
3473
|
+
if (!map.has(name)) {
|
|
3474
|
+
map.set(name, emptyMergeTreePool.pop() || { map: new Map });
|
|
3475
|
+
}
|
|
3476
|
+
return map.get(name);
|
|
3443
3477
|
}
|
|
3444
|
-
function
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3478
|
+
function mergeMergeTrees(left, right) {
|
|
3479
|
+
if (left === right || !right || mergeTreeIsEmpty(right))
|
|
3480
|
+
return left;
|
|
3481
|
+
if (!left || mergeTreeIsEmpty(left))
|
|
3482
|
+
return right;
|
|
3483
|
+
var info = left.info && right.info ? tslib.__assign(tslib.__assign({}, left.info), right.info) : left.info || right.info;
|
|
3484
|
+
var needToMergeMaps = left.map.size && right.map.size;
|
|
3485
|
+
var map = needToMergeMaps ? new Map :
|
|
3486
|
+
left.map.size ? left.map : right.map;
|
|
3487
|
+
var merged = { info: info, map: map };
|
|
3488
|
+
if (needToMergeMaps) {
|
|
3489
|
+
var remainingRightKeys_1 = new Set(right.map.keys());
|
|
3490
|
+
left.map.forEach(function (leftTree, key) {
|
|
3491
|
+
merged.map.set(key, mergeMergeTrees(leftTree, right.map.get(key)));
|
|
3492
|
+
remainingRightKeys_1.delete(key);
|
|
3493
|
+
});
|
|
3494
|
+
remainingRightKeys_1.forEach(function (key) {
|
|
3495
|
+
merged.map.set(key, mergeMergeTrees(right.map.get(key), left.map.get(key)));
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
return merged;
|
|
3499
|
+
}
|
|
3500
|
+
function mergeTreeIsEmpty(tree) {
|
|
3501
|
+
return !tree || !(tree.info || tree.map.size);
|
|
3502
|
+
}
|
|
3503
|
+
function maybeRecycleChildMergeTree(_a, name) {
|
|
3504
|
+
var map = _a.map;
|
|
3505
|
+
var childTree = map.get(name);
|
|
3506
|
+
if (childTree && mergeTreeIsEmpty(childTree)) {
|
|
3507
|
+
emptyMergeTreePool.push(childTree);
|
|
3508
|
+
map.delete(name);
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
var warnings = new Set();
|
|
3512
|
+
function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
3513
|
+
var getChild = function (objOrRef) {
|
|
3514
|
+
var child = store.getFieldValue(objOrRef, storeFieldName);
|
|
3515
|
+
return typeof child === "object" && child;
|
|
3516
|
+
};
|
|
3517
|
+
var existing = getChild(existingRef);
|
|
3518
|
+
if (!existing)
|
|
3519
|
+
return;
|
|
3520
|
+
var incoming = getChild(incomingObj);
|
|
3521
|
+
if (!incoming)
|
|
3522
|
+
return;
|
|
3523
|
+
if (isReference(existing))
|
|
3524
|
+
return;
|
|
3525
|
+
if (equality.equal(existing, incoming))
|
|
3526
|
+
return;
|
|
3527
|
+
if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
|
|
3528
|
+
return;
|
|
3529
|
+
}
|
|
3530
|
+
var parentType = store.getFieldValue(existingRef, "__typename") ||
|
|
3531
|
+
store.getFieldValue(incomingObj, "__typename");
|
|
3532
|
+
var fieldName = fieldNameFromStoreName(storeFieldName);
|
|
3533
|
+
var typeDotName = parentType + "." + fieldName;
|
|
3534
|
+
if (warnings.has(typeDotName))
|
|
3535
|
+
return;
|
|
3536
|
+
warnings.add(typeDotName);
|
|
3537
|
+
var childTypenames = [];
|
|
3538
|
+
if (!Array.isArray(existing) &&
|
|
3539
|
+
!Array.isArray(incoming)) {
|
|
3540
|
+
[existing, incoming].forEach(function (child) {
|
|
3541
|
+
var typename = store.getFieldValue(child, "__typename");
|
|
3542
|
+
if (typeof typename === "string" &&
|
|
3543
|
+
!childTypenames.includes(typename)) {
|
|
3544
|
+
childTypenames.push(typename);
|
|
3479
3545
|
}
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3546
|
+
});
|
|
3547
|
+
}
|
|
3548
|
+
__DEV__ && tsInvariant.invariant.warn("Cache data may be lost when replacing the " + fieldName + " field of a " + parentType + " object.\n\nTo address this problem (which is not a bug in Apollo Client), " + (childTypenames.length
|
|
3549
|
+
? "either ensure all objects of type " +
|
|
3550
|
+
childTypenames.join(" and ") + " have an ID or a custom merge function, or "
|
|
3551
|
+
: "") + "define a custom merge function for the " + typeDotName + " field, so InMemoryCache can safely merge these objects:\n\n existing: " + JSON.stringify(existing).slice(0, 1000) + "\n incoming: " + JSON.stringify(incoming).slice(0, 1000) + "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n");
|
|
3484
3552
|
}
|
|
3485
3553
|
|
|
3486
3554
|
var InMemoryCache = (function (_super) {
|
|
@@ -5457,7 +5525,7 @@ var QueryManager = (function () {
|
|
|
5457
5525
|
if (result !== false) {
|
|
5458
5526
|
results.set(oq, result);
|
|
5459
5527
|
}
|
|
5460
|
-
return
|
|
5528
|
+
return result;
|
|
5461
5529
|
}
|
|
5462
5530
|
if (onQueryUpdated !== null) {
|
|
5463
5531
|
includedQueriesById.set(oq.queryId, { oq: oq, lastDiff: lastDiff, diff: diff });
|