Gin: Gin and GraphQL.

Created on 27 Dec 2017  路  4Comments  路  Source: gin-gonic/gin

I'm building a new project in Golang world and I wanna try this amazing framework. What do you think about GraphQL?

Is it worth having a framework like Gin for this purpose?

If I search "graphql" in these issues nothing appears.

Most helpful comment

@mrkongo create the gin middleware:

package graphql

import (
    "github.com/go-ggz/ggz/schema"

    "github.com/gin-gonic/gin"
    "github.com/graphql-go/handler"
)

// Handler initializes the prometheus middleware.
func Handler() gin.HandlerFunc {
    // Creates a GraphQL-go HTTP handler with the defined schema
    h := handler.New(&handler.Config{
        Schema: &schema.Schema,
        Pretty: true,
    })

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

in router:

        g := e.Group("/graphql")
        g.Use(auth0.Check())
        {
            g.POST("", graphql.Handler())
        }

try it.

All 4 comments

I'm using Gin with GraphQL and it's work like a charm. You just need to create a custom handler to handle your graphql query.
I can provide you some example for the handler if you need.

@mrkongo create the gin middleware:

package graphql

import (
    "github.com/go-ggz/ggz/schema"

    "github.com/gin-gonic/gin"
    "github.com/graphql-go/handler"
)

// Handler initializes the prometheus middleware.
func Handler() gin.HandlerFunc {
    // Creates a GraphQL-go HTTP handler with the defined schema
    h := handler.New(&handler.Config{
        Schema: &schema.Schema,
        Pretty: true,
    })

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

in router:

        g := e.Group("/graphql")
        g.Use(auth0.Check())
        {
            g.POST("", graphql.Handler())
        }

try it.

Did Gin support subscription of GraphQL

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mdnight picture mdnight  路  3Comments

wangcn picture wangcn  路  3Comments

ccaza picture ccaza  路  3Comments

Bloomca picture Bloomca  路  3Comments

nxvl picture nxvl  路  3Comments