stufflog graphql server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
1.1 KiB

package graph
import (
"git.aiterp.net/stufflog/server/database"
"git.aiterp.net/stufflog/server/graph/graphcore"
"git.aiterp.net/stufflog/server/graph/loaders"
"git.aiterp.net/stufflog/server/graph/resolvers"
"git.aiterp.net/stufflog/server/services"
"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/gin-gonic/gin"
)
//go:generate go run github.com/99designs/gqlgen --verbose --config gqlgen.yml
// New creates a new GraphQL schema.
func New(bundle services.Bundle, database database.Database) graphql.ExecutableSchema {
return graphcore.NewExecutableSchema(graphcore.Config{
Resolvers: &resolvers.Resolver{
Bundle: bundle,
Database: database,
},
})
}
func Gin(bundle services.Bundle, database database.Database) gin.HandlerFunc {
schema := New(bundle, database)
gqlHandler := handler.NewDefaultServer(schema)
return func(c *gin.Context) {
bundle.Auth.CheckGinSession(c)
c.Request = c.Request.WithContext(
loaders.ContextWithLoaders(
c.Request.Context(),
bundle.Auth.UserFromContext(c.Request.Context()),
database,
),
)
gqlHandler.ServeHTTP(c.Writer, c.Request)
}
}