initial commit
This commit is contained in:
commit
1253955070
75 changed files with 13972 additions and 0 deletions
66
api/internal/transport/playground.go
Normal file
66
api/internal/transport/playground.go
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package transport
|
||||
|
||||
// playgroundHTML is a minimal query console served at GET /graphql when the
|
||||
// request carries no query. It is deliberately dependency-free: the API has no
|
||||
// front-end assets to ship, and this is enough to exercise the endpoint from a
|
||||
// browser during development.
|
||||
const playgroundHTML = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>go-places GraphQL</title>
|
||||
<style>
|
||||
:root { color-scheme: light dark; }
|
||||
body { font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; margin: 0; padding: 1.5rem; }
|
||||
h1 { font-size: 1rem; margin: 0 0 1rem; }
|
||||
textarea, pre { width: 100%; box-sizing: border-box; padding: .75rem; border: 1px solid #8884;
|
||||
border-radius: 6px; background: #0001; color: inherit; }
|
||||
textarea { min-height: 12rem; font: inherit; }
|
||||
button { margin: .75rem 0; padding: .5rem 1rem; font: inherit; cursor: pointer;
|
||||
border-radius: 6px; border: 1px solid #8886; background: #0002; color: inherit; }
|
||||
pre { min-height: 6rem; overflow: auto; }
|
||||
.row { display: flex; gap: .75rem; align-items: baseline; }
|
||||
.hint { opacity: .7; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>go-places GraphQL</h1>
|
||||
<div class="row">
|
||||
<label for="token">Bearer token</label>
|
||||
<input id="token" size="40" value="valid_token" style="font:inherit;padding:.4rem">
|
||||
<span class="hint">AUTH_MODE=dev accepts <code>valid_token</code></span>
|
||||
</div>
|
||||
<p><textarea id="q">query {
|
||||
places {
|
||||
id
|
||||
title
|
||||
coordinate { latitude longitude }
|
||||
images { id url badges { label confidence } }
|
||||
}
|
||||
}</textarea></p>
|
||||
<button id="run">Run</button>
|
||||
<pre id="out"></pre>
|
||||
<script>
|
||||
const q = document.getElementById('q');
|
||||
const out = document.getElementById('out');
|
||||
async function run() {
|
||||
out.textContent = 'running...';
|
||||
const headers = { 'Content-Type': 'application/json' };
|
||||
const token = document.getElementById('token').value.trim();
|
||||
if (token) headers['Authorization'] = 'Bearer ' + token;
|
||||
try {
|
||||
const res = await fetch('/graphql', {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({ query: q.value }),
|
||||
});
|
||||
out.textContent = JSON.stringify(await res.json(), null, 2);
|
||||
} catch (e) {
|
||||
out.textContent = 'request failed: ' + e;
|
||||
}
|
||||
}
|
||||
document.getElementById('run').addEventListener('click', run);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
Loading…
Add table
Add a link
Reference in a new issue