Skip to content

Instantly share code, notes, and snippets.

@sogko
Last active March 10, 2016 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sogko/07c3ac863e2ab144781b to your computer and use it in GitHub Desktop.
Save sogko/07c3ac863e2ab144781b to your computer and use it in GitHub Desktop.
Example of using graphql-go/handler with a custom JWT middleware
package main
import (
"net/http"
"log"
"github.com/graphql-go/handler"
"github.com/graphql-go/relay/examples/starwars"
)
func myJWTMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Implement your JWT authentication flow here
// ...
log.Println("JWT Request Authenticated OK")
next.ServeHTTP(w, r)
})
}
func main() {
graphqlHandler := handler.New(&handler.Config{
Schema: &starwars.Schema,
Pretty: true,
})
http.Handle("/graphql/", myJWTMiddleware(graphqlHandler))
http.ListenAndServe(":3000", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment