Graphql更新缓存不要忘记__typename
By QQCif
手写Edge,console里面一直有warning: writeToStore: Missing field __typename,那我就加上咯,可以怎么试怎么不行。结果发现是漏了一个_,有两个_面壁一百次。
update: (proxy, { data: { createPost } }) => {
const data = proxy.readQuery({
query: POSTS_QUERY,
variables: {
input: {
authorNickname: this.getCurrentUserProfile.nickname
}
}
})
data.posts.edges.push({
node: createPost,
cursor: Buffer.from(createPost.id.toString()).toString('base64'),
__typename: 'PostEdge' // 注意这里
})
proxy.writeQuery({
query: POSTS_QUERY,
variables: {
input: {
authorNickname: this.getCurrentUserProfile.nickname
}
},
data
})
}