Unhandled Rejection (Error): couldn’t rewrite mutation addUser because failed to rewrite mutation payload because id Eduard already exists for field user_name inside type User
Edward is the user I entered again.
mutation AddUser($user_name: String!, $phone: Int!, $email: String!,$role: String!, $image: String, $pwd: String = "")
{
addUser(input: {
user_name: $user_name,
phone: $phone,
email: $email,
role: $role,
image: $image,
pwd: $pwd
}) {
numUids
user {
user_name
}
}
}
type User @secret(field: "pwd") {
user_name: String! @search(by:[hash]) @id
email: String!
phone: Int!
role: String!
image: String
purchases: [Purchase] @hasInverse(field:buyer)
}
const [addUser, { data, loading, error }] = useMutation(ADD_USER);
if (loading) return 'Submitting...';
if (error) {
console.log("--------------------", error)
return < div style={{background: 'red'}}>Submission error! {error.message}</div>;
}
if (data) {
console.log("--------------------", error)
console.log(data.addUser.user[0])
userIsLogin(true)
authNameVar({name: data.addUser.user[0].user_name, pwd: pwd})
history.push(SHOP_ROUTE)
}
Enters error block, but an error is still generated and does not render < div style={{background: ‘red’}}>Submission error! {error.message}
This is fetch Data Using the useQuery Hook Apollo (Apollo Docs - Apollo GraphQL Docs)