1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package graphql
import (
"context"
"net/http"
"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{
Handler: handler.New(&handler.Config{
Schema: &schema,
Pretty: true,
GraphiQL: true,
}),
Repo: repo,
}, nil
}
|