Unable to get the return of useMutations?

Viewed 21

I am trying to get the return of useMUtations using React.js and apollo-client but it does not work. Here is my code :

const Register = (props) => {
    const { register, handleSubmit, errors  } = useForm();
    const GET_ACTIVITY = gql`
    mutation register($username: String!, $email: String!, $password1: String!, $password2: String!){
    register(username: $username, email: $email, password1: $password1, password2: $password2){
    success,
    errors,
    token,
    refreshToken,
    } 
    }
    `;
  const [addchannel, {datas} ] = useMutation(GET_ACTIVITY);
  const onSubmit = data => {
    let username = data.Username;
    let email = data.Email;
    let password1= data.Password1;
    let password2 = data.Password2;
    addchannel({
        variables: {
            username: username,
            email: email,
            password1: password1,
            password2: password2,
        }
    }).then(r =>console.log(r.token)).catch(err => console.log(err.errors))

    }
return (...);}
export default Register;

I thought I will have the result using that line .then(r =>console.log(r.token)).catch(err => console.log(err.errors)) but without any effects unfortunately...

I don't understand why I don't achieve to get the following variables : success, errors, token, refreshToken.

I precise my query is working perfectly (I checked that in the database).

Could you help me please ?

0 Answers
Related