~netlandish/links

8e956738b328d2b5d9d68eaccef854270fba045a — Peter Sanchez 20 days ago 5e97f1e
More graphql cleanup
2 files changed, 17 insertions(+), 15 deletions(-)

M core/routes.go
M templates/graphql.html
M core/routes.go => core/routes.go +16 -15
@@ 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)
}


M templates/graphql.html => templates/graphql.html +1 -0
@@ 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>