// VulcanizeDB // Copyright © 2020 Vulcanize // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . package graphql import ( "bytes" "fmt" "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. type GraphiQL struct{} func respond(w http.ResponseWriter, body []byte, code int) { w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("X-Content-Type-Options", "nosniff") w.WriteHeader(code) _, _ = w.Write(body) } func errorJSON(msg string) []byte { buf := bytes.Buffer{} fmt.Fprintf(&buf, `{"error": "%s"}`, msg) return buf.Bytes() } func (h GraphiQL) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" { respond(w, errorJSON("only GET requests are supported"), http.StatusMethodNotAllowed) return } w.Header().Set("Content-Type", "text/html") w.Write(graphiql) } var graphiql = []byte(`
Loading...
`)