summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/graphql_shared/issuable_client.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/graphql_shared/issuable_client.js')
-rw-r--r--app/assets/javascripts/graphql_shared/issuable_client.js80
1 files changed, 79 insertions, 1 deletions
diff --git a/app/assets/javascripts/graphql_shared/issuable_client.js b/app/assets/javascripts/graphql_shared/issuable_client.js
index 01cc2fc3018..316bc746051 100644
--- a/app/assets/javascripts/graphql_shared/issuable_client.js
+++ b/app/assets/javascripts/graphql_shared/issuable_client.js
@@ -6,6 +6,8 @@ import getIssueStateQuery from '~/issues/show/queries/get_issue_state.query.grap
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';
export const config = {
typeDefs,
@@ -13,7 +15,9 @@ export const config = {
// included temporarily until Vuex is removed from boards app
dataIdFromObject: (object) => {
// eslint-disable-next-line no-underscore-dangle
- return object.__typename === 'BoardList' ? object.iid : defaultDataIdFromObject(object);
+ return object.__typename === 'BoardList' && !window.gon?.features?.apolloBoards
+ ? object.iid
+ : defaultDataIdFromObject(object);
},
typePolicies: {
Project: {
@@ -72,6 +76,7 @@ export const config = {
},
};
}
+
return incomingWidget || existingWidget;
});
},
@@ -83,12 +88,85 @@ export const config = {
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],
+ };
+ },
+ },
+ 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) => {