I'm trying to use gqlgen with gin (https://github.com/gin-gonic/gin).
I'm using the code below but there is a question about the subscription endpoint.
package server
import (
"myProject/graphql"
"github.com/99designs/gqlgen/handler"
"github.com/gin-gonic/gin"
)
func Start() {
r := gin.Default()
r.GET("/query", gin.WrapH(handler.Playground("GraphQL playground", "/api")))
r.GET("/api", gin.WrapH(handler.GraphQL(graphql.NewExecutableSchema(graphql.Config{Resolvers: &graphql.Resolver{}}))))
r.POST("/api", gin.WrapH(handler.GraphQL(graphql.NewExecutableSchema(graphql.Config{Resolvers: &graphql.Resolver{}}))))
r.Run()
}
As you can see I need to repeat the lines:
r.GET("/api", gin.WrapH(handler.GraphQL(graphql.NewExecutableSchema(graphql.Config{Resolvers: &graphql.Resolver{}}))))
r.POST("/api", gin.WrapH(handler.GraphQL(graphql.NewExecutableSchema(graphql.Config{Resolvers: &graphql.Resolver{}}))))
Is this correct?
Is there a way to have two separate handlers: one for graphql engine and one for subscriptions engine?
Also because in the future I'll need two separate endpoint. And from what I can see here: https://github.com/99designs/gqlgen/blob/4bda3bc1291bdc0bc44e3057b5229d987eeecde2/handler/playground.go#L25-L38
Today there isn't a way to change the default Playground subscriptionEndpoint?
Maybe a config like this below?
r.GET("/query", gin.WrapH(handler.Playground("GraphQL playground", "/api", "/subscriptions")))
You probably want to create the handler once and pass the same instance to all of them, otherwise you making copies of a bunch of internal state like the query cache.
gql := gin.WrapH(handler.GraphQL(graphql.NewExecutableSchema(graphql.Config{Resolvers: &graphql.Resolver{}})))
r.GET("/api", gql)
r.POST("/api", gql)
Why do you need to split the subscription endpoint out?
Most helpful comment
You probably want to create the handler once and pass the same instance to all of them, otherwise you making copies of a bunch of internal state like the query cache.
Why do you need to split the subscription endpoint out?