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

134
gql.go

@ -19,77 +19,77 @@ 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
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>GraphiQL</title>
<style>
body {
height: 100%;
margin: 0;
width: 100%;
overflow: hidden;
}
#graphiql {
height: 100vh;
}
</style>
<!-- <!--
This GraphiQL example depends on Promise and fetch, which are available in * Copyright (c) 2021 GraphQL Contributors
modern browsers, but can be "polyfilled" for older browsers. * All rights reserved.
GraphiQL itself depends on React DOM. *
If you do not want to rely on a CDN, you can host these files locally or * This source code is licensed under the license found in the
include them directly in your favored resource bundler. * LICENSE file in the root directory of this source tree.
--> -->
<script <!DOCTYPE html>
crossorigin <html lang="en">
src="https://unpkg.com/react@18/umd/react.development.js" <head>
></script> <title>GraphiQL</title>
<script <style>
crossorigin body {
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" height: 100%%;
></script> margin: 0;
width: 100%%;
<!-- overflow: hidden;
These two files can be found in the npm module, however you may wish to }
copy them directly into your environment, or perhaps include them in your
favored resource bundler. #graphiql {
--> height: 100vh;
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" /> }
</head> </style>
<body> <!--
<div id="graphiql">Loading...</div> This GraphiQL example depends on Promise and fetch, which are available in
<script modern browsers, but can be "polyfilled" for older browsers.
src="https://unpkg.com/graphiql/graphiql.min.js" GraphiQL itself depends on React DOM.
type="application/javascript" If you do not want to rely on a CDN, you can host these files locally or
></script> include them directly in your favored resource bundler.
<script> -->
const root = ReactDOM.createRoot(document.getElementById('graphiql')); <script
root.render( crossorigin
React.createElement(GraphiQL, { src="https://unpkg.com/react@18/umd/react.development.js"
fetcher: GraphiQL.createFetcher({ ></script>
url: 'http://localhost:8080/gql', <script
crossorigin
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
></script>
<!--
These two files can be found in the npm module, however you may wish to
copy them directly into your environment, or perhaps include them in your
favored resource bundler.
-->
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
</head>
<body>
<div id="graphiql">Loading...</div>
<script
src="https://unpkg.com/graphiql/graphiql.min.js"
type="application/javascript"
></script>
<script>
const root = ReactDOM.createRoot(document.getElementById('graphiql'));
root.render(
React.createElement(GraphiQL, {
fetcher: GraphiQL.createFetcher({
url: '%s/gql',
}),
defaultEditorToolsVisibility: true,
}), }),
defaultEditorToolsVisibility: true, );
}), </script>
); </body>
</script> </html>
</body> `, r.RequestURI)
</html>
`
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)