aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/handler.go
diff options
context:
space:
mode:
Diffstat (limited to 'graphql/handler.go')
-rw-r--r--graphql/handler.go35
1 files changed, 27 insertions, 8 deletions
diff --git a/graphql/handler.go b/graphql/handler.go
index 7dbb7a0f..b49ca56b 100644
--- a/graphql/handler.go
+++ b/graphql/handler.go
@@ -1,17 +1,36 @@
package graphql
-import "github.com/graphql-go/handler"
+import (
+ "context"
+ "net/http"
-func NewHandler() (*handler.Handler, error) {
- schema, err := newGraphqlSchema()
+ "github.com/MichaelMure/git-bug/repository"
+ "github.com/graphql-go/handler"
+)
+
+type Handler struct {
+ Handler *handler.Handler
+ Repo repository.Repo
+}
+
+func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ ctx := context.WithValue(r.Context(), "repo", h.Repo)
+ h.Handler.ContextHandler(ctx, w, r)
+}
+
+func NewHandler(repo repository.Repo) (*Handler, error) {
+ schema, err := graphqlSchema()
if err != nil {
return nil, err
}
- return handler.New(&handler.Config{
- Schema: &schema,
- Pretty: true,
- GraphiQL: true,
- }), nil
+ return &Handler{
+ Handler: handler.New(&handler.Config{
+ Schema: &schema,
+ Pretty: true,
+ GraphiQL: true,
+ }),
+ Repo: repo,
+ }, nil
}