1 | import { isNonNullObject } from "./objects.js";
|
2 | import { isNonEmptyArray } from "./arrays.js";
|
3 | import { DeepMerger } from "./mergeDeep.js";
|
4 | export function isExecutionPatchIncrementalResult(value) {
|
5 | return "incremental" in value;
|
6 | }
|
7 | export function isExecutionPatchInitialResult(value) {
|
8 | return "hasNext" in value && "data" in value;
|
9 | }
|
10 | export function isExecutionPatchResult(value) {
|
11 | return (isExecutionPatchIncrementalResult(value) ||
|
12 | isExecutionPatchInitialResult(value));
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 | export function isApolloPayloadResult(value) {
|
18 | return isNonNullObject(value) && "payload" in value;
|
19 | }
|
20 | export 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 |
|
\ | No newline at end of file |