github.com/geneva/gqlgen@v0.17.7-0.20230801155730-7b9317164836/graphql/playground/apollo_sandbox_playground.go (about) 1 package playground 2 3 import ( 4 "html/template" 5 "net/http" 6 ) 7 8 var apolloSandboxPage = template.Must(template.New("ApolloSandbox").Parse(`<!doctype html> 9 <html> 10 11 <head> 12 <meta charset="utf-8"> 13 <title>{{.title}}</title> 14 <meta name="viewport" content="width=device-width,initial-scale=1"> 15 <link rel="icon" href="https://embeddable-sandbox.cdn.apollographql.com/_latest/public/assets/favicon-dark.png"> 16 <style> 17 body { 18 margin: 0; 19 overflow: hidden; 20 } 21 </style> 22 </head> 23 24 <body> 25 <div style="width: 100vw; height: 100vh;" id='embedded-sandbox'></div> 26 <!-- NOTE: New version available at https://embeddable-sandbox.cdn.apollographql.com/ --> 27 <script rel="preload" as="script" crossorigin="anonymous" integrity="{{.mainSRI}}" type="text/javascript" src="https://embeddable-sandbox.cdn.apollographql.com/7212121cad97028b007e974956dc951ce89d683c/embeddable-sandbox.umd.production.min.js"></script> 28 <script> 29 {{- if .endpointIsAbsolute}} 30 const url = {{.endpoint}}; 31 {{- else}} 32 const url = location.protocol + '//' + location.host + {{.endpoint}}; 33 {{- end}} 34 <!-- See https://www.apollographql.com/docs/graphos/explorer/sandbox/#options --> 35 new window.EmbeddedSandbox({ 36 target: '#embedded-sandbox', 37 initialEndpoint: url, 38 persistExplorerState: true, 39 initialState: { 40 includeCookies: true, 41 pollForSchemaUpdates: false, 42 } 43 }); 44 </script> 45 </body> 46 47 </html>`)) 48 49 // ApolloSandboxHandler responsible for setting up the altair playground 50 func ApolloSandboxHandler(title, endpoint string) http.HandlerFunc { 51 return func(w http.ResponseWriter, r *http.Request) { 52 err := apolloSandboxPage.Execute(w, map[string]interface{}{ 53 "title": title, 54 "endpoint": endpoint, 55 "endpointIsAbsolute": endpointHasScheme(endpoint), 56 "mainSRI": "sha256-ldbSJ7EovavF815TfCN50qKB9AMvzskb9xiG71bmg2I=", 57 }) 58 if err != nil { 59 panic(err) 60 } 61 } 62 }