I can not catch the error

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)

Is this a typo? should be <div

Moving this to App Development

Thanks. Fixed but did not help.

What renders? What errors are you getting in React? Do you see the error.message in the console?

Try {JSON.stringify(error)} inside your div. I think the error is an array and not an object?

Doesn’t render anything, only does console.log on line 51
The one in the error block
JSON.stringify(error) did not help

Still believe it is because error.message does not exist. Remove that div and put just a string there like you did for submitting that says “Error…” and add a console log with just the error.

I believe you are seeing the error on the page because it is literally what you are putting on the page idk? Maybe you don’t want the whole error stack, the response returns an error array of objects with the object has a message and path. Did into what from the error you actually want to display.



removed everything)