|
1 | 1 | <!DOCTYPE html>
|
2 | 2 | <html lang="en">
|
3 | 3 | <head>
|
4 |
| - <meta charset="utf-8"/> |
5 |
| - <meta name="robots" content="noindex"/> |
6 |
| - <meta name="referrer" content="origin"/> |
7 |
| - <meta name="viewport" content="width=device-width, initial-scale=1"/> |
8 |
| - <title>${pageTitle}</title> |
9 |
| - <style> |
10 |
| - body { |
11 |
| - height: 100vh; |
12 |
| - margin: 0; |
13 |
| - overflow: hidden; |
14 |
| - } |
15 |
| - |
16 |
| - #splash { |
17 |
| - color: #333; |
18 |
| - display: flex; |
19 |
| - flex-direction: column; |
20 |
| - font-family: system, -apple-system, "San Francisco", ".SFNSDisplay-Regular", "Segoe UI", Segoe, "Segoe WP", "Helvetica Neue", helvetica, "Lucida Grande", arial, sans-serif; |
21 |
| - height: 100vh; |
22 |
| - justify-content: center; |
23 |
| - text-align: center; |
24 |
| - } |
25 |
| - |
26 |
| - </style> |
27 |
| - |
28 |
| - <script src="${es6PromiseJsUrl}"></script> |
29 |
| - <script src="${fetchJsUrl}"></script> |
30 |
| - <script src="${reactJsUrl}"></script> |
31 |
| - <script src="${reactDomJsUrl}"></script> |
32 |
| - |
33 |
| - <link rel="stylesheet" href="${graphiqlCssUrl}"/> |
34 |
| - <link rel="icon" type="image/x-icon" href="${pageFavicon}"> |
35 |
| - <script src="${graphiqlJsUrl}"></script> |
36 |
| - <script src="${subscriptionsTransportWsBrowserClientUrl}"></script> |
37 |
| - <script src="${graphiqlSubscriptionsFetcherBrowserClientUrl}"></script> |
38 |
| -</head> |
39 |
| -<body> |
40 |
| -<div id="splash"> |
41 |
| - Loading… |
42 |
| -</div> |
43 |
| -<script> |
44 |
| - var editorThemeCss = '${editorThemeCss}' |
45 |
| - if (editorThemeCss !== '') { |
46 |
| - var link = document.createElement( "link" ); |
47 |
| - link.href = editorThemeCss; |
48 |
| - link.type = "text/css"; |
49 |
| - link.rel = "stylesheet"; |
50 |
| - link.media = "screen,print"; |
51 |
| - |
52 |
| - document.getElementsByTagName( "head" )[0].appendChild( link ); |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <meta name="robots" content="noindex" /> |
| 6 | + <meta name="referrer" content="origin" /> |
| 7 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 8 | + <title>${pageTitle}</title> |
| 9 | + <style> |
| 10 | + body { |
| 11 | + height: 100vh; |
| 12 | + margin: 0; |
| 13 | + overflow: hidden; |
53 | 14 | }
|
54 | 15 |
|
55 |
| - // Parse the search string to get url parameters. |
56 |
| - var search = window.location.search; |
57 |
| - var parameters = {}; |
58 |
| - search.substr(1).split('&').forEach(function (entry) { |
59 |
| - var eq = entry.indexOf('='); |
60 |
| - if (eq >= 0) { |
61 |
| - parameters[decodeURIComponent(entry.slice(0, eq))] = |
62 |
| - decodeURIComponent(entry.slice(eq + 1)); |
63 |
| - } |
64 |
| - }); |
65 |
| - |
66 |
| - // if variables was provided, try to format it. |
67 |
| - if (parameters.variables) { |
68 |
| - try { |
69 |
| - parameters.variables = JSON.stringify(JSON.parse(parameters.variables), null, 2); |
70 |
| - } catch (e) { |
71 |
| - // Do nothing, we want to display the invalid JSON as a string, rather |
72 |
| - // than present an error. |
73 |
| - } |
| 16 | + #splash { |
| 17 | + color: #333; |
| 18 | + display: flex; |
| 19 | + flex-direction: column; |
| 20 | + font-family: system, -apple-system, "San Francisco", ".SFNSDisplay-Regular", "Segoe UI", Segoe, "Segoe WP", "Helvetica Neue", helvetica, "Lucida Grande", arial, sans-serif; |
| 21 | + height: 100vh; |
| 22 | + justify-content: center; |
| 23 | + text-align: center; |
74 | 24 | }
|
75 | 25 |
|
76 |
| - // When the query and variables string is edited, update the URL bar so |
77 |
| - // that it can be easily shared |
78 |
| - function onEditQuery(newQuery) { |
79 |
| - parameters.query = newQuery; |
80 |
| - updateURL(); |
81 |
| - } |
| 26 | + </style> |
82 | 27 |
|
83 |
| - function onEditVariables(newVariables) { |
84 |
| - parameters.variables = newVariables; |
85 |
| - updateURL(); |
86 |
| - } |
87 |
| - |
88 |
| - function onEditOperationName(newOperationName) { |
89 |
| - parameters.operationName = newOperationName; |
90 |
| - updateURL(); |
91 |
| - } |
92 |
| - |
93 |
| - function updateURL() { |
94 |
| - var newSearch = '?' + Object.keys(parameters).filter(function (key) { |
95 |
| - return Boolean(parameters[key]); |
96 |
| - }).map(function (key) { |
97 |
| - return encodeURIComponent(key) + '=' + encodeURIComponent(parameters[key]); |
98 |
| - }).join('&'); |
99 |
| - history.replaceState(null, null, newSearch); |
100 |
| - } |
| 28 | + <script src="${es6PromiseJsUrl}"></script> |
| 29 | + <script src="${fetchJsUrl}"></script> |
| 30 | + <script src="${reactJsUrl}"></script> |
| 31 | + <script src="${reactDomJsUrl}"></script> |
101 | 32 |
|
102 |
| - var headers = ${headers}; |
103 |
| - |
104 |
| - // Defines a GraphQL fetcher using the fetch API. You're not required to |
105 |
| - // use fetch, and could instead implement graphQLFetcher however you like, |
106 |
| - // as long as it returns a Promise or Observable. |
107 |
| - function graphQLFetcher(graphQLParams) { |
108 |
| - // This example expects a GraphQL server at the path /graphql. |
109 |
| - // Change this to point wherever you host your GraphQL server. |
110 |
| - return fetch('${graphqlEndpoint}', { |
111 |
| - method: 'post', |
112 |
| - headers: headers, |
113 |
| - body: JSON.stringify(graphQLParams), |
114 |
| - credentials: 'include' |
115 |
| - }).then(function (response) { |
116 |
| - return response.text(); |
117 |
| - }).then(function (responseBody) { |
118 |
| - try { |
119 |
| - return JSON.parse(responseBody); |
120 |
| - } catch (error) { |
121 |
| - return responseBody; |
122 |
| - } |
123 |
| - }); |
124 |
| - } |
125 |
| - |
126 |
| - var loc = window.location, newUri; |
127 |
| - |
128 |
| - if (loc.protocol === "https:") { |
129 |
| - newUri = "wss:"; |
130 |
| - } else { |
131 |
| - newUri = "ws:"; |
132 |
| - } |
133 |
| - newUri += "//" + loc.host; |
134 |
| - newUri += "${subscriptionsEndpoint}"; |
135 |
| - |
136 |
| - var subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient(newUri, { |
137 |
| - reconnect: ${subscriptionClientReconnect}, |
138 |
| - timeout: ${subscriptionClientTimeout} |
139 |
| - }); |
140 |
| - var subscriptionsFetcher = window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLFetcher); |
141 |
| - |
142 |
| - var props = ${props}; |
143 |
| - if (parameters.query) { |
144 |
| - props.query = parameters.query; |
145 |
| - } |
146 |
| - if (parameters.variables) { |
147 |
| - props.variables = parameters.variables; |
| 33 | + <link rel="stylesheet" href="${graphiqlCssUrl}" /> |
| 34 | + <link rel="icon" type="image/x-icon" href="${pageFavicon}"> |
| 35 | + <script src="${graphiqlJsUrl}"></script> |
| 36 | + <script src="${subscriptionsTransportWsBrowserClientUrl}"></script> |
| 37 | + <script src="${graphiqlSubscriptionsFetcherBrowserClientUrl}"></script> |
| 38 | +</head> |
| 39 | +<body> |
| 40 | +<div id="splash"> |
| 41 | + Loading… |
| 42 | +</div> |
| 43 | +<script> |
| 44 | + var editorThemeCss = '${editorThemeCss}' |
| 45 | + if (editorThemeCss !== '') { |
| 46 | + var link = document.createElement("link") |
| 47 | + link.href = editorThemeCss |
| 48 | + link.type = "text/css" |
| 49 | + link.rel = "stylesheet" |
| 50 | + link.media = "screen,print" |
| 51 | + |
| 52 | + document.getElementsByTagName("head")[0].appendChild(link) |
| 53 | + } |
| 54 | + |
| 55 | + // Parse the search string to get url parameters. |
| 56 | + var search = window.location.search |
| 57 | + var parameters = {} |
| 58 | + search.substr(1).split('&').forEach(function(entry) { |
| 59 | + var eq = entry.indexOf('=') |
| 60 | + if (eq >= 0) { |
| 61 | + parameters[decodeURIComponent(entry.slice(0, eq))] = |
| 62 | + decodeURIComponent(entry.slice(eq + 1)) |
148 | 63 | }
|
149 |
| - if (parameters.operationName) { |
150 |
| - props.operationName = parameters.operationName; |
| 64 | + }) |
| 65 | + |
| 66 | + // if variables was provided, try to format it. |
| 67 | + if (parameters.variables) { |
| 68 | + try { |
| 69 | + parameters.variables = JSON.stringify(JSON.parse(parameters.variables), null, 2) |
| 70 | + } catch (e) { |
| 71 | + // Do nothing, we want to display the invalid JSON as a string, rather |
| 72 | + // than present an error. |
151 | 73 | }
|
152 |
| - props.fetcher = subscriptionsFetcher; |
153 |
| - props.onEditQuery = onEditQuery; |
154 |
| - props.onEditVariables = onEditVariables; |
155 |
| - props.onEditOperationName = onEditOperationName; |
156 |
| - |
157 |
| - // Render <GraphiQL /> into the body. |
158 |
| - ReactDOM.render( |
159 |
| - React.createElement(GraphiQL, props), |
160 |
| - document.body |
161 |
| - ); |
| 74 | + } |
| 75 | + |
| 76 | + // When the query and variables string is edited, update the URL bar so |
| 77 | + // that it can be easily shared |
| 78 | + function onEditQuery(newQuery) { |
| 79 | + parameters.query = newQuery |
| 80 | + updateURL() |
| 81 | + } |
| 82 | + |
| 83 | + function onEditVariables(newVariables) { |
| 84 | + parameters.variables = newVariables |
| 85 | + updateURL() |
| 86 | + } |
| 87 | + |
| 88 | + function onEditOperationName(newOperationName) { |
| 89 | + parameters.operationName = newOperationName |
| 90 | + updateURL() |
| 91 | + } |
| 92 | + |
| 93 | + function updateURL() { |
| 94 | + var newSearch = '?' + Object.keys(parameters).filter(function(key) { |
| 95 | + return Boolean(parameters[key]) |
| 96 | + }).map(function(key) { |
| 97 | + return encodeURIComponent(key) + '=' + encodeURIComponent(parameters[key]) |
| 98 | + }).join('&') |
| 99 | + history.replaceState(null, null, newSearch) |
| 100 | + } |
| 101 | + |
| 102 | + var headers = ${headers} |
| 103 | + |
| 104 | + // Defines a GraphQL fetcher using the fetch API. You're not required to |
| 105 | + // use fetch, and could instead implement graphQLFetcher however you like, |
| 106 | + // as long as it returns a Promise or Observable. |
| 107 | + function graphQLFetcher(graphQLParams) { |
| 108 | + // This example expects a GraphQL server at the path /graphql. |
| 109 | + // Change this to point wherever you host your GraphQL server. |
| 110 | + return fetch('${graphqlEndpoint}', { |
| 111 | + method: 'post', |
| 112 | + headers: headers, |
| 113 | + body: JSON.stringify(graphQLParams), |
| 114 | + credentials: 'include' |
| 115 | + }).then(function(response) { |
| 116 | + return response.text() |
| 117 | + }).then(function(responseBody) { |
| 118 | + try { |
| 119 | + return JSON.parse(responseBody) |
| 120 | + } catch (error) { |
| 121 | + return responseBody |
| 122 | + } |
| 123 | + }) |
| 124 | + } |
| 125 | + |
| 126 | + var loc = window.location, newUri |
| 127 | + |
| 128 | + if (loc.protocol === "https:") { |
| 129 | + newUri = "wss:" |
| 130 | + } else { |
| 131 | + newUri = "ws:" |
| 132 | + } |
| 133 | + newUri += "//" + loc.host |
| 134 | + newUri += "${subscriptionsEndpoint}" |
| 135 | + |
| 136 | + var subscriptionsClient = new window.SubscriptionsTransportWs.SubscriptionClient(newUri, { |
| 137 | + reconnect: ${subscriptionClientReconnect}, |
| 138 | + timeout: ${subscriptionClientTimeout} |
| 139 | + }) |
| 140 | + var subscriptionsFetcher = window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLFetcher) |
| 141 | + |
| 142 | + var props = ${props} |
| 143 | + if (parameters.query) { |
| 144 | + props.query = parameters.query |
| 145 | + } |
| 146 | + if (parameters.variables) { |
| 147 | + props.variables = parameters.variables |
| 148 | + } |
| 149 | + if (parameters.operationName) { |
| 150 | + props.operationName = parameters.operationName |
| 151 | + } |
| 152 | + props.fetcher = subscriptionsFetcher |
| 153 | + props.onEditQuery = onEditQuery |
| 154 | + props.onEditVariables = onEditVariables |
| 155 | + props.onEditOperationName = onEditOperationName |
| 156 | + |
| 157 | + console.debug(props) |
| 158 | + // Render <GraphiQL /> into the body. |
| 159 | + ReactDOM.render( |
| 160 | + React.createElement(GraphiQL, props), |
| 161 | + document.body |
| 162 | + ) |
162 | 163 |
|
163 | 164 | </script>
|
164 | 165 | </body>
|
|
0 commit comments