Skip to content

Commit

Permalink
Altair Playground updated to version 8.1.3 and configuration input ad…
Browse files Browse the repository at this point in the history
…ded. (#3485)

* altair options added

* Update go.mod

* Update altair_playground.go

* Update altair_playground.go

* Update altair_playground.go

* Update altair_playground.go

* Update altair_playground.go

* update version

* sha

* Update altair_playground.go

* revert

* jsonOptions

* fix tests

* revert and alter test

* Update graphql/playground/altair_playground.go

---------

Co-authored-by: Steve Coffman <[email protected]>
  • Loading branch information
reginbald and StevenACoffman authored Jan 15, 2025
1 parent 83e3979 commit 7b1908e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
22 changes: 15 additions & 7 deletions graphql/playground/altair_playground.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package playground

import (
"encoding/json"
"html/template"
"net/http"
)
Expand Down Expand Up @@ -55,27 +56,34 @@ var altairPage = template.Must(template.New("altair").Parse(`<!doctype html>
endpointURL: url,
subscriptionsEndpoint: subscriptionUrl,
};
var options = {...altairOptions, ...JSON.parse({{.options}})};
window.addEventListener("load", function() {
AltairGraphQL.init(altairOptions);
AltairGraphQL.init(options);
});
</script>
</body>
</html>`))

// AltairHandler responsible for setting up the altair playground
func AltairHandler(title, endpoint string) http.HandlerFunc {
func AltairHandler(title, endpoint string, options map[string]any) http.HandlerFunc {
jsonOptions, err := json.Marshal(options)
if err != nil {
jsonOptions = []byte("{}")
}

return func(w http.ResponseWriter, r *http.Request) {
err := altairPage.Execute(w, map[string]any{
"title": title,
"endpoint": endpoint,
"endpointIsAbsolute": endpointHasScheme(endpoint),
"subscriptionEndpoint": getSubscriptionEndpoint(endpoint),
"version": "5.0.5",
"cssSRI": "sha256-kZ35e5mdMYN5ALEbnsrA2CLn85Oe4hBodfsih9BqNxs=",
"mainSRI": "sha256-nWdVTcGTlBDV1L04UQnqod+AJedzBCnKHv6Ct65liHE=",
"polyfillsSRI": "sha256-1aVEg2sROcCQ/RxU3AlcPaRZhZdIWA92q2M+mdd/R4c=",
"runtimeSRI": "sha256-cK2XhXqQr0WS1Z5eKNdac0rJxTD6miC3ubd+aEVMQDk=",
"version": "8.1.3",
"cssSRI": "sha256-aYcodhWPcqIHh2lLDWeoq+irtg7qkWLLLK30gjQJZc8=",
"mainSRI": "sha256-bjpcMy7w3aaX8Cjuyv5hPE9FlkJRys0kxooPRtbGd8c=",
"polyfillsSRI": "sha256-+hQzPqfWEkAfOfKytrW7hLceq0mUR3pHXn+UzwhrWQ0=",
"runtimeSRI": "sha256-2SHK1nFbucnnM02VXrl4CAKDYQbJEF9HVZstRkVbkJM=",
"options": string(jsonOptions),
})
if err != nil {
panic(err)
Expand Down
3 changes: 2 additions & 1 deletion graphql/playground/altair_playground_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package playground

import (
"net/http"
"testing"
)

func TestAltairHandler_Integrity(t *testing.T) {
testResourceIntegrity(t, AltairHandler)
testResourceIntegrity(t, func(title, endpoint string) http.HandlerFunc { return AltairHandler(title, endpoint, nil) })
}

0 comments on commit 7b1908e

Please sign in to comment.