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

Update cache to be immutable

parent cf6e1344
<script> <script>
import produce from 'immer';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import Todo from '~/sidebar/components/todo_toggle/todo.vue'; import Todo from '~/sidebar/components/todo_toggle/todo.vue';
import createAlertTodoMutation from '../../graphql/mutations/alert_todo_create.mutation.graphql'; import createAlertTodoMutation from '../../graphql/mutations/alert_todo_create.mutation.graphql';
...@@ -109,12 +110,15 @@ export default { ...@@ -109,12 +110,15 @@ export default {
}); });
}, },
updateCache(store) { updateCache(store) {
const data = store.readQuery({ const sourceData = store.readQuery({
query: alertQuery, query: alertQuery,
variables: this.getAlertQueryVariables, 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({ store.writeQuery({
query: alertQuery, query: alertQuery,
......
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import produce from 'immer';
import { defaultDataIdFromObject } from 'apollo-cache-inmemory'; import { defaultDataIdFromObject } from 'apollo-cache-inmemory';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import createRouter from './router'; import createRouter from './router';
...@@ -16,8 +17,11 @@ export default selector => { ...@@ -16,8 +17,11 @@ export default selector => {
const resolvers = { const resolvers = {
Mutation: { Mutation: {
toggleSidebarStatus: (_, __, { cache }) => { toggleSidebarStatus: (_, __, { cache }) => {
const data = cache.readQuery({ query: sidebarStatusQuery }); const sourceData = cache.readQuery({ query: sidebarStatusQuery });
data.sidebarStatus = !data.sidebarStatus; const data = produce(sourceData, draftData => {
// eslint-disable-next-line no-param-reassign
draftData.sidebarStatus = !draftData.sidebarStatus;
});
cache.writeQuery({ query: sidebarStatusQuery, data }); cache.writeQuery({ query: sidebarStatusQuery, data });
}, },
}, },
...@@ -34,6 +38,7 @@ export default selector => { ...@@ -34,6 +38,7 @@ export default selector => {
return defaultDataIdFromObject(object); 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