Fix delete mutation update
This commit is contained in:
parent
63d79894ae
commit
6d1eb48fe5
|
|
@ -84,6 +84,7 @@
|
|||
import {hidden} from '@/helpers/visibility';
|
||||
import {CONTENT_TYPE} from '@/consts/types';
|
||||
import PopoverLink from '@/components/ui/PopoverLink';
|
||||
import {removeAtIndex} from '@/graphql/immutable-operations';
|
||||
const ContentComponent = () => import(/* webpackChunkName: "content-components" */'@/components/content-blocks/ContentComponent');
|
||||
|
||||
const instruments = {
|
||||
|
|
@ -101,8 +102,8 @@
|
|||
default: () => ({})
|
||||
},
|
||||
parent: {
|
||||
type: String,
|
||||
default: ''
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
editMode: {
|
||||
type: Boolean,
|
||||
|
|
@ -219,19 +220,22 @@
|
|||
}
|
||||
},
|
||||
update(store, {data: {deleteContentBlock: {success}}}) {
|
||||
try {
|
||||
if (success) {
|
||||
const query = CHAPTER_QUERY;
|
||||
const variables = {
|
||||
id: parent
|
||||
id: parent.id
|
||||
};
|
||||
const {chapter} = store.readQuery({query, variables});
|
||||
const index = chapter.contentBlocks.findIndex(contentBlock => contentBlock.id === id);
|
||||
const contentBlocks = removeAtIndex(chapter.contentBlocks, index);
|
||||
const data = {
|
||||
chapter: {
|
||||
...chapter,
|
||||
contentBlocks
|
||||
}
|
||||
};
|
||||
const data = store.readQuery({query, variables});
|
||||
data.chapter.contentBlocks.splice(data.chapter.contentBlocks.findIndex(contentBlock => contentBlock.id === id), 1);
|
||||
store.writeQuery({query, variables, data});
|
||||
}
|
||||
} catch (e) {
|
||||
// Query did not exist in the cache, and apollo throws a generic Error. Do nothing
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue