我有这个突变,我正在尝试访问 userErrors 但我无法获取代码或字段,并且消息是我唯一能得到的,还是我做错了什么?突变正在起作用,因为正在删除产品,但是当发生一些错误时,我需要进入代码或字段才能执行特定操作。
export const ITEM_REMOVED = gql`
mutation checkoutLineItemsReplace($lineItems: [CheckoutLineItemInput!] !, $checkoutId: ID!) {
checkoutLineItemsReplace(lineItems: $lineItems, checkoutId: $checkoutId) {
userErrors {
code
field
message
}
checkout {
...CheckoutFragment
}
}
}
${CHECKOUT_FRAGMENT}
`
const [mutationItemRemoved] = useMutation(ITEM_REMOVED)
// Item removed
const itemRemoved = (lineItems) => {
mutationItemRemoved({
variables: {
checkoutId: props.checkout.id,
lineItems,
},
}).then(r => {
console.log(r.data.checkoutLineItemsReplace.checkout)
props.updateCheckout(r.data.checkoutLineItemsReplace.checkout)
}).catch(error => {
console.log(error.code) // undefined
console.log(error.field) // undefined
console.log(error.message)
})
}