aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/handler.go
blob: 8448d1d27d335bd2b209352989ebc81513c30ec0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//go:generate go run gen_graphql.go

package graphql

import (
	"github.com/MichaelMure/git-bug/graphql/graph"
	"github.com/MichaelMure/git-bug/graphql/resolvers"
	"github.com/MichaelMure/git-bug/repository"
	"github.com/vektah/gqlgen/handler"
	"net/http"
)

type Handler struct {
	http.HandlerFunc
	*resolvers.RootResolver
}

func NewHandler(repo repository.Repo) (Handler, error) {
	h := Handler{
		RootResolver: resolvers.NewRootResolver(),
	}

	err := h.RootResolver.RegisterDefaultRepository(repo)
	if err != nil {
		return Handler{}, err
	}

	h.HandlerFunc = handler.GraphQL(graph.NewExecutableSchema(h.RootResolver))

	return h, nil
}