1//go:generate go tool gqlgen generate
 2
 3// Package graphql contains the root GraphQL http handler
 4package graphql
 5
 6import (
 7	"io"
 8	"net/http"
 9
10	"github.com/99designs/gqlgen/graphql/handler"
11
12	"github.com/git-bug/git-bug/api/graphql/graph"
13	"github.com/git-bug/git-bug/api/graphql/resolvers"
14	"github.com/git-bug/git-bug/cache"
15)
16
17// Handler is the root GraphQL http handler
18type Handler struct {
19	http.Handler
20	io.Closer
21}
22
23func NewHandler(mrc *cache.MultiRepoCache, errorOut io.Writer) Handler {
24	rootResolver := resolvers.NewRootResolver(mrc)
25	config := graph.Config{Resolvers: rootResolver}
26	h := handler.NewDefaultServer(graph.NewExecutableSchema(config))
27
28	if errorOut != nil {
29		h.Use(&Tracer{Out: errorOut})
30	}
31
32	return Handler{
33		Handler: h,
34		Closer:  rootResolver,
35	}
36}