aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/handler.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-29 18:58:42 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-29 18:58:42 +0200
commit8fa0b258ac89781dae269790a4bde09cbcd2f324 (patch)
treeb9bcf0826f5739f128de52123447cede23291c02 /graphql/handler.go
parent6363518c85cbd8247a5f6507b8a1dd3903cfb71d (diff)
downloadgit-bug-8fa0b258ac89781dae269790a4bde09cbcd2f324.tar.gz
cleaning
Diffstat (limited to 'graphql/handler.go')
-rw-r--r--graphql/handler.go42
1 files changed, 9 insertions, 33 deletions
diff --git a/graphql/handler.go b/graphql/handler.go
index 0f2aaad8..d1906dda 100644
--- a/graphql/handler.go
+++ b/graphql/handler.go
@@ -1,42 +1,18 @@
+//go:generate gorunpkg github.com/vektah/gqlgen
+
package graphql
import (
- "context"
- "net/http"
-
- "github.com/MichaelMure/git-bug/cache"
+ "github.com/MichaelMure/git-bug/graphql/resolvers"
"github.com/MichaelMure/git-bug/repository"
- graphqlHandler "github.com/graphql-go/handler"
+ "github.com/vektah/gqlgen/handler"
+ "net/http"
)
-type Handler struct {
- handler *graphqlHandler.Handler
- cache cache.Cacher
-}
-
-func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- ctx := context.WithValue(r.Context(), "cache", h.cache)
- h.handler.ContextHandler(ctx, w, r)
-}
-
-func NewHandler(repo repository.Repo) (*Handler, error) {
- schema, err := graphqlSchema()
-
- if err != nil {
- return nil, err
- }
-
- h := graphqlHandler.New(&graphqlHandler.Config{
- Schema: &schema,
- Pretty: true,
- GraphiQL: true,
- })
+func NewHandler(repo repository.Repo) http.Handler {
+ backend := resolvers.NewRootResolver()
- c := cache.NewCache()
- c.RegisterDefaultRepository(repo)
+ backend.RegisterDefaultRepository(repo)
- return &Handler{
- handler: h,
- cache: c,
- }, nil
+ return handler.GraphQL(resolvers.NewExecutableSchema(backend))
}