authorizer/server/server.go
Lakhan Samani 27264c6e29
Implement login resolver (#15)
* add sign_up_method to users table

* add session store

* implement login resolver
2021-07-15 00:13:19 +05:30

48 lines
1.2 KiB
Go

package main
import (
"context"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/gin-gonic/gin"
"github.com/yauthdev/yauth/server/graph"
"github.com/yauthdev/yauth/server/graph/generated"
)
// Defining the Graphql handler
func graphqlHandler() gin.HandlerFunc {
// NewExecutableSchema and Config are in the generated.go file
// Resolver is in the resolver.go file
h := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}
}
// Defining the Playground handler
func playgroundHandler() gin.HandlerFunc {
h := playground.Handler("GraphQL", "/graphql")
return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}
}
func GinContextToContextMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
ctx := context.WithValue(c.Request.Context(), "GinContextKey", c)
c.Request = c.Request.WithContext(ctx)
c.Next()
}
}
func main() {
r := gin.Default()
r.Use(GinContextToContextMiddleware())
r.POST("/graphql", graphqlHandler())
r.GET("/", playgroundHandler())
r.Run()
}