Add api server muxer

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-01-23 16:25:18 +01:00
parent baa038fa52
commit 7ab7fd2d04
6 changed files with 171 additions and 5 deletions

View File

@@ -16,10 +16,46 @@
package console_v1
import "github.com/getprobo/probo/pkg/probo"
import (
"net/http"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/getprobo/probo/pkg/api/console/v1/schema"
"github.com/getprobo/probo/pkg/probo"
"github.com/go-chi/chi/v5"
)
type (
Resolver struct {
svc *probo.Service
}
)
func NewMux() *chi.Mux {
r := chi.NewMux()
r.Get("/", playground.Handler("GraphQL", "/console/v1/query"))
r.Post("/query", graphql())
return r
}
func graphql() http.HandlerFunc {
es := schema.NewExecutableSchema(
schema.Config{
Resolvers: &Resolver{},
},
)
srv := handler.New(es)
srv.AddTransport(transport.Options{})
srv.AddTransport(transport.GET{})
srv.AddTransport(transport.POST{})
srv.AddTransport(transport.MultipartForm{})
srv.Use(extension.Introspection{})
return func(w http.ResponseWriter, r *http.Request) {
srv.ServeHTTP(w, r)
}
}