2018-08-14 15:48:41 +03:00
|
|
|
//go:generate go run gen_graphql.go
|
2018-07-29 19:58:42 +03:00
|
|
|
|
2018-09-16 14:50:53 +03:00
|
|
|
// Package graphql contains the root GraphQL http handler
|
2018-07-19 15:15:50 +03:00
|
|
|
package graphql
|
|
|
|
|
2018-07-20 01:25:30 +03:00
|
|
|
import (
|
2019-02-24 19:40:52 +03:00
|
|
|
"net/http"
|
|
|
|
|
2018-09-14 13:40:31 +03:00
|
|
|
"github.com/99designs/gqlgen/handler"
|
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-09-16 14:50:53 +03:00
|
|
|
// Handler is the root GraphQL http handler
|
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
|
|
|
}
|
|
|
|
|
2018-09-21 19:18:51 +03:00
|
|
|
func NewHandler(repo repository.ClockedRepo) (Handler, error) {
|
2018-08-21 19:46:53 +03:00
|
|
|
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-09-14 13:40:31 +03:00
|
|
|
config := graph.Config{
|
|
|
|
Resolvers: h.RootResolver,
|
|
|
|
}
|
|
|
|
|
|
|
|
h.HandlerFunc = handler.GraphQL(graph.NewExecutableSchema(config))
|
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
|
|
|
}
|