0
我想知道如何刪除分頁列表中的項目,以便始終顯示相同數量的項目。我目前的做法不工作(名單後,每個刪除變小):如何從Apollo中的分頁列表中刪除項目?
const GET_PAGINATED_POSTS = gql`
query postsBySize($page: Int!, $pageSize: Int!) {
postsPage(page: $page, size: $pageSize) {
_id
title
}
}
`;
deletePost() {
this.$apollo.mutate({
mutation: DELETE_POST,
variables: {
postId: this.post._id,
commentIds: this.post.comments.map(x => x._id)
},
update: (cache, { data: { deletePost } }) => {
const query = {
query: GET_PAGINATED_POSTS,
variables: {
page: 0,
pageSize: 10
},
};
const data = cache.readQuery({ ...query });
data.postsPage = data.postsPage.filter(post => post._id != this.post._id)
cache.writeQuery({ ...query, data })
}
})
}