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}}}) { update(store, {data: {updateSolutionVisibility: {success, solutionsEnabled}}}) {
if (success) { if (success) {
// according to the documentation, this should be // https://www.apollographql.com/docs/react/caching/cache-interaction/#obtaining-an-objects-cache-id
// const id = `ModuleNode:${slug}`; const id = store.identify({
// see: https://www.apollographql.com/docs/react/caching/cache-interaction/#readfragment __typename: 'ModuleNode',
// but in the actual cache, it's found like this slug
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 module = store.readFragment({fragment, id}); const module = store.readFragment({fragment, id});
const data = { const data = {