-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathauth.html.twig
73 lines (69 loc) · 2.88 KB
/
auth.html.twig
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{% extends '@OverblogGraphiQL/GraphiQL/index.html.twig' %}
{% block style %}
{{ parent() }}
<style>
.x-header {
padding: 2px 4px;
}
</style>
{% endblock %}
{% block graphql_fetcher_headers %}
{{ parent() }}
{% block graphql_fetcher_headers_extra %}
let headerName = document.getElementById('x_header_name').value;
let token = getToken() || document.token || null;
if (headerName && token) {
headers[headerName] = token;
}
{% endblock graphql_fetcher_headers_extra %}
{% endblock graphql_fetcher_headers %}
{% block graphiql_render %}
let getToken = function () {
let field = document.getElementById('x_header_value');
return field ? field.value : null;
};
let renderPage = function () {
ReactDOM.render(
React.createElement('div', {style: {height: '100%'}},
React.createElement('div', {style: {background: '#f6f6f6', padding: '5px 15px'}},
React.createElement('select', {
id: 'x_header_name',
className: 'x-header',
style: {height: '24px'},
title: 'Header used for the authorization',
},
React.createElement('option', {value: 'Authorization'}, 'Authorization'),
React.createElement('option', {value: 'X-Auth-Token'}, 'X-Auth-Token'),
),
React.createElement('input', {
id: 'x_header_value',
type: 'text',
className: 'x-header',
placeholder: 'Set token (usually add prefix "Bearer" for "Authorization" header)',
style: {height: '16px', width: '400px'},
title: 'Header value (token) for the authorization',
value: getToken() || document.token || null,
}),
React.createElement('button', {
className: 'x-header',
onClick: () => {
document.token = getToken();
document.body.innerHTML = '';
document.body.outerHTML = 'Loading...';
renderPage();
},
style: {height: '24px'},
title: 'Click the button to load schema when the token specified',
},
'Reload schema',
),
),
React.createElement(GraphiQL, {
fetcher: graphQLFetcher
}),
),
document.body,
);
};
renderPage();
{% endblock graphiql_render %}