git-bug/graphql/handler.go

32 lines
642 B
Go
Raw Normal View History

//go:generate go run gen_graphql.go
2018-07-29 19:58:42 +03:00
2018-07-19 15:15:50 +03:00
package graphql
import (
"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-07-29 19:58:42 +03:00
"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
2018-07-19 15:15:50 +03:00
}