Created
July 14, 2019 17:44
-
-
Save cmelgarejo/7549ebca12f86b40183b2546865cc5f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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