I'm trying to make a POST to a GraphQL server in a React Redux app.
retu (dispatch) => fetch(API_URL, {
method: 'POST',
body: JSON.stringify(query)
})
.then(response => response.json())
.then(json => dispatch({
type: CREATE_USER,
payload: json
}))
When I place a breakpoint in the response.json() part of the code and the browser pauses there, the network panel shows a 200 OK but no response and was me that my request is not finished yet.
The response object looks like this:
Response {
body: null,
bodyUsed: false,
headers: Headers,
ok: false,
status: 0,
statusText: "",
type: "opaque",
url: ""
}
The code never reaches the second then and the console shows an error SyntaxError: Unexpected end of input at SyntaxError.
When I let the rest of the code play out and check the network panel, my POST has completed successfully and retued the data I need.
I was wondering what's going on here? Why does the then function fire when the request is not yet done and the response body is null? How can I tell my code to wait until the request completes?
