aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/handler.go
blob: b452d8287f34f9bab9a596640e427ff59fb82a2c (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.Backend
}

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

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

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

	return h, nil
}