Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RootObjectFn request body always empty #688

Open
gerardmrk opened this issue Mar 13, 2024 · 0 comments
Open

RootObjectFn request body always empty #688

gerardmrk opened this issue Mar 13, 2024 · 0 comments

Comments

@gerardmrk
Copy link

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.

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
        ...
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant