diff options
author | Michael Muré <batolettre@gmail.com> | 2018-07-29 18:58:42 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-07-29 18:58:42 +0200 |
commit | 8fa0b258ac89781dae269790a4bde09cbcd2f324 (patch) | |
tree | b9bcf0826f5739f128de52123447cede23291c02 /graphql/handler.go | |
parent | 6363518c85cbd8247a5f6507b8a1dd3903cfb71d (diff) | |
download | git-bug-8fa0b258ac89781dae269790a4bde09cbcd2f324.tar.gz |
cleaning
Diffstat (limited to 'graphql/handler.go')
-rw-r--r-- | graphql/handler.go | 42 |
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)) } |