-
Notifications
You must be signed in to change notification settings - Fork 135
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
Network Interface #11
Comments
@omgj, you can use a custom handler to have access for Just did a test case, hope it helps: |
After #24, you can implement a middleware (something like chi.Middleware or alice.Constructor), parse anything in the http.Request and pass along as context.Context with http.Request.WithContext(). For example, import (
"context"
"net/http"
"github.com/graphql-go/handler"
)
func main() {
// define GraphQL schema using relay library helpers
schema := graphql.NewSchema(...)
// apply middleware
h := func(inner http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// some kind of authentication here
user := parseJwtUser(r)
if !user.canDoGraphQL() {
// do something to tell the user
// ...
// ...
return
}
// do normal graphql
innerCtx := context.WithValue(r.Context(), "user", user)
inner.ServeHTTP(w, r.WithContext(innerCtx))
})
}(handler.New(&handler.Config{
Schema: &schema,
Pretty: true,
}))
// serve it to port 8080
http.Handle("/graphql", h)
http.ListenAndServe(":8080", nil)
} |
For authorization I need to send tokens inside an optional header configuration exposed on the graphql server. Unless I'm blind, or it's meant for the graphql-go package and not this one, I can't see it anywhere.
The text was updated successfully, but these errors were encountered: