I've written a logger middleware which stores incoming GraphQL requests info. The problem is if I try to read the request body, I get the following 400 Bad Request:
{
"errors": [
{
"message": "json body could not be decoded: EOF"
}
],
"data": null
}
My code:
clonedReq := r.Clone(ctx)
data, _ := io.ReadAll(clonedReq.Body)
// store the data...
fmt.Println(string(data))
The data is displayed, but then I face the EOF error. If I comment this part out, the request is responded without any problems.
With or without a deep copy of the request with Clone
, the issue persists.