我使用graphCool作为后端,但有一个错误,不会很快修复。
在delete
架构上制作mutation
File
将始终抛出此错误(不是什么大问题):
“GraphQL错误:糟糕。看起来像是内部服务器错误。请通过控制台(https://console.graph.cool)或通过电子邮件(support@graph.cool)与我们联系并提供您的请求ID:”
通话有效,但我需要在通话后访问update
功能,因为错误我无法访问。
两个解决方案:
1.捕获graphql错误,以便我可以达到update:
功能,我该怎么做?
2.不使用update:
功能更新商店,我该怎么做?
这是我的代码:
_deleteImageFile = async () => {
// THIS WORKS, BUT GET AN ERROR
const socialPostId = this.props.socialPost.id
// Tried to wrap the following in try catch without success
await this.props.deleteImageFileMutation({
variables: {
id: this.props.socialPost.image.id
}, //Error hits here "internal service error..."
update: (store) => { //This is never run because of error
console.log('this text will never log')
const userId = localStorage.getItem(GC_USER_ID)
const data = store.readQuery({query: ALL_SOCIAL_POSTS_QUERY,
variables: {
id: userId
}})
// Need to change the store here
store.writeQuery({query: ALL_SOCIAL_POSTS_QUERY, data,
variables: {
id: userId
}}).catch(res => { const errors = res.graphQLErrors; console.log(errors)})
//The catch was an attempt to fix it
}
})
}
答案 0 :(得分:2)
您可以尝试传递另一个虚拟变异,并在deleteImageFileMutation
抛出后执行此操作。
try {
await this.props.deleteImageFileMutation ...
} catch (e) {
// ...
} finally {
await this.props.dummyMutation ...
}