我使用 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
}
})
}