jaydenseric / graphql-multipart-request-spec

A spec for GraphQL multipart form requests (file uploads).
993 stars 54 forks source link

You have to solve my problem. Please help me. #58

Closed siamahnaf closed 2 years ago

siamahnaf commented 2 years ago

Where I am wrong. Why getting again again 400 bad request. Please help. Here is the error image-

Screenshot 2021-10-18 132322

export const signUp = (data) => async (dispatch) => {
    console.log(data.picture[0].name);
    dispatch({type: SIGNUP_LOADING})
    var formData = new FormData();
    formData.append('operations', '{ "query": "mutation($file: Upload!) {signUp(avatar: $file, input: {name: "Siam Ahnaf", email: "siamahnaf198@yahoo.com", password: "siam1980"}){message, token}}", "variables": { "file": null } }');
    formData.append('map', '{ "0": ["variables.file"] }');
    formData.append('0', Image);
    await axios({
        url: "http://localhost:3001/graphql",
        method: "post",
        data: formData,
        Headers: {
            Accept: "application/json"
        }
    })
        .then(response => console.log(response))
        .catch(error => console.log(error));
}

I can't anything. Please, jaydenseric, I need your help. Please help me. Please. The mutation is worked in playground. Here is image- Screenshot 2021-10-18 131758

You have to help me. Please. Where I am wrong. 😌 Please please please.

jaydenseric commented 2 years ago

The error message is correct, and the answer is simple. The JSON you put in the operations field is invalid. You need to escape the " in the query with \".

siamahnaf commented 2 years ago

@jaydenseric I use this like-

'{ "query": "mutation($file: Upload!) {signUp(avatar: $file, input: {name: \"Siam Ahnaf\", email: \"siamahnaf198@yahoo.com\", password: \"siam1980"\}){message, token}}", "variables": { "file": null } }'

But throw the same error like image- Screenshot 2021-10-18 132322

siamahnaf commented 2 years ago

Hey @jaydenseric Please help me. I still can't solve the problem.