Move gql handler out of main, improve admin route matching

This commit is contained in:
David Stotijn
2022-02-28 09:23:08 +01:00
parent f15438e10b
commit fa3f24eb70
2 changed files with 53 additions and 24 deletions

21
pkg/api/http.go Normal file
View File

@ -0,0 +1,21 @@
package api
import (
"net/http"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/gorilla/mux"
)
func HTTPHandler(resolver *Resolver, gqlEndpoint string) http.Handler {
router := mux.NewRouter().SkipClean(true)
router.Methods("POST").Handler(
handler.NewDefaultServer(NewExecutableSchema(Config{
Resolvers: resolver,
})),
)
router.Methods("GET").Handler(playground.Handler("GraphQL Playground", gqlEndpoint))
return router
}