graphql-go / graphql-go/graphql
RootObjectFn request body always empty
- Dominant language
- Go
- Stars
- 10.1k
- Forks
- 845
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to access the top-level query's arguments (and other stuff) from child object resolvers. This was my attempt to pass them down through `p.Info.RootValue`. However, the request body is always empty. The content length however says otherwise.
```go
func GinHttpHandler() gin.HandlerFunc {
httpHandler := handler.New(&handler.Config{
Schema: &rootSchema,
Pretty: true,
GraphiQL: true,
Playground: true,
RootObjectFn: func(ctx context.Context, r *http.Request) map[string]interface{} {
rootObj := make(map[string]interface{})
bb, err := io.ReadAll(r.Body)
if err != nil {
log.Println(err)
}
rootObj[`raw_query`] = string(bb) // body always empty
rootObj[`content_length`] = r.ContentLength // always 2271
return rootObj
},
})
return func(ctx *gin.Context) {
httpHandler.ServeHTTP(ctx.Writer, ctx.Request)
}
}
```
The query itself always have a successful response:
```
// POST request body from Postman
{
service(id: "xxxxxxx") {
id
description
...
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.