2022-07-23 23:45:48 +05:30
|
|
|
import produce from 'immer';
|
2021-12-11 22:18:48 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createDefaultClient from '~/lib/graphql';
|
2022-07-23 23:45:48 +05:30
|
|
|
import { WIDGET_TYPE_ASSIGNEE } from '../constants';
|
|
|
|
import typeDefs from './typedefs.graphql';
|
|
|
|
import workItemQuery from './work_item.query.graphql';
|
|
|
|
|
|
|
|
export const temporaryConfig = {
|
|
|
|
typeDefs,
|
|
|
|
cacheConfig: {
|
|
|
|
possibleTypes: {
|
|
|
|
LocalWorkItemWidget: ['LocalWorkItemAssignees'],
|
|
|
|
},
|
|
|
|
typePolicies: {
|
|
|
|
WorkItem: {
|
|
|
|
fields: {
|
|
|
|
mockWidgets: {
|
|
|
|
read(widgets) {
|
|
|
|
return (
|
|
|
|
widgets || [
|
|
|
|
{
|
|
|
|
__typename: 'LocalWorkItemAssignees',
|
|
|
|
type: 'ASSIGNEES',
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
__typename: 'UserCore',
|
|
|
|
id: 'gid://gitlab/User/1',
|
|
|
|
avatarUrl: '',
|
|
|
|
webUrl: '',
|
|
|
|
// eslint-disable-next-line @gitlab/require-i18n-strings
|
|
|
|
name: 'John Doe',
|
|
|
|
username: 'doe_I',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
__typename: 'UserCore',
|
|
|
|
id: 'gid://gitlab/User/2',
|
|
|
|
avatarUrl: '',
|
|
|
|
webUrl: '',
|
|
|
|
// eslint-disable-next-line @gitlab/require-i18n-strings
|
|
|
|
name: 'Marcus Rutherford',
|
|
|
|
username: 'ruthfull',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
__typename: 'LocalWorkItemWeight',
|
|
|
|
type: 'WEIGHT',
|
|
|
|
weight: 0,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const resolvers = {
|
|
|
|
Mutation: {
|
|
|
|
localUpdateWorkItem(_, { input }, { cache }) {
|
|
|
|
const sourceData = cache.readQuery({
|
|
|
|
query: workItemQuery,
|
|
|
|
variables: { id: input.id },
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = produce(sourceData, (draftData) => {
|
|
|
|
const assigneesWidget = draftData.workItem.mockWidgets.find(
|
|
|
|
(widget) => widget.type === WIDGET_TYPE_ASSIGNEE,
|
|
|
|
);
|
|
|
|
assigneesWidget.nodes = assigneesWidget.nodes.filter((assignee) =>
|
|
|
|
input.assigneeIds.includes(assignee.id),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
cache.writeQuery({
|
|
|
|
query: workItemQuery,
|
|
|
|
variables: { id: input.id },
|
|
|
|
data,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
export function createApolloProvider() {
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
const defaultClient = createDefaultClient(resolvers, temporaryConfig);
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
return new VueApollo({
|
|
|
|
defaultClient,
|
|
|
|
});
|
|
|
|
}
|