Skip to content

Instantly share code, notes, and snippets.

@cmelgarejo
Created July 14, 2019 17:44
Show Gist options
  • Save cmelgarejo/7549ebca12f86b40183b2546865cc5f6 to your computer and use it in GitHub Desktop.
Save cmelgarejo/7549ebca12f86b40183b2546865cc5f6 to your computer and use it in GitHub Desktop.
package handlers
import (
"github.com/99designs/gqlgen/handler"
"github.com/cmelgarejo/go-gql-server/internal/gql"
"github.com/cmelgarejo/go-gql-server/internal/gql/resolvers"
"github.com/gin-gonic/gin"
)
// GraphqlHandler defines the GQLGen GraphQL server handler
func GraphqlHandler() gin.HandlerFunc {
// NewExecutableSchema and Config are in the generated.go file
c := gql.Config{
Resolvers: &resolvers.Resolver{},
}
h := handler.GraphQL(gql.NewExecutableSchema(c))
return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}
}
// PlaygroundHandler Defines the Playground handler to expose our playground
func PlaygroundHandler(path string) gin.HandlerFunc {
h := handler.Playground("Go GraphQL Server", path)
return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment