From c8feb5ff75c78a9818e51c55e3d2dc628cb43477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Thu, 20 Oct 2022 17:32:42 +0200 Subject: [PATCH] server: Add setting to enable playground --- config/config.go | 14 ++++++++++++++ server.go | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/config/config.go b/config/config.go index db3293c..98bcacb 100644 --- a/config/config.go +++ b/config/config.go @@ -11,6 +11,7 @@ type Config struct { HTTPAddress string DBConnectionString string LogLevel string + EnablePlayground bool Admins []string Maps []string } @@ -25,6 +26,7 @@ func ReadConfig(path string) (*Config, error) { // Set default values config.HTTPAddress = "127.0.0.1:8080" config.LogLevel = "info" + config.EnablePlayground = false d := cfg.Get("http-address") if d != nil { @@ -48,6 +50,18 @@ func ReadConfig(path string) (*Config, error) { } } + d = cfg.Get("enable-playground") + if d != nil { + var enablePlayground string + if err := d.ParseParams(&enablePlayground); err != nil { + return nil, err + } + + if enablePlayground == "true" { + config.EnablePlayground = true + } + } + d = cfg.Get("admins") if d != nil { var admins string diff --git a/server.go b/server.go index e2922df..7611bc4 100644 --- a/server.go +++ b/server.go @@ -13,6 +13,7 @@ import ( "git.xenrox.net/~xenrox/10man-api/graph/generated" "git.xenrox.net/~xenrox/go-log" "github.com/99designs/gqlgen/graphql/handler" + "github.com/99designs/gqlgen/graphql/playground" ) func main() { @@ -47,6 +48,10 @@ func main() { }, })) + if cfg.EnablePlayground { + http.Handle("/", playground.Handler("GraphQL playground", "/query")) + logger.Infof("connect to http://%s/ for GraphQL playground", cfg.HTTPAddress) + } http.Handle("/query", srv) go func() { -- 2.44.0