git-bug/graphql/handler.go

39 lines
805 B
Go
Raw Normal View History

//go:generate go run gen_graphql.go
2018-07-29 19:58:42 +03:00
2018-09-16 14:50:53 +03:00
// Package graphql contains the root GraphQL http handler
2018-07-19 15:15:50 +03:00
package graphql
import (
2019-02-24 19:40:52 +03:00
"net/http"
2018-09-14 13:40:31 +03:00
"github.com/99designs/gqlgen/handler"
"github.com/MichaelMure/git-bug/graphql/graph"
2018-07-29 19:58:42 +03:00
"github.com/MichaelMure/git-bug/graphql/resolvers"
"github.com/MichaelMure/git-bug/repository"
)
2018-09-16 14:50:53 +03:00
// Handler is the root GraphQL http handler
type Handler struct {
http.HandlerFunc
*resolvers.RootResolver
}
func NewHandler(repo repository.ClockedRepo) (Handler, error) {
h := Handler{
RootResolver: resolvers.NewRootResolver(),
}
err := h.RootResolver.RegisterDefaultRepository(repo)
if err != nil {
return Handler{}, err
}
2018-09-14 13:40:31 +03:00
config := graph.Config{
Resolvers: h.RootResolver,
}
h.HandlerFunc = handler.GraphQL(graph.NewExecutableSchema(config))
return h, nil
2018-07-19 15:15:50 +03:00
}