2018-08-14 15:48:41 +03:00
|
|
|
//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
|
|
|
|
|
2018-07-20 01:25:30 +03:00
|
|
|
import (
|
2018-07-30 00:48:52 +03:00
|
|
|
"github.com/MichaelMure/git-bug/graphql/graph"
|
2018-07-29 19:58:42 +03:00
|
|
|
"github.com/MichaelMure/git-bug/graphql/resolvers"
|
2018-07-20 01:25:30 +03:00
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
2018-07-29 19:58:42 +03:00
|
|
|
"github.com/vektah/gqlgen/handler"
|
|
|
|
"net/http"
|
2018-07-20 01:25:30 +03:00
|
|
|
)
|
|
|
|
|
2018-08-21 19:46:53 +03:00
|
|
|
type Handler struct {
|
|
|
|
http.HandlerFunc
|
2018-08-27 13:15:41 +03:00
|
|
|
*resolvers.RootResolver
|
2018-08-21 19:46:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewHandler(repo repository.Repo) (Handler, error) {
|
|
|
|
h := Handler{
|
2018-08-27 13:15:41 +03:00
|
|
|
RootResolver: resolvers.NewRootResolver(),
|
2018-08-21 19:46:53 +03:00
|
|
|
}
|
|
|
|
|
2018-08-27 13:15:41 +03:00
|
|
|
err := h.RootResolver.RegisterDefaultRepository(repo)
|
2018-08-21 19:46:53 +03:00
|
|
|
if err != nil {
|
|
|
|
return Handler{}, err
|
|
|
|
}
|
2018-07-25 22:26:25 +03:00
|
|
|
|
2018-08-27 13:15:41 +03:00
|
|
|
h.HandlerFunc = handler.GraphQL(graph.NewExecutableSchema(h.RootResolver))
|
2018-07-25 22:26:25 +03:00
|
|
|
|
2018-08-21 19:46:53 +03:00
|
|
|
return h, nil
|
2018-07-19 15:15:50 +03:00
|
|
|
}
|