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

Add way to set graphql.Params.RootObject via handler.Config #9

Closed
wants to merge 1 commit into from

Conversation

nossila
Copy link

@nossila nossila commented Apr 20, 2016

I wanted to have http.ResponseWriter and http.Request within my relay.MutationConfig .MutateAndGetPayload and graphql.Field.Resolve methods. The main reason is that I needed to write and read cookies for authentication reasons.

Looking on #1 and #7 seems like there are other cases where this PR would be helpful. In my case with this changes I just needed to write a very single http handler to have access to both http.ResponseWriter and http.Request anywhere:

func requestResponseOnRootObject(h *handler.Handler) func(http.ResponseWriter, *http.Request) {
    return func(w http.ResponseWriter, r *http.Request) {
        h.RootObject = map[string]interface{}{
            "w": w,
            "r": r,
        }
        h.ServeHTTP(w, r)
    }
}

graphqlHandler := handler.New(&handler.Config{
    Schema: schema.GetSchema(),
    Pretty: true,
})
http.Handle("/graphql", requestResponseOnRootObject(graphqlHandler))

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 94.545% when pulling d86c8a0 on nossila:master into 52e6de4 on graphql-go:master.

@chris-ramon
Copy link
Member

Thanks a lot for your contribution @nossila 🌟 👍 — closing this one in favor of: #30

robdaemon pushed a commit to puppetlabs/handler that referenced this pull request Jul 10, 2018
Right now, there is no way to generate a default RootObject without forking this repo entirely.

This expands on graphql-go#9 by using a generator function for the root object, and graphql-go#30 by not changing any other contracts in the handler.
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

Successfully merging this pull request may close these issues.

3 participants