package gql import ( "html/template" "net/http" ) // GraphiQL is an in-browser IDE for exploring GraphiQL APIs. // This handler returns GraphiQL when requested. // // For more information, see https://github.com/graphql/graphiql. func PlaygroundHandler(apiURL string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" { http.Error(w, "only GET requests are supported", http.StatusMethodNotAllowed) return } w.Header().Set("Content-Type", "text/html") err := page.Execute(w, map[string]interface{}{ "apiURL": apiURL, }) if err != nil { panic(err) } } } // https://github.com/graphql/graphiql/blob/main/examples/graphiql-cdn/index.html var page = template.Must(template.New("graphiql").Parse(` GraphiQL
Loading...
`))