|
|
@ -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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
#graphiql {
|
|
|
|
These two files can be found in the npm module, however you may wish to
|
|
|
|
height: 100vh;
|
|
|
|
copy them directly into your environment, or perhaps include them in your
|
|
|
|
}
|
|
|
|
favored resource bundler.
|
|
|
|
</style>
|
|
|
|
-->
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
|
|
|
|
<!--
|
|
|
|
</head>
|
|
|
|
This GraphiQL example depends on Promise and fetch, which are available in
|
|
|
|
|
|
|
|
modern browsers, but can be "polyfilled" for older browsers.
|
|
|
|
<body>
|
|
|
|
GraphiQL itself depends on React DOM.
|
|
|
|
<div id="graphiql">Loading...</div>
|
|
|
|
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.
|
|
|
|
src="https://unpkg.com/graphiql/graphiql.min.js"
|
|
|
|
-->
|
|
|
|
type="application/javascript"
|
|
|
|
<script
|
|
|
|
></script>
|
|
|
|
crossorigin
|
|
|
|
<script>
|
|
|
|
src="https://unpkg.com/react@18/umd/react.development.js"
|
|
|
|
const root = ReactDOM.createRoot(document.getElementById('graphiql'));
|
|
|
|
></script>
|
|
|
|
root.render(
|
|
|
|
<script
|
|
|
|
React.createElement(GraphiQL, {
|
|
|
|
crossorigin
|
|
|
|
fetcher: GraphiQL.createFetcher({
|
|
|
|
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
|
|
|
|
url: 'http://localhost:8080/gql',
|
|
|
|
></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)
|
|
|
|