【发布时间】:2018-05-15 20:47:02
【问题描述】:
我使用graphCool 作为后端,但是有一个错误,短期内不会修复。
在File 架构上创建delete mutation总会抛出这个错误(没什么大不了的):
“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
}
})
}
【问题讨论】:
标签: error-handling graphql react-apollo graphcool