-
Notifications
You must be signed in to change notification settings - Fork 2
/
graphql.html
42 lines (40 loc) · 1.43 KB
/
graphql.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<html>
<head><title>GraphQL</title></head>
<body>
<div>
Query: <br/>
<textarea type="textarea" id="query" cols="100" rows="20"></textarea>
</div>
<div>
Variables: <br/>
<textarea type="textarea" id="variables" cols="100" rows="10"></textarea>
</div>
<p><button id="send">Send</button></p>
<pre id="result"></pre>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
<script>
const token = new URL(window.location.href).searchParams.get('token');
if (!token) {
console.warn('Query string token is empty.');
}
document.getElementById('send').addEventListener('click', function() {
const query = document.getElementById('query').value;
const variables = document.getElementById('variables').value;
const headers = {
'Content-Type': 'application/json',
};
if (token) {
headers['Authorization'] = 'Bearer ' + token;
}
axios.post('https://api.github.com/graphql', {
query: query,
variables: variables && JSON.parse(variables),
}, {
headers: headers,
}).then(function (response) {
document.getElementById('result').innerHTML = JSON.stringify(response.data, null, 2);
});
});
</script>
</body>
</html>