1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
import { isEqual } from 'lodash';
export default {
typePolicies: {
Query: {
fields: {
jobs: {
keyArgs: ['statuses'],
},
},
},
CiJobConnection: {
merge(existing = {}, incoming, { args = {} }) {
if (incoming.nodes) {
let nodes;
const areNodesEqual = isEqual(existing.nodes, incoming.nodes);
const statuses = Array.isArray(args.statuses) ? [...args.statuses] : args.statuses;
const { pageInfo } = incoming;
if (Object.keys(existing).length !== 0 && isEqual(existing?.statuses, args?.statuses)) {
if (areNodesEqual) {
if (incoming.pageInfo.hasNextPage) {
nodes = [...existing.nodes, ...incoming.nodes];
} else {
nodes = [...incoming.nodes];
}
} else {
if (!existing.pageInfo?.hasNextPage) {
nodes = [...incoming.nodes];
return {
nodes,
statuses,
pageInfo,
count: incoming.count,
};
}
nodes = [...existing.nodes, ...incoming.nodes];
}
} else {
nodes = [...incoming.nodes];
}
return {
nodes,
statuses,
pageInfo,
count: incoming.count,
};
}
return {
nodes: existing.nodes,
pageInfo: existing.pageInfo,
statuses: args.statuses,
};
},
},
},
};
|