Commit 9e3c7109 authored by David O'Regan's avatar David O'Regan

Update cache to be immutable

parent cf6e1344
<script>
import produce from 'immer';
import { s__ } from '~/locale';
import Todo from '~/sidebar/components/todo_toggle/todo.vue';
import createAlertTodoMutation from '../../graphql/mutations/alert_todo_create.mutation.graphql';
......@@ -109,12 +110,15 @@ export default {
});
},
updateCache(store) {
const data = store.readQuery({
const sourceData = store.readQuery({
query: alertQuery,
variables: this.getAlertQueryVariables,
});
data.project.alertManagementAlerts.nodes[0].todos.nodes.shift();
const data = produce(sourceData, draftData => {
// eslint-disable-next-line no-param-reassign
draftData.project.alertManagementAlerts.nodes[0].todos.nodes = [];
});
store.writeQuery({
query: alertQuery,
......
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import produce from 'immer';
import { defaultDataIdFromObject } from 'apollo-cache-inmemory';
import createDefaultClient from '~/lib/graphql';
import createRouter from './router';
......@@ -16,8 +17,11 @@ export default selector => {
const resolvers = {
Mutation: {
toggleSidebarStatus: (_, __, { cache }) => {
const data = cache.readQuery({ query: sidebarStatusQuery });
data.sidebarStatus = !data.sidebarStatus;
const sourceData = cache.readQuery({ query: sidebarStatusQuery });
const data = produce(sourceData, draftData => {
// eslint-disable-next-line no-param-reassign
draftData.sidebarStatus = !draftData.sidebarStatus;
});
cache.writeQuery({ query: sidebarStatusQuery, data });
},
},
......@@ -34,6 +38,7 @@ export default selector => {
return defaultDataIdFromObject(object);
},
},
assumeImmutableResults: true,
}),
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment