UNPKG

1.54 kBJavaScriptView Raw
1import { isNonNullObject } from "./objects.js";
2import { isNonEmptyArray } from "./arrays.js";
3import { DeepMerger } from "./mergeDeep.js";
4export function isExecutionPatchIncrementalResult(value) {
5 return "incremental" in value;
6}
7export function isExecutionPatchInitialResult(value) {
8 return "hasNext" in value && "data" in value;
9}
10export function isExecutionPatchResult(value) {
11 return (isExecutionPatchIncrementalResult(value) ||
12 isExecutionPatchInitialResult(value));
13}
14// This function detects an Apollo payload result before it is transformed
15// into a FetchResult via HttpLink; it cannot detect an ApolloPayloadResult
16// once it leaves the link chain.
17export function isApolloPayloadResult(value) {
18 return isNonNullObject(value) && "payload" in value;
19}
20export function mergeIncrementalData(prevResult, result) {
21 var mergedData = prevResult;
22 var merger = new DeepMerger();
23 if (isExecutionPatchIncrementalResult(result) &&
24 isNonEmptyArray(result.incremental)) {
25 result.incremental.forEach(function (_a) {
26 var data = _a.data, path = _a.path;
27 for (var i = path.length - 1; i >= 0; --i) {
28 var key = path[i];
29 var isNumericKey = !isNaN(+key);
30 var parent_1 = isNumericKey ? [] : {};
31 parent_1[key] = data;
32 data = parent_1;
33 }
34 mergedData = merger.merge(mergedData, data);
35 });
36 }
37 return mergedData;
38}
39//# sourceMappingURL=incrementalResult.js.map
\No newline at end of file