v0.8.3 v0.13.0 master v0.12.2 v0.11.3 v0.10.2 v0.9.3


Using Gin to setup HTTP handlers
You are looking at the docs for an older version (v0.8.3). The latest version is v0.13.0.

Gin is an excellent alternative for the net/http router. From their official GitHub page:

Gin is a web framework written in Go (Golang). It features a martini-like API with much better performance, up to 40 times faster thanks to httprouter. If you need performance and good productivity, you will love Gin.

Here are the steps to setup Gin and gqlgen together:

Install Gin:

$ go get github.com/gin-gonic/gin

In your router file, define the handlers for the GraphQL and Playground endpoints in two different methods and tie then together in the Gin router:

import (

// 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.GraphQL(NewExecutableSchema(Config{Resolvers: &Resolver{}}))

	return func(c *gin.Context) {
		h.ServeHTTP(c.Writer, c.Request)

// Defining the Playground handler
func playgroundHandler() gin.HandlerFunc {
	h := handler.Playground("GraphQL", "/query")

	return func(c *gin.Context) {
		h.ServeHTTP(c.Writer, c.Request)

func main() {
    // Setting up Gin  
    r := gin.Default()
	r.POST("/query", graphqlHandler())
	r.GET("/", playgroundHandler())