@apollo/client 3.5.0-rc.2 → 3.5.2
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 +601 -563
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +545 -523
- 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.map +1 -1
- package/cache/inmemory/writeToStore.js +44 -22
- 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 +18 -18
- package/react/hooks/hooks.cjs +67 -51
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +68 -52
- package/react/hooks/useMutation.js.map +1 -1
- 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.2';
|
|
1295
1295
|
|
|
1296
1296
|
var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
1297
1297
|
function parseAndCheckHttpResponse(operations) {
|
|
@@ -2574,376 +2574,6 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
2574
2574
|
}
|
|
2575
2575
|
}
|
|
2576
2576
|
|
|
2577
|
-
function getContextFlavor(context, clientOnly, deferred) {
|
|
2578
|
-
var key = "" + clientOnly + deferred;
|
|
2579
|
-
var flavored = context.flavors.get(key);
|
|
2580
|
-
if (!flavored) {
|
|
2581
|
-
context.flavors.set(key, flavored = (context.clientOnly === clientOnly &&
|
|
2582
|
-
context.deferred === deferred) ? context : tslib.__assign(tslib.__assign({}, context), { clientOnly: clientOnly, deferred: deferred }));
|
|
2583
|
-
}
|
|
2584
|
-
return flavored;
|
|
2585
|
-
}
|
|
2586
|
-
var StoreWriter = (function () {
|
|
2587
|
-
function StoreWriter(cache, reader) {
|
|
2588
|
-
this.cache = cache;
|
|
2589
|
-
this.reader = reader;
|
|
2590
|
-
}
|
|
2591
|
-
StoreWriter.prototype.writeToStore = function (store, _a) {
|
|
2592
|
-
var _this = this;
|
|
2593
|
-
var query = _a.query, result = _a.result, dataId = _a.dataId, variables = _a.variables, overwrite = _a.overwrite;
|
|
2594
|
-
var operationDefinition = getOperationDefinition(query);
|
|
2595
|
-
var merger = makeProcessedFieldsMerger();
|
|
2596
|
-
variables = tslib.__assign(tslib.__assign({}, getDefaultValues(operationDefinition)), variables);
|
|
2597
|
-
var context = {
|
|
2598
|
-
store: store,
|
|
2599
|
-
written: Object.create(null),
|
|
2600
|
-
merge: function (existing, incoming) {
|
|
2601
|
-
return merger.merge(existing, incoming);
|
|
2602
|
-
},
|
|
2603
|
-
variables: variables,
|
|
2604
|
-
varString: canonicalStringify(variables),
|
|
2605
|
-
fragmentMap: createFragmentMap(getFragmentDefinitions(query)),
|
|
2606
|
-
overwrite: !!overwrite,
|
|
2607
|
-
incomingById: new Map,
|
|
2608
|
-
clientOnly: false,
|
|
2609
|
-
deferred: false,
|
|
2610
|
-
flavors: new Map,
|
|
2611
|
-
};
|
|
2612
|
-
var ref = this.processSelectionSet({
|
|
2613
|
-
result: result || Object.create(null),
|
|
2614
|
-
dataId: dataId,
|
|
2615
|
-
selectionSet: operationDefinition.selectionSet,
|
|
2616
|
-
mergeTree: { map: new Map },
|
|
2617
|
-
context: context,
|
|
2618
|
-
});
|
|
2619
|
-
if (!isReference(ref)) {
|
|
2620
|
-
throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(6);
|
|
2621
|
-
}
|
|
2622
|
-
context.incomingById.forEach(function (_a, dataId) {
|
|
2623
|
-
var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
|
|
2624
|
-
var entityRef = makeReference(dataId);
|
|
2625
|
-
if (mergeTree && mergeTree.map.size) {
|
|
2626
|
-
var applied = _this.applyMerges(mergeTree, entityRef, storeObject, context);
|
|
2627
|
-
if (isReference(applied)) {
|
|
2628
|
-
return;
|
|
2629
|
-
}
|
|
2630
|
-
storeObject = applied;
|
|
2631
|
-
}
|
|
2632
|
-
if (__DEV__ && !context.overwrite) {
|
|
2633
|
-
var fieldsWithSelectionSets_1 = Object.create(null);
|
|
2634
|
-
fieldNodeSet.forEach(function (field) {
|
|
2635
|
-
if (field.selectionSet) {
|
|
2636
|
-
fieldsWithSelectionSets_1[field.name.value] = true;
|
|
2637
|
-
}
|
|
2638
|
-
});
|
|
2639
|
-
var hasSelectionSet_1 = function (storeFieldName) {
|
|
2640
|
-
return fieldsWithSelectionSets_1[fieldNameFromStoreName(storeFieldName)] === true;
|
|
2641
|
-
};
|
|
2642
|
-
var hasMergeFunction_1 = function (storeFieldName) {
|
|
2643
|
-
var childTree = mergeTree && mergeTree.map.get(storeFieldName);
|
|
2644
|
-
return Boolean(childTree && childTree.info && childTree.info.merge);
|
|
2645
|
-
};
|
|
2646
|
-
Object.keys(storeObject).forEach(function (storeFieldName) {
|
|
2647
|
-
if (hasSelectionSet_1(storeFieldName) &&
|
|
2648
|
-
!hasMergeFunction_1(storeFieldName)) {
|
|
2649
|
-
warnAboutDataLoss(entityRef, storeObject, storeFieldName, context.store);
|
|
2650
|
-
}
|
|
2651
|
-
});
|
|
2652
|
-
}
|
|
2653
|
-
store.merge(dataId, storeObject);
|
|
2654
|
-
});
|
|
2655
|
-
store.retain(ref.__ref);
|
|
2656
|
-
return ref;
|
|
2657
|
-
};
|
|
2658
|
-
StoreWriter.prototype.processSelectionSet = function (_a) {
|
|
2659
|
-
var _this = this;
|
|
2660
|
-
var dataId = _a.dataId, result = _a.result, selectionSet = _a.selectionSet, context = _a.context, mergeTree = _a.mergeTree;
|
|
2661
|
-
var policies = this.cache.policies;
|
|
2662
|
-
var _b = policies.identify(result, selectionSet, context.fragmentMap), id = _b[0], keyObject = _b[1];
|
|
2663
|
-
dataId = dataId || id;
|
|
2664
|
-
if ("string" === typeof dataId) {
|
|
2665
|
-
var sets = context.written[dataId] || (context.written[dataId] = []);
|
|
2666
|
-
var ref = makeReference(dataId);
|
|
2667
|
-
if (sets.indexOf(selectionSet) >= 0)
|
|
2668
|
-
return ref;
|
|
2669
|
-
sets.push(selectionSet);
|
|
2670
|
-
if (this.reader && this.reader.isFresh(result, ref, selectionSet, context)) {
|
|
2671
|
-
return ref;
|
|
2672
|
-
}
|
|
2673
|
-
}
|
|
2674
|
-
var incoming = Object.create(null);
|
|
2675
|
-
if (keyObject) {
|
|
2676
|
-
incoming = context.merge(incoming, keyObject);
|
|
2677
|
-
}
|
|
2678
|
-
var typename = (dataId && policies.rootTypenamesById[dataId]) ||
|
|
2679
|
-
getTypenameFromResult(result, selectionSet, context.fragmentMap) ||
|
|
2680
|
-
(dataId && context.store.get(dataId, "__typename"));
|
|
2681
|
-
if ("string" === typeof typename) {
|
|
2682
|
-
incoming.__typename = typename;
|
|
2683
|
-
}
|
|
2684
|
-
var fieldNodeSet = new Set();
|
|
2685
|
-
this.flattenFields(selectionSet, result, context, typename).forEach(function (context, field) {
|
|
2686
|
-
var _a;
|
|
2687
|
-
var resultFieldKey = resultKeyNameFromField(field);
|
|
2688
|
-
var value = result[resultFieldKey];
|
|
2689
|
-
fieldNodeSet.add(field);
|
|
2690
|
-
if (value !== void 0) {
|
|
2691
|
-
var storeFieldName = policies.getStoreFieldName({
|
|
2692
|
-
typename: typename,
|
|
2693
|
-
fieldName: field.name.value,
|
|
2694
|
-
field: field,
|
|
2695
|
-
variables: context.variables,
|
|
2696
|
-
});
|
|
2697
|
-
var childTree = getChildMergeTree(mergeTree, storeFieldName);
|
|
2698
|
-
var incomingValue = _this.processFieldValue(value, field, field.selectionSet
|
|
2699
|
-
? getContextFlavor(context, false, false)
|
|
2700
|
-
: context, childTree);
|
|
2701
|
-
var childTypename = void 0;
|
|
2702
|
-
if (field.selectionSet) {
|
|
2703
|
-
childTypename = context.store.getFieldValue(incomingValue, "__typename");
|
|
2704
|
-
if (!childTypename && isReference(incomingValue)) {
|
|
2705
|
-
var info = context.incomingById.get(incomingValue.__ref);
|
|
2706
|
-
childTypename = info && info.storeObject.__typename;
|
|
2707
|
-
}
|
|
2708
|
-
}
|
|
2709
|
-
var merge = policies.getMergeFunction(typename, field.name.value, childTypename);
|
|
2710
|
-
if (merge) {
|
|
2711
|
-
childTree.info = {
|
|
2712
|
-
field: field,
|
|
2713
|
-
typename: typename,
|
|
2714
|
-
merge: merge,
|
|
2715
|
-
};
|
|
2716
|
-
}
|
|
2717
|
-
else {
|
|
2718
|
-
maybeRecycleChildMergeTree(mergeTree, storeFieldName);
|
|
2719
|
-
}
|
|
2720
|
-
incoming = context.merge(incoming, (_a = {},
|
|
2721
|
-
_a[storeFieldName] = incomingValue,
|
|
2722
|
-
_a));
|
|
2723
|
-
}
|
|
2724
|
-
else if (__DEV__ &&
|
|
2725
|
-
!context.clientOnly &&
|
|
2726
|
-
!context.deferred &&
|
|
2727
|
-
!addTypenameToDocument.added(field) &&
|
|
2728
|
-
!policies.getReadFunction(typename, field.name.value)) {
|
|
2729
|
-
__DEV__ && tsInvariant.invariant.error(("Missing field '" + resultKeyNameFromField(field) + "' while writing result " + JSON.stringify(result, null, 2)).substring(0, 1000));
|
|
2730
|
-
}
|
|
2731
|
-
});
|
|
2732
|
-
if ("string" === typeof dataId) {
|
|
2733
|
-
var previous_1 = context.incomingById.get(dataId);
|
|
2734
|
-
if (previous_1) {
|
|
2735
|
-
previous_1.storeObject = context.merge(previous_1.storeObject, incoming);
|
|
2736
|
-
previous_1.mergeTree = mergeMergeTrees(previous_1.mergeTree, mergeTree);
|
|
2737
|
-
fieldNodeSet.forEach(function (field) { return previous_1.fieldNodeSet.add(field); });
|
|
2738
|
-
}
|
|
2739
|
-
else {
|
|
2740
|
-
context.incomingById.set(dataId, {
|
|
2741
|
-
storeObject: incoming,
|
|
2742
|
-
mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
|
|
2743
|
-
fieldNodeSet: fieldNodeSet,
|
|
2744
|
-
});
|
|
2745
|
-
}
|
|
2746
|
-
return makeReference(dataId);
|
|
2747
|
-
}
|
|
2748
|
-
return incoming;
|
|
2749
|
-
};
|
|
2750
|
-
StoreWriter.prototype.processFieldValue = function (value, field, context, mergeTree) {
|
|
2751
|
-
var _this = this;
|
|
2752
|
-
if (!field.selectionSet || value === null) {
|
|
2753
|
-
return __DEV__ ? cloneDeep(value) : value;
|
|
2754
|
-
}
|
|
2755
|
-
if (Array.isArray(value)) {
|
|
2756
|
-
return value.map(function (item, i) {
|
|
2757
|
-
var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
|
|
2758
|
-
maybeRecycleChildMergeTree(mergeTree, i);
|
|
2759
|
-
return value;
|
|
2760
|
-
});
|
|
2761
|
-
}
|
|
2762
|
-
return this.processSelectionSet({
|
|
2763
|
-
result: value,
|
|
2764
|
-
selectionSet: field.selectionSet,
|
|
2765
|
-
context: context,
|
|
2766
|
-
mergeTree: mergeTree,
|
|
2767
|
-
});
|
|
2768
|
-
};
|
|
2769
|
-
StoreWriter.prototype.flattenFields = function (selectionSet, result, context, typename) {
|
|
2770
|
-
if (typename === void 0) { typename = getTypenameFromResult(result, selectionSet, context.fragmentMap); }
|
|
2771
|
-
var fieldMap = new Map();
|
|
2772
|
-
var policies = this.cache.policies;
|
|
2773
|
-
var limitingTrie = new trie.Trie(false);
|
|
2774
|
-
(function flatten(selectionSet, inheritedContext) {
|
|
2775
|
-
var visitedNode = limitingTrie.lookup(selectionSet, inheritedContext.clientOnly, inheritedContext.deferred);
|
|
2776
|
-
if (visitedNode.visited)
|
|
2777
|
-
return;
|
|
2778
|
-
visitedNode.visited = true;
|
|
2779
|
-
selectionSet.selections.forEach(function (selection) {
|
|
2780
|
-
if (!shouldInclude(selection, context.variables))
|
|
2781
|
-
return;
|
|
2782
|
-
var clientOnly = inheritedContext.clientOnly, deferred = inheritedContext.deferred;
|
|
2783
|
-
if (!(clientOnly && deferred) &&
|
|
2784
|
-
isNonEmptyArray(selection.directives)) {
|
|
2785
|
-
selection.directives.forEach(function (dir) {
|
|
2786
|
-
var name = dir.name.value;
|
|
2787
|
-
if (name === "client")
|
|
2788
|
-
clientOnly = true;
|
|
2789
|
-
if (name === "defer") {
|
|
2790
|
-
var args = argumentsObjectFromField(dir, context.variables);
|
|
2791
|
-
if (!args || args.if !== false) {
|
|
2792
|
-
deferred = true;
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
});
|
|
2796
|
-
}
|
|
2797
|
-
if (isField(selection)) {
|
|
2798
|
-
var existing = fieldMap.get(selection);
|
|
2799
|
-
if (existing) {
|
|
2800
|
-
clientOnly = clientOnly && existing.clientOnly;
|
|
2801
|
-
deferred = deferred && existing.deferred;
|
|
2802
|
-
}
|
|
2803
|
-
fieldMap.set(selection, getContextFlavor(context, clientOnly, deferred));
|
|
2804
|
-
}
|
|
2805
|
-
else {
|
|
2806
|
-
var fragment = getFragmentFromSelection(selection, context.fragmentMap);
|
|
2807
|
-
if (fragment &&
|
|
2808
|
-
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
2809
|
-
flatten(fragment.selectionSet, getContextFlavor(context, clientOnly, deferred));
|
|
2810
|
-
}
|
|
2811
|
-
}
|
|
2812
|
-
});
|
|
2813
|
-
})(selectionSet, context);
|
|
2814
|
-
return fieldMap;
|
|
2815
|
-
};
|
|
2816
|
-
StoreWriter.prototype.applyMerges = function (mergeTree, existing, incoming, context, getStorageArgs) {
|
|
2817
|
-
var _a;
|
|
2818
|
-
var _this = this;
|
|
2819
|
-
if (mergeTree.map.size && !isReference(incoming)) {
|
|
2820
|
-
var e_1 = (!Array.isArray(incoming) &&
|
|
2821
|
-
(isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
|
|
2822
|
-
var i_1 = incoming;
|
|
2823
|
-
if (e_1 && !getStorageArgs) {
|
|
2824
|
-
getStorageArgs = [isReference(e_1) ? e_1.__ref : e_1];
|
|
2825
|
-
}
|
|
2826
|
-
var changedFields_1;
|
|
2827
|
-
var getValue_1 = function (from, name) {
|
|
2828
|
-
return Array.isArray(from)
|
|
2829
|
-
? (typeof name === "number" ? from[name] : void 0)
|
|
2830
|
-
: context.store.getFieldValue(from, String(name));
|
|
2831
|
-
};
|
|
2832
|
-
mergeTree.map.forEach(function (childTree, storeFieldName) {
|
|
2833
|
-
var eVal = getValue_1(e_1, storeFieldName);
|
|
2834
|
-
var iVal = getValue_1(i_1, storeFieldName);
|
|
2835
|
-
if (void 0 === iVal)
|
|
2836
|
-
return;
|
|
2837
|
-
if (getStorageArgs) {
|
|
2838
|
-
getStorageArgs.push(storeFieldName);
|
|
2839
|
-
}
|
|
2840
|
-
var aVal = _this.applyMerges(childTree, eVal, iVal, context, getStorageArgs);
|
|
2841
|
-
if (aVal !== iVal) {
|
|
2842
|
-
changedFields_1 = changedFields_1 || new Map;
|
|
2843
|
-
changedFields_1.set(storeFieldName, aVal);
|
|
2844
|
-
}
|
|
2845
|
-
if (getStorageArgs) {
|
|
2846
|
-
tsInvariant.invariant(getStorageArgs.pop() === storeFieldName);
|
|
2847
|
-
}
|
|
2848
|
-
});
|
|
2849
|
-
if (changedFields_1) {
|
|
2850
|
-
incoming = (Array.isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
|
|
2851
|
-
changedFields_1.forEach(function (value, name) {
|
|
2852
|
-
incoming[name] = value;
|
|
2853
|
-
});
|
|
2854
|
-
}
|
|
2855
|
-
}
|
|
2856
|
-
if (mergeTree.info) {
|
|
2857
|
-
return this.cache.policies.runMergeFunction(existing, incoming, mergeTree.info, context, getStorageArgs && (_a = context.store).getStorage.apply(_a, getStorageArgs));
|
|
2858
|
-
}
|
|
2859
|
-
return incoming;
|
|
2860
|
-
};
|
|
2861
|
-
return StoreWriter;
|
|
2862
|
-
}());
|
|
2863
|
-
var emptyMergeTreePool = [];
|
|
2864
|
-
function getChildMergeTree(_a, name) {
|
|
2865
|
-
var map = _a.map;
|
|
2866
|
-
if (!map.has(name)) {
|
|
2867
|
-
map.set(name, emptyMergeTreePool.pop() || { map: new Map });
|
|
2868
|
-
}
|
|
2869
|
-
return map.get(name);
|
|
2870
|
-
}
|
|
2871
|
-
function mergeMergeTrees(left, right) {
|
|
2872
|
-
if (left === right || !right || mergeTreeIsEmpty(right))
|
|
2873
|
-
return left;
|
|
2874
|
-
if (!left || mergeTreeIsEmpty(left))
|
|
2875
|
-
return right;
|
|
2876
|
-
var info = left.info && right.info ? tslib.__assign(tslib.__assign({}, left.info), right.info) : left.info || right.info;
|
|
2877
|
-
var needToMergeMaps = left.map.size && right.map.size;
|
|
2878
|
-
var map = needToMergeMaps ? new Map :
|
|
2879
|
-
left.map.size ? left.map : right.map;
|
|
2880
|
-
var merged = { info: info, map: map };
|
|
2881
|
-
if (needToMergeMaps) {
|
|
2882
|
-
var remainingRightKeys_1 = new Set(right.map.keys());
|
|
2883
|
-
left.map.forEach(function (leftTree, key) {
|
|
2884
|
-
merged.map.set(key, mergeMergeTrees(leftTree, right.map.get(key)));
|
|
2885
|
-
remainingRightKeys_1.delete(key);
|
|
2886
|
-
});
|
|
2887
|
-
remainingRightKeys_1.forEach(function (key) {
|
|
2888
|
-
merged.map.set(key, mergeMergeTrees(right.map.get(key), left.map.get(key)));
|
|
2889
|
-
});
|
|
2890
|
-
}
|
|
2891
|
-
return merged;
|
|
2892
|
-
}
|
|
2893
|
-
function mergeTreeIsEmpty(tree) {
|
|
2894
|
-
return !tree || !(tree.info || tree.map.size);
|
|
2895
|
-
}
|
|
2896
|
-
function maybeRecycleChildMergeTree(_a, name) {
|
|
2897
|
-
var map = _a.map;
|
|
2898
|
-
var childTree = map.get(name);
|
|
2899
|
-
if (childTree && mergeTreeIsEmpty(childTree)) {
|
|
2900
|
-
emptyMergeTreePool.push(childTree);
|
|
2901
|
-
map.delete(name);
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
var warnings = new Set();
|
|
2905
|
-
function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
2906
|
-
var getChild = function (objOrRef) {
|
|
2907
|
-
var child = store.getFieldValue(objOrRef, storeFieldName);
|
|
2908
|
-
return typeof child === "object" && child;
|
|
2909
|
-
};
|
|
2910
|
-
var existing = getChild(existingRef);
|
|
2911
|
-
if (!existing)
|
|
2912
|
-
return;
|
|
2913
|
-
var incoming = getChild(incomingObj);
|
|
2914
|
-
if (!incoming)
|
|
2915
|
-
return;
|
|
2916
|
-
if (isReference(existing))
|
|
2917
|
-
return;
|
|
2918
|
-
if (equality.equal(existing, incoming))
|
|
2919
|
-
return;
|
|
2920
|
-
if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
|
|
2921
|
-
return;
|
|
2922
|
-
}
|
|
2923
|
-
var parentType = store.getFieldValue(existingRef, "__typename") ||
|
|
2924
|
-
store.getFieldValue(incomingObj, "__typename");
|
|
2925
|
-
var fieldName = fieldNameFromStoreName(storeFieldName);
|
|
2926
|
-
var typeDotName = parentType + "." + fieldName;
|
|
2927
|
-
if (warnings.has(typeDotName))
|
|
2928
|
-
return;
|
|
2929
|
-
warnings.add(typeDotName);
|
|
2930
|
-
var childTypenames = [];
|
|
2931
|
-
if (!Array.isArray(existing) &&
|
|
2932
|
-
!Array.isArray(incoming)) {
|
|
2933
|
-
[existing, incoming].forEach(function (child) {
|
|
2934
|
-
var typename = store.getFieldValue(child, "__typename");
|
|
2935
|
-
if (typeof typename === "string" &&
|
|
2936
|
-
!childTypenames.includes(typename)) {
|
|
2937
|
-
childTypenames.push(typename);
|
|
2938
|
-
}
|
|
2939
|
-
});
|
|
2940
|
-
}
|
|
2941
|
-
__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
|
|
2942
|
-
? "either ensure all objects of type " +
|
|
2943
|
-
childTypenames.join(" and ") + " have an ID or a custom merge function, or "
|
|
2944
|
-
: "") + "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");
|
|
2945
|
-
}
|
|
2946
|
-
|
|
2947
2577
|
var cacheSlot = new context.Slot();
|
|
2948
2578
|
var cacheInfoMap = new WeakMap();
|
|
2949
2579
|
function getCacheInfo(cache) {
|
|
@@ -3007,6 +2637,121 @@ function broadcast(cache) {
|
|
|
3007
2637
|
}
|
|
3008
2638
|
}
|
|
3009
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
|
+
|
|
3010
2755
|
getStoreKeyName.setStringify(canonicalStringify);
|
|
3011
2756
|
function argsFromFieldSpecifier(spec) {
|
|
3012
2757
|
return spec.args !== void 0 ? spec.args :
|
|
@@ -3041,18 +2786,22 @@ var Policies = (function () {
|
|
|
3041
2786
|
this.addTypePolicies(config.typePolicies);
|
|
3042
2787
|
}
|
|
3043
2788
|
}
|
|
3044
|
-
Policies.prototype.identify = function (object,
|
|
3045
|
-
var
|
|
3046
|
-
|
|
3047
|
-
|
|
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;
|
|
3048
2794
|
if (typename === this.rootTypenamesById.ROOT_QUERY) {
|
|
3049
2795
|
return ["ROOT_QUERY"];
|
|
3050
2796
|
}
|
|
3051
|
-
var
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
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
|
+
} });
|
|
3056
2805
|
var id;
|
|
3057
2806
|
var policy = typename && this.getTypePolicy(typename);
|
|
3058
2807
|
var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
|
|
@@ -3134,7 +2883,7 @@ var Policies = (function () {
|
|
|
3134
2883
|
var rootId = "ROOT_" + which.toUpperCase();
|
|
3135
2884
|
var old = this.rootTypenamesById[rootId];
|
|
3136
2885
|
if (typename !== old) {
|
|
3137
|
-
__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);
|
|
3138
2887
|
if (old)
|
|
3139
2888
|
delete this.rootIdsByTypename[old];
|
|
3140
2889
|
this.rootIdsByTypename[typename] = rootId;
|
|
@@ -3350,39 +3099,39 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
|
|
|
3350
3099
|
storage: storage,
|
|
3351
3100
|
cache: policies.cache,
|
|
3352
3101
|
canRead: canRead,
|
|
3353
|
-
readField: function (
|
|
3354
|
-
|
|
3355
|
-
if (typeof fieldNameOrOptions === "string") {
|
|
3356
|
-
options = {
|
|
3357
|
-
fieldName: fieldNameOrOptions,
|
|
3358
|
-
from: arguments.length > 1 ? from : objectOrReference,
|
|
3359
|
-
};
|
|
3360
|
-
}
|
|
3361
|
-
else if (isNonNullObject(fieldNameOrOptions)) {
|
|
3362
|
-
options = tslib.__assign({}, fieldNameOrOptions);
|
|
3363
|
-
if (!hasOwn.call(fieldNameOrOptions, "from")) {
|
|
3364
|
-
options.from = objectOrReference;
|
|
3365
|
-
}
|
|
3366
|
-
}
|
|
3367
|
-
else {
|
|
3368
|
-
__DEV__ && tsInvariant.invariant.warn("Unexpected readField arguments: " + stringifyForDisplay(Array.from(arguments)));
|
|
3369
|
-
return;
|
|
3370
|
-
}
|
|
3371
|
-
if (__DEV__ && options.from === void 0) {
|
|
3372
|
-
__DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments " + stringifyForDisplay(Array.from(arguments)));
|
|
3373
|
-
}
|
|
3374
|
-
if (void 0 === options.variables) {
|
|
3375
|
-
options.variables = variables;
|
|
3376
|
-
}
|
|
3377
|
-
return policies.readField(options, context);
|
|
3102
|
+
readField: function () {
|
|
3103
|
+
return policies.readField(normalizeReadFieldOptions(arguments, objectOrReference, context), context);
|
|
3378
3104
|
},
|
|
3379
3105
|
mergeObjects: makeMergeObjectsFunction(context.store),
|
|
3380
3106
|
};
|
|
3381
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
|
+
}
|
|
3382
3131
|
function makeMergeObjectsFunction(store) {
|
|
3383
3132
|
return function mergeObjects(existing, incoming) {
|
|
3384
3133
|
if (Array.isArray(existing) || Array.isArray(incoming)) {
|
|
3385
|
-
throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(
|
|
3134
|
+
throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
|
|
3386
3135
|
}
|
|
3387
3136
|
if (isNonNullObject(existing) &&
|
|
3388
3137
|
isNonNullObject(incoming)) {
|
|
@@ -3410,123 +3159,396 @@ function makeMergeObjectsFunction(store) {
|
|
|
3410
3159
|
return incoming;
|
|
3411
3160
|
};
|
|
3412
3161
|
}
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
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);
|
|
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
|
+
});
|
|
3238
|
+
}
|
|
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
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
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));
|
|
3305
|
+
}
|
|
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));
|
|
3312
|
+
}
|
|
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);
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
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;
|
|
3339
|
+
}
|
|
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); });
|
|
3345
|
+
}
|
|
3346
|
+
else {
|
|
3347
|
+
context.incomingById.set(dataId, {
|
|
3348
|
+
storeObject: incoming,
|
|
3349
|
+
mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
|
|
3350
|
+
fieldNodeSet: fieldNodeSet,
|
|
3351
|
+
});
|
|
3352
|
+
}
|
|
3353
|
+
return dataRef;
|
|
3419
3354
|
}
|
|
3420
|
-
return
|
|
3355
|
+
return incoming;
|
|
3421
3356
|
};
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
var aliasMap;
|
|
3427
|
-
if (context.selectionSet && context.fragmentMap) {
|
|
3428
|
-
var info = trie$1.lookupArray([
|
|
3429
|
-
context.selectionSet,
|
|
3430
|
-
context.fragmentMap,
|
|
3431
|
-
]);
|
|
3432
|
-
aliasMap = info.aliasMap || (info.aliasMap = makeAliasMap(context.selectionSet, context.fragmentMap));
|
|
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;
|
|
3433
3361
|
}
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
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
|
+
});
|
|
3368
|
+
}
|
|
3369
|
+
return this.processSelectionSet({
|
|
3370
|
+
result: value,
|
|
3371
|
+
selectionSet: field.selectionSet,
|
|
3372
|
+
context: context,
|
|
3373
|
+
mergeTree: mergeTree,
|
|
3374
|
+
});
|
|
3437
3375
|
};
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
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;
|
|
3451
3409
|
}
|
|
3410
|
+
fieldMap.set(selection, getContextFlavor(context, clientOnly, deferred));
|
|
3452
3411
|
}
|
|
3453
|
-
|
|
3454
|
-
var
|
|
3455
|
-
|
|
3456
|
-
|
|
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
|
+
}
|
|
3457
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];
|
|
3458
3432
|
}
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
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);
|
|
3463
3446
|
}
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
}
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
typeof lastResponseKey === "string") {
|
|
3479
|
-
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
|
+
});
|
|
3480
3461
|
}
|
|
3481
3462
|
}
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
__DEV__ ? tsInvariant.invariant(hasOwn.call(response, responseKey), "Missing field '" + responseKey + "' while extracting keyFields from " + JSON.stringify(response)) : tsInvariant.invariant(hasOwn.call(response, responseKey), 4);
|
|
3485
|
-
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));
|
|
3486
3465
|
}
|
|
3487
|
-
|
|
3488
|
-
|
|
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);
|
|
3489
3477
|
}
|
|
3490
|
-
function
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
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);
|
|
3525
3545
|
}
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
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");
|
|
3530
3552
|
}
|
|
3531
3553
|
|
|
3532
3554
|
var InMemoryCache = (function (_super) {
|
|
@@ -5503,7 +5525,7 @@ var QueryManager = (function () {
|
|
|
5503
5525
|
if (result !== false) {
|
|
5504
5526
|
results.set(oq, result);
|
|
5505
5527
|
}
|
|
5506
|
-
return
|
|
5528
|
+
return result;
|
|
5507
5529
|
}
|
|
5508
5530
|
if (onQueryUpdated !== null) {
|
|
5509
5531
|
includedQueriesById.set(oq.queryId, { oq: oq, lastDiff: lastDiff, diff: diff });
|
|
@@ -6301,63 +6323,79 @@ function useMutation(mutation, options) {
|
|
|
6301
6323
|
result: result,
|
|
6302
6324
|
mutationId: 0,
|
|
6303
6325
|
isMounted: true,
|
|
6326
|
+
execute: null,
|
|
6327
|
+
client: client,
|
|
6328
|
+
mutation: mutation,
|
|
6329
|
+
options: options,
|
|
6304
6330
|
});
|
|
6305
|
-
var execute = React.
|
|
6306
|
-
if (
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
var error = errors && errors.length > 0
|
|
6323
|
-
? new ApolloError({ graphQLErrors: errors })
|
|
6324
|
-
: void 0;
|
|
6325
|
-
if (mutationId === ref.current.mutationId &&
|
|
6326
|
-
!baseOptions.ignoreResults) {
|
|
6327
|
-
var result_1 = {
|
|
6328
|
-
called: true,
|
|
6329
|
-
loading: false,
|
|
6330
|
-
data: data,
|
|
6331
|
-
error: error,
|
|
6332
|
-
client: client,
|
|
6333
|
-
};
|
|
6334
|
-
if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
|
|
6335
|
-
setResult(ref.current.result = result_1);
|
|
6336
|
-
}
|
|
6337
|
-
}
|
|
6338
|
-
(_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
|
|
6339
|
-
return response;
|
|
6340
|
-
}).catch(function (error) {
|
|
6341
|
-
if (mutationId === ref.current.mutationId &&
|
|
6342
|
-
ref.current.isMounted) {
|
|
6343
|
-
var result_2 = {
|
|
6344
|
-
loading: false,
|
|
6345
|
-
error: error,
|
|
6331
|
+
var execute = React.useMemo(function () {
|
|
6332
|
+
if (ref.current.execute != null &&
|
|
6333
|
+
ref.current.client === client &&
|
|
6334
|
+
equality.equal(options, ref.current.options) &&
|
|
6335
|
+
equality.equal(mutation, ref.current.mutation)) {
|
|
6336
|
+
return ref.current.execute;
|
|
6337
|
+
}
|
|
6338
|
+
ref.current.client = client;
|
|
6339
|
+
ref.current.options = options;
|
|
6340
|
+
ref.current.mutation = mutation;
|
|
6341
|
+
ref.current.execute = function (executeOptions) {
|
|
6342
|
+
if (executeOptions === void 0) { executeOptions = {}; }
|
|
6343
|
+
var baseOptions = tslib.__assign(tslib.__assign({}, options), { mutation: mutation });
|
|
6344
|
+
if (!ref.current.result.loading && !baseOptions.ignoreResults) {
|
|
6345
|
+
setResult(ref.current.result = {
|
|
6346
|
+
loading: true,
|
|
6347
|
+
error: void 0,
|
|
6346
6348
|
data: void 0,
|
|
6347
6349
|
called: true,
|
|
6348
6350
|
client: client,
|
|
6349
|
-
};
|
|
6350
|
-
if (!equality.equal(ref.current.result, result_2)) {
|
|
6351
|
-
setResult(ref.current.result = result_2);
|
|
6352
|
-
}
|
|
6353
|
-
}
|
|
6354
|
-
if (baseOptions.onError) {
|
|
6355
|
-
baseOptions.onError(error);
|
|
6356
|
-
return { data: void 0, errors: error };
|
|
6351
|
+
});
|
|
6357
6352
|
}
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6353
|
+
var mutationId = ++ref.current.mutationId;
|
|
6354
|
+
var clientOptions = mergeOptions(baseOptions, executeOptions);
|
|
6355
|
+
return client.mutate(clientOptions).then(function (response) {
|
|
6356
|
+
var _a;
|
|
6357
|
+
var data = response.data, errors = response.errors;
|
|
6358
|
+
var error = errors && errors.length > 0
|
|
6359
|
+
? new ApolloError({ graphQLErrors: errors })
|
|
6360
|
+
: void 0;
|
|
6361
|
+
if (mutationId === ref.current.mutationId &&
|
|
6362
|
+
!baseOptions.ignoreResults) {
|
|
6363
|
+
var result_1 = {
|
|
6364
|
+
called: true,
|
|
6365
|
+
loading: false,
|
|
6366
|
+
data: data,
|
|
6367
|
+
error: error,
|
|
6368
|
+
client: client,
|
|
6369
|
+
};
|
|
6370
|
+
if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
|
|
6371
|
+
setResult(ref.current.result = result_1);
|
|
6372
|
+
}
|
|
6373
|
+
}
|
|
6374
|
+
(_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
|
|
6375
|
+
return response;
|
|
6376
|
+
}).catch(function (error) {
|
|
6377
|
+
if (mutationId === ref.current.mutationId &&
|
|
6378
|
+
ref.current.isMounted) {
|
|
6379
|
+
var result_2 = {
|
|
6380
|
+
loading: false,
|
|
6381
|
+
error: error,
|
|
6382
|
+
data: void 0,
|
|
6383
|
+
called: true,
|
|
6384
|
+
client: client,
|
|
6385
|
+
};
|
|
6386
|
+
if (!equality.equal(ref.current.result, result_2)) {
|
|
6387
|
+
setResult(ref.current.result = result_2);
|
|
6388
|
+
}
|
|
6389
|
+
}
|
|
6390
|
+
if (baseOptions.onError) {
|
|
6391
|
+
baseOptions.onError(error);
|
|
6392
|
+
return { data: void 0, errors: error };
|
|
6393
|
+
}
|
|
6394
|
+
throw error;
|
|
6395
|
+
});
|
|
6396
|
+
};
|
|
6397
|
+
return ref.current.execute;
|
|
6398
|
+
}, [client, mutation, options]);
|
|
6361
6399
|
var reset = React.useCallback(function () {
|
|
6362
6400
|
setResult({ called: false, loading: false, client: client });
|
|
6363
6401
|
}, []);
|