Fix cache bug

Fixes MS-507
This commit is contained in:
Ramon Wenger 2022-05-24 16:24:56 +02:00
parent e05edc0867
commit ddf5360c51
1 changed files with 21 additions and 12 deletions

View File

@ -16,20 +16,20 @@
export default { export default {
components: { components: {
Checkbox Checkbox,
}, },
apollo: { apollo: {
me: meQuery, me: meQuery,
module: moduleQuery module: moduleQuery,
}, },
data() { data() {
return { return {
me: { me: {
permissions: [] permissions: [],
}, },
module: {} module: {},
}; };
}, },
@ -39,7 +39,7 @@
}, },
slug() { slug() {
return this.$route.params.slug; return this.$route.params.slug;
} },
}, },
methods: { methods: {
@ -50,20 +50,29 @@
variables: { variables: {
input: { input: {
slug, slug,
enabled enabled,
} },
}, },
update(store, {data: {updateSolutionVisibility: {success, solutionsEnabled}}}) { update(store, {data: {updateSolutionVisibility: {success, solutionsEnabled}}}) {
if (success) { if (success) {
const id = `ModuleNode:${slug}`; // according to the documentation, this should be
// const id = `ModuleNode:${slug}`;
// see: https://www.apollographql.com/docs/react/caching/cache-interaction/#readfragment
// but in the actual cache, it's found like this
const id = `ModuleNode:{"slug":"${slug}"}`;
// there's an open issue on Stackoverflow here
// https://stackoverflow.com/questions/70264586/apollo-client-readfragment-with-custom-id-keyfields
const fragment = MODULE_FRAGMENT; const fragment = MODULE_FRAGMENT;
const data = store.readFragment({fragment, id}); const module = store.readFragment({fragment, id});
data.solutionsEnabled = solutionsEnabled; const data = {
solutionsEnabled,
...module,
};
store.writeFragment({fragment, data, id}); store.writeFragment({fragment, data, id});
} }
} },
}); });
} },
}, },
}; };
</script> </script>