Updated gql.go to use requesturi

graph-rework
noah metz 2023-06-18 21:34:02 -06:00
parent 001614189f
commit 97e2e50fd5
1 changed files with 67 additions and 67 deletions

@ -19,7 +19,8 @@ import (
) )
func GraphiQLHandler() func(http.ResponseWriter, *http.Request) { func GraphiQLHandler() func(http.ResponseWriter, *http.Request) {
graphiql_string := ` return func(w http.ResponseWriter, r * http.Request) {
graphiql_string := fmt.Sprintf(`
<!-- <!--
* Copyright (c) 2021 GraphQL Contributors * Copyright (c) 2021 GraphQL Contributors
* All rights reserved. * All rights reserved.
@ -33,9 +34,9 @@ func GraphiQLHandler() func(http.ResponseWriter, *http.Request) {
<title>GraphiQL</title> <title>GraphiQL</title>
<style> <style>
body { body {
height: 100%; height: 100%%;
margin: 0; margin: 0;
width: 100%; width: 100%%;
overflow: hidden; overflow: hidden;
} }
@ -79,7 +80,7 @@ func GraphiQLHandler() func(http.ResponseWriter, *http.Request) {
root.render( root.render(
React.createElement(GraphiQL, { React.createElement(GraphiQL, {
fetcher: GraphiQL.createFetcher({ fetcher: GraphiQL.createFetcher({
url: 'http://localhost:8080/gql', url: '%s/gql',
}), }),
defaultEditorToolsVisibility: true, defaultEditorToolsVisibility: true,
}), }),
@ -87,9 +88,8 @@ func GraphiQLHandler() func(http.ResponseWriter, *http.Request) {
</script> </script>
</body> </body>
</html> </html>
` `, r.RequestURI)
return func(w http.ResponseWriter, r * http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
io.WriteString(w, graphiql_string) io.WriteString(w, graphiql_string)