aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/handler.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-25 21:26:25 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-25 21:27:50 +0200
commit074156634b47bfb6141f20a26ec38a386f9ba1b1 (patch)
tree2c98706539caddf853ef80c29a1b2ab35266e557 /graphql/handler.go
parent6706fa2bebcf5e1ff7001dbe82a9d79fa33ac096 (diff)
downloadgit-bug-074156634b47bfb6141f20a26ec38a386f9ba1b1.tar.gz
add a cache to support the graphql API and the future interactive CLI UI
Diffstat (limited to 'graphql/handler.go')
-rw-r--r--graphql/handler.go28
1 files changed, 17 insertions, 11 deletions
diff --git a/graphql/handler.go b/graphql/handler.go
index b49ca56b..89ef3801 100644
--- a/graphql/handler.go
+++ b/graphql/handler.go
@@ -4,18 +4,19 @@ import (
"context"
"net/http"
+ "github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/repository"
- "github.com/graphql-go/handler"
+ graphqlHandler "github.com/graphql-go/handler"
)
type Handler struct {
- Handler *handler.Handler
- Repo repository.Repo
+ handler *graphqlHandler.Handler
+ cache cache.Cache
}
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- ctx := context.WithValue(r.Context(), "repo", h.Repo)
- h.Handler.ContextHandler(ctx, w, r)
+ ctx := context.WithValue(r.Context(), "cache", h.cache)
+ h.handler.ContextHandler(ctx, w, r)
}
func NewHandler(repo repository.Repo) (*Handler, error) {
@@ -25,12 +26,17 @@ func NewHandler(repo repository.Repo) (*Handler, error) {
return nil, err
}
+ h := graphqlHandler.New(&graphqlHandler.Config{
+ Schema: &schema,
+ Pretty: true,
+ GraphiQL: true,
+ })
+
+ c := cache.NewDefaultCache()
+ c.RegisterDefaultRepository(repo)
+
return &Handler{
- Handler: handler.New(&handler.Config{
- Schema: &schema,
- Pretty: true,
- GraphiQL: true,
- }),
- Repo: repo,
+ handler: h,
+ cache: c,
}, nil
}