@@ 37,7 37,7 @@ import (
)
// Used by the graphql playground
-var schemaHTML template.HTML
+var cssStyle, schemaHTML template.HTML
// Service is the base accounts service struct
type Service struct {
@@ 133,14 133,19 @@ func (s *Service) GQLPlayground(c echo.Context) error {
}
formatter := html.New(html.WithClasses(true))
- style := styles.Get("monokai")
- var cssBuf bytes.Buffer
- cssw := bufio.NewWriter(&cssBuf)
- if err := formatter.WriteCSS(cssw, style); err != nil {
- return fmt.Errorf("Error generating schema HTML: %w", err)
+ style := styles.Get("monokailight")
+
+ if cssStyle == "" {
+ var cssBuf bytes.Buffer
+ cssw := bufio.NewWriter(&cssBuf)
+ if err := formatter.WriteCSS(cssw, style); err != nil {
+ return fmt.Errorf("Error generating schema HTML: %w", err)
+ }
+
+ cssw.Flush()
+ cssStyle = template.HTML(fmt.Sprintf("<style>%s</style>", cssBuf.String()))
}
- cssw.Flush()
- cssStyle := cssBuf.String()
+ gmap["style"] = cssStyle
if schemaHTML == "" {
lexer := lexers.Get("graphql")
@@ 156,11 161,9 @@ func (s *Service) GQLPlayground(c echo.Context) error {
if err != nil {
return fmt.Errorf("Error formatting schema: %w", err)
}
- schw.Flush()
- schemaHTML = template.HTML(
- fmt.Sprintf("<style>%s</style>%s", cssStyle, schemaBuf.String()),
- )
+ schw.Flush()
+ schemaHTML = template.HTML(schemaBuf.String())
}
gmap["schema"] = schemaHTML
@@ 227,9 230,7 @@ func (s *Service) GQLPlayground(c echo.Context) error {
}
resw.Flush()
- gmap["results"] = template.HTML(
- fmt.Sprintf("<style>%s</style>%s", cssStyle, resBuf.String()),
- )
+ gmap["results"] = template.HTML(resBuf.String())
return links.Render(c, http.StatusOK, "graphql.html", gmap)
}
@@ 3,6 3,7 @@
{{ define "main-class" }} center-content{{ end }}
{{ define "extrahead" }}
<link rel="stylesheet" href="{{ staticURL "css/codemirror.css" }}">
+{{ .style }}
{{ end }}
<section class="app-header" style="margin-top:25px;">
<h1 class="app-header__title">{{.pd.Title}}</h1>