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-08-27 11:52:29 +05:30
|
|
|
import { WIDGET_TYPE_LABELS } from '../constants';
|
2022-07-23 23:45:48 +05:30
|
|
|
import typeDefs from './typedefs.graphql';
|
|
|
|
import workItemQuery from './work_item.query.graphql';
|
|
|
|
|
|
|
|
export const temporaryConfig = {
|
|
|
|
typeDefs,
|
|
|
|
cacheConfig: {
|
|
|
|
possibleTypes: {
|
2022-08-27 11:52:29 +05:30
|
|
|
LocalWorkItemWidget: ['LocalWorkItemLabels'],
|
2022-07-23 23:45:48 +05:30
|
|
|
},
|
|
|
|
typePolicies: {
|
|
|
|
WorkItem: {
|
|
|
|
fields: {
|
|
|
|
mockWidgets: {
|
|
|
|
read(widgets) {
|
|
|
|
return (
|
|
|
|
widgets || [
|
|
|
|
{
|
2022-08-13 15:12:31 +05:30
|
|
|
__typename: 'LocalWorkItemLabels',
|
|
|
|
type: WIDGET_TYPE_LABELS,
|
|
|
|
allowScopedLabels: true,
|
|
|
|
nodes: [],
|
2022-07-23 23:45:48 +05:30
|
|
|
},
|
|
|
|
]
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2022-08-27 11:52:29 +05:30
|
|
|
widgets: {
|
|
|
|
merge(_, incoming) {
|
|
|
|
return incoming;
|
|
|
|
},
|
|
|
|
},
|
2022-07-23 23:45:48 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const resolvers = {
|
|
|
|
Mutation: {
|
|
|
|
localUpdateWorkItem(_, { input }, { cache }) {
|
|
|
|
const sourceData = cache.readQuery({
|
|
|
|
query: workItemQuery,
|
|
|
|
variables: { id: input.id },
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = produce(sourceData, (draftData) => {
|
2022-08-13 15:12:31 +05:30
|
|
|
if (input.labels) {
|
|
|
|
const labelsWidget = draftData.workItem.mockWidgets.find(
|
|
|
|
(widget) => widget.type === WIDGET_TYPE_LABELS,
|
|
|
|
);
|
|
|
|
labelsWidget.nodes = [...input.labels];
|
|
|
|
}
|
2022-07-23 23:45:48 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|