Use `cache.identify` instead of manually creating a cache ID

This commit is contained in:
Ramon Wenger 2022-06-23 11:33:59 +02:00
parent 2fbd878387
commit 9f8464ff7b
1 changed files with 5 additions and 7 deletions

View File

@ -55,13 +55,11 @@
},
update(store, {data: {updateSolutionVisibility: {success, solutionsEnabled}}}) {
if (success) {
// 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
// https://www.apollographql.com/docs/react/caching/cache-interaction/#obtaining-an-objects-cache-id
const id = store.identify({
__typename: 'ModuleNode',
slug
});
const fragment = MODULE_FRAGMENT;
const module = store.readFragment({fragment, id});
const data = {