3

I am trying to upload user profile image using useMutation But I am getting 400 error while uploading.

here is my code.

File Input

<input type="file" multiple required onChange={onChange} />

onChange

 function onChange({ target: { validity, files } }: any) {
        if (validity.valid) {
            try {
                updateUserImage({
                    variables: { files: { upload: files[0] } },
                });
            } catch (error) {
                console.log(error);
            }
        }
    }

updateUserImage

const [updateUserImage] = useMutation(updateProfileImageQuery);

const updateProfileImageQuery = gql`
    mutation ($files: Upload!) {
        updateUser(
            data: { avatar: $files }
            where: { id: "ckx8qymsv0046iol87cszngcn" }
        ) {
            name
        }
    }
`;
DEV
  • 455
  • 4
  • 18

0 Answers0