Delete ModuleNode caches on class change

This commit is contained in:
Christian Cueni 2021-11-18 13:29:42 +01:00
parent 48e2a8a428
commit 3c4646bff6
3 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,3 @@
mutation {
deleteModuleNodes @client
}

View File

@ -34,5 +34,11 @@ export const resolvers = {
cache.writeQuery({query: SIDEBAR, data});
return data.sidebar;
},
deleteModuleNodes: (_, _query, {cache}) => {
Object.keys(cache.data.data)
.filter(prop => prop.indexOf('ModuleNode:') === 0)
.map(moduleName => cache.data.delete(moduleName)); // v3 uses .evict{id, fieldname}
return {success: true}
},
},
};

View File

@ -1,10 +1,12 @@
import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';
import UPDATE_USER_SETTING from '@/graphql/gql/mutations/updateUserSetting.gql';
import MY_SCHOOL_CLASS_QUERY from '@/graphql/gql/queries/mySchoolClass.gql';
import DELETE_MODULE_NODES from '@/graphql/gql/local/mutations/deleteModuleNodes.gql';
export default {
methods: {
updateSelectedClass(selectedClass) {
const innerApollo = this.$apollo;
return this.$apollo.mutate({
mutation: UPDATE_USER_SETTING,
variables: {
@ -18,6 +20,14 @@ export default {
meData.me.selectedClass = selectedClass;
store.writeQuery({query: ME_QUERY, data: meData});
innerApollo.mutate({
mutation: DELETE_MODULE_NODES,
variables: {
test: '',
}
})
},
refetchQueries: [{
query: MY_SCHOOL_CLASS_QUERY