Skip to content

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