2022-07-23 23:45:48 +05:30
|
|
|
import produce from 'immer';
|
2021-12-11 22:18:48 +05:30
|
|
|
import VueApollo from 'vue-apollo';
|
2022-10-11 01:57:18 +05:30
|
|
|
import { concatPagination } from '@apollo/client/utilities';
|
|
|
|
import getIssueStateQuery from '~/issues/show/queries/get_issue_state.query.graphql';
|
2021-12-11 22:18:48 +05:30
|
|
|
import createDefaultClient from '~/lib/graphql';
|
2022-10-11 01:57:18 +05:30
|
|
|
import typeDefs from '~/work_items/graphql/typedefs.graphql';
|
2022-11-25 23:54:43 +05:30
|
|
|
import { WIDGET_TYPE_MILESTONE } from '~/work_items/constants';
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
export const temporaryConfig = {
|
|
|
|
typeDefs,
|
|
|
|
cacheConfig: {
|
|
|
|
possibleTypes: {
|
2022-11-25 23:54:43 +05:30
|
|
|
LocalWorkItemWidget: ['LocalWorkItemMilestone'],
|
2022-07-23 23:45:48 +05:30
|
|
|
},
|
|
|
|
typePolicies: {
|
2022-10-11 01:57:18 +05:30
|
|
|
Project: {
|
|
|
|
fields: {
|
|
|
|
projectMembers: {
|
|
|
|
keyArgs: ['fullPath', 'search', 'relations', 'first'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-23 23:45:48 +05:30
|
|
|
WorkItem: {
|
|
|
|
fields: {
|
|
|
|
mockWidgets: {
|
|
|
|
read(widgets) {
|
|
|
|
return (
|
|
|
|
widgets || [
|
|
|
|
{
|
2022-11-25 23:54:43 +05:30
|
|
|
__typename: 'LocalWorkItemMilestone',
|
|
|
|
type: WIDGET_TYPE_MILESTONE,
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
dueDate: null,
|
|
|
|
expired: false,
|
|
|
|
id: 'gid://gitlab/Milestone/30',
|
|
|
|
title: 'v4.0',
|
|
|
|
// eslint-disable-next-line @gitlab/require-i18n-strings
|
|
|
|
__typename: 'Milestone',
|
|
|
|
},
|
|
|
|
],
|
2022-07-23 23:45:48 +05:30
|
|
|
},
|
|
|
|
]
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2022-08-27 11:52:29 +05:30
|
|
|
widgets: {
|
2022-11-25 23:54:43 +05:30
|
|
|
merge(existing = [], incoming) {
|
|
|
|
if (existing.length === 0) {
|
|
|
|
return incoming;
|
|
|
|
}
|
|
|
|
return existing.map((existingWidget) => {
|
|
|
|
const incomingWidget = incoming.find((w) => w.type === existingWidget.type);
|
|
|
|
return incomingWidget || existingWidget;
|
|
|
|
});
|
2022-08-27 11:52:29 +05:30
|
|
|
},
|
|
|
|
},
|
2022-07-23 23:45:48 +05:30
|
|
|
},
|
|
|
|
},
|
2022-10-11 01:57:18 +05:30
|
|
|
MemberInterfaceConnection: {
|
|
|
|
fields: {
|
|
|
|
nodes: concatPagination(),
|
|
|
|
},
|
|
|
|
},
|
2022-07-23 23:45:48 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const resolvers = {
|
|
|
|
Mutation: {
|
2022-10-11 01:57:18 +05:30
|
|
|
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 });
|
|
|
|
},
|
2022-07-23 23:45:48 +05:30
|
|
|
},
|
|
|
|
};
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
export const defaultClient = createDefaultClient(resolvers, temporaryConfig);
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
export const apolloProvider = new VueApollo({
|
|
|
|
defaultClient,
|
|
|
|
});
|