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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
import produce from 'immer';
import VueApollo from 'vue-apollo';
import { defaultDataIdFromObject } from '@apollo/client/core';
import { concatPagination } from '@apollo/client/utilities';
import getIssueStateQuery from '~/issues/show/queries/get_issue_state.query.graphql';
import createDefaultClient from '~/lib/graphql';
import typeDefs from '~/work_items/graphql/typedefs.graphql';
import { WIDGET_TYPE_NOTES } from '~/work_items/constants';
import getWorkItemLinksQuery from '~/work_items/graphql/work_item_links.query.graphql';
import { findHierarchyWidgetChildren } from '~/work_items/utils';
import activeBoardItemQuery from 'ee_else_ce/boards/graphql/client/active_board_item.query.graphql';
export const config = {
typeDefs,
cacheConfig: {
// included temporarily until Vuex is removed from boards app
dataIdFromObject: (object) => {
// eslint-disable-next-line no-underscore-dangle
return object.__typename === 'BoardList' && !window.gon?.features?.apolloBoards
? object.iid
: defaultDataIdFromObject(object);
},
typePolicies: {
Project: {
fields: {
projectMembers: {
keyArgs: ['fullPath', 'search', 'relations', 'first'],
},
},
},
WorkItemWidgetNotes: {
fields: {
// If we add any key args, the discussions field becomes discussions({"filter":"ONLY_ACTIVITY","first":10}) and
// kills any possibility to handle it on the widget level without hardcoding a string.
discussions: {
keyArgs: false,
},
},
},
WorkItemWidgetProgress: {
fields: {
progress: {
// We want to show null progress as 0 as per https://gitlab.com/gitlab-org/gitlab/-/issues/386117
read(existing) {
return existing === null ? 0 : existing;
},
},
},
},
WorkItem: {
fields: {
// widgets policy because otherwise the subscriptions invalidate the cache
widgets: {
merge(existing = [], incoming, context) {
if (existing.length === 0) {
return incoming;
}
return existing.map((existingWidget) => {
const incomingWidget = incoming.find(
(w) => w.type && w.type === existingWidget.type,
);
// We don't want to override existing notes with empty widget on work item updates
if (incomingWidget?.type === WIDGET_TYPE_NOTES && !context.variables.pageSize) {
return existingWidget;
}
// we want to concat next page of discussions to the existing ones
if (incomingWidget?.type === WIDGET_TYPE_NOTES && context.variables.after) {
// concatPagination won't work because we were placing new widget here so we have to do this manually
return {
...incomingWidget,
discussions: {
...incomingWidget.discussions,
nodes: [
...existingWidget.discussions.nodes,
...incomingWidget.discussions.nodes,
],
},
};
}
return incomingWidget || existingWidget;
});
},
},
userPermissions: {
read(permission = {}) {
return {
...permission,
setWorkItemMetadata: false,
};
},
},
},
},
MemberInterfaceConnection: {
fields: {
nodes: concatPagination(),
},
},
...(window.gon?.features?.apolloBoards
? {
BoardList: {
fields: {
issues: {
keyArgs: ['filters'],
},
},
},
IssueConnection: {
merge(existing = { nodes: [] }, incoming, { args }) {
if (!args.after) {
return incoming;
}
return {
...incoming,
nodes: [...existing.nodes, ...incoming.nodes],
};
},
},
EpicList: {
fields: {
epics: {
keyArgs: ['filters'],
},
},
},
EpicConnection: {
merge(existing = { nodes: [] }, incoming, { args }) {
if (!args.after) {
return incoming;
}
return {
...incoming,
nodes: [...existing.nodes, ...incoming.nodes],
};
},
},
Group: {
fields: {
projects: {
keyArgs: ['includeSubgroups', 'search'],
},
descendantGroups: {
keyArgs: ['includeSubgroups', 'search'],
},
},
},
ProjectConnection: {
fields: {
nodes: concatPagination(),
},
},
GroupConnection: {
fields: {
nodes: concatPagination(),
},
},
Board: {
fields: {
epics: {
keyArgs: ['boardId'],
},
},
},
BoardEpicConnection: {
merge(existing = { nodes: [] }, incoming, { args }) {
if (!args.after) {
return incoming;
}
return {
...incoming,
nodes: [...existing.nodes, ...incoming.nodes],
};
},
},
}
: {}),
},
},
};
export const resolvers = {
Mutation: {
addHierarchyChild: (_, { id, workItem }, { cache }) => {
const queryArgs = { query: getWorkItemLinksQuery, variables: { id } };
const sourceData = cache.readQuery(queryArgs);
const data = produce(sourceData, (draftState) => {
findHierarchyWidgetChildren(draftState.workItem).push(workItem);
});
cache.writeQuery({ ...queryArgs, data });
},
removeHierarchyChild: (_, { id, workItem }, { cache }) => {
const queryArgs = { query: getWorkItemLinksQuery, variables: { id } };
const sourceData = cache.readQuery(queryArgs);
const data = produce(sourceData, (draftState) => {
const hierarchyChildren = findHierarchyWidgetChildren(draftState.workItem);
const index = hierarchyChildren.findIndex((child) => child.id === workItem.id);
hierarchyChildren.splice(index, 1);
});
cache.writeQuery({ ...queryArgs, data });
},
updateIssueState: (_, { issueType = undefined, isDirty = false }, { cache }) => {
const sourceData = cache.readQuery({ query: getIssueStateQuery });
const data = produce(sourceData, (draftData) => {
draftData.issueState = { issueType, isDirty };
});
cache.writeQuery({ query: getIssueStateQuery, data });
},
setActiveBoardItem(_, { boardItem }, { cache }) {
cache.writeQuery({
query: activeBoardItemQuery,
data: { activeBoardItem: boardItem },
});
return boardItem;
},
},
};
export const defaultClient = createDefaultClient(resolvers, config);
export const apolloProvider = new VueApollo({
defaultClient,
});
|