我想知道如何删除分页列表中的项目,以便我始终显示相同数量的项目。我目前的方法不起作用(每次删除后列表变小):
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 })
}
})
}