
;; GraphQL playground API handler — returns raw text for innerHTML injection

(defhandler
  gql-parse-demo
  :path "/sx/(applications.(graphql.(api.parse-demo)))"
  :method :get
  :returns "text"
  (&key source)
  (if
    (or (nil? source) (empty? source))
    "<p class=\"text-sm text-gray-400 italic\">Enter a GraphQL query and click Parse.</p>"
    (let
      ((doc (gql-parse source)))
      (str
        "<div class=\"space-y-4\">"
        "<div><h4 class=\"text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2\">AST</h4>"
        "<pre class=\"bg-gray-900 text-green-400 p-4 rounded-lg text-sm overflow-x-auto\">"
        (escape (sx-serialize doc))
        "</pre></div>"
        "<div><h4 class=\"text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2\">Serialized</h4>"
        "<pre class=\"bg-gray-900 text-amber-400 p-4 rounded-lg text-sm overflow-x-auto\">"
        (escape (gql-serialize doc))
        "</pre></div></div>"))))
