我正在尝试为帖子添加书签和取消收藏。突变取决于bookmarkId是否已经存在。新书签效果很好,然后取消书签效果很好,然后如果我尝试再次对同一帖子添加书签,则会收到错误消息:Error: GraphQL error: No Node for the model Bookmark with value cjn8j3ka0ktwl0b77katcw8eu for id found.
我试图重新获取所有帖子FEED_QUERY
,但仍然无法正常工作。我的按钮的突变:
<Mutation
mutation={bookmarkId ? UN_BOOKMARK_MUTATION : BOOKMARK_MUTATION}
variables={variables}
// refetchQueries={[{ query: FEED_QUERY }]}
update={(cache, payload) => {
const data = cache.readQuery({
query: ME_QUERY,
})
if (payload.data.createBookmark) {
const { createBookmark } = payload.data
data.me.bookmarks = [...data.me.bookmarks, createBookmark]
}
if (
payload.data.deleteBookmark &&
payload.data.deleteBookmark.id
) {
filledIcon = false
const { deleteBookmark } = payload.data
console.log('deleteBookmark', deleteBookmark)
data.me.bookmarks = data.me.bookmarks.filter(
bm => bm.id !== deleteBookmark.id,
)
}
console.log('data after', data)
cache.writeQuery({
query: ME_QUERY,
data,
})
}}
>
这里是repo