Last active
March 10, 2016 04:50
-
-
Save sogko/07c3ac863e2ab144781b to your computer and use it in GitHub Desktop.
Example of using graphql-go/handler with a custom JWT middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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