diff options
Diffstat (limited to 'graphql/handler.go')
-rw-r--r-- | graphql/handler.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/graphql/handler.go b/graphql/handler.go index 507cb508..b452d828 100644 --- a/graphql/handler.go +++ b/graphql/handler.go @@ -10,10 +10,22 @@ import ( "net/http" ) -func NewHandler(repo repository.Repo) http.Handler { - backend := resolvers.NewBackend() +type Handler struct { + http.HandlerFunc + *resolvers.Backend +} + +func NewHandler(repo repository.Repo) (Handler, error) { + h := Handler{ + Backend: resolvers.NewBackend(), + } + + err := h.Backend.RegisterDefaultRepository(repo) + if err != nil { + return Handler{}, err + } - backend.RegisterDefaultRepository(repo) + h.HandlerFunc = handler.GraphQL(graph.NewExecutableSchema(h.Backend)) - return handler.GraphQL(graph.NewExecutableSchema(backend)) + return h, nil } |