|
2 | 2 | <html>
|
3 | 3 | <head>
|
4 | 4 | <style>
|
5 |
| - body { |
| 5 | + html, body { |
6 | 6 | height: 100%;
|
7 | 7 | margin: 0;
|
| 8 | + padding: 0; |
8 | 9 | width: 100%;
|
9 | 10 | overflow: hidden;
|
10 | 11 | }
|
11 | 12 | #graphiql {
|
12 | 13 | height: 100vh;
|
13 | 14 | }
|
14 | 15 | </style>
|
15 |
| - <link rel="stylesheet" href="https://unpkg.com/graphiql@^0.7.8/graphiql.css" /> |
16 |
| - <script src="https://cdnjs.cloudflare.com/ajax/libs/superagent/3.3.2/superagent.min.js"></script> |
17 |
| - <script src="https://unpkg.com/react@^15.0/dist/react.min.js"></script> |
18 |
| - <script src="https://unpkg.com/react-dom@^15.0/dist/react-dom.min.js"></script> |
19 |
| - <script src="https://unpkg.com/graphiql@^0.7.8/graphiql.min.js"></script> |
| 16 | + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/graphiql/0.10.2/graphiql.min.css" /> |
| 17 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.min.js"></script> |
| 18 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react.min.js"></script> |
| 19 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react-dom.min.js"></script> |
| 20 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/graphiql/0.11.3/graphiql.min.js"></script> |
20 | 21 | </head>
|
21 | 22 | <body>
|
22 | 23 | <div id="graphiql">Loading...</div>
|
@@ -73,22 +74,29 @@ function updateURL() {
|
73 | 74 | var newSearch = '?' + Object.keys(parameters).filter(function (key) {
|
74 | 75 | return Boolean(parameters[key]);
|
75 | 76 | }).map(function (key) {
|
76 |
| - return encodeURIComponent(key) + '=' + |
77 |
| - encodeURIComponent(parameters[key]); |
| 77 | + return encodeURIComponent(key) + '=' + encodeURIComponent(parameters[key]); |
78 | 78 | }).join('&');
|
79 | 79 | history.replaceState(null, null, newSearch);
|
80 | 80 | }
|
81 | 81 |
|
82 | 82 | // Defines a GraphQL fetcher using the fetch API.
|
83 | 83 | function graphQLFetcher(graphQLParams) {
|
84 |
| - return new Promise(function(resolve, reject) { |
85 |
| - superagent.post('<?php echo $graphqlPath; ?>') |
86 |
| - .send(graphQLParams) |
87 |
| - .set('Accept', 'application/json') |
88 |
| - .set('Content-Type', 'application/json') |
89 |
| - .end(function(err, response) { |
90 |
| - resolve(response.body); |
91 |
| - }); |
| 84 | + return fetch('<?php echo $graphqlPath; ?>', { |
| 85 | + method: 'post', |
| 86 | + headers: { |
| 87 | + 'Accept': 'application/json', |
| 88 | + 'Content-Type': 'application/json', |
| 89 | + }, |
| 90 | + body: JSON.stringify(graphQLParams), |
| 91 | + credentials: 'include', |
| 92 | + }).then(function (response) { |
| 93 | + return response.text(); |
| 94 | + }).then(function (responseBody) { |
| 95 | + try { |
| 96 | + return JSON.parse(responseBody); |
| 97 | + } catch (error) { |
| 98 | + return responseBody; |
| 99 | + } |
92 | 100 | });
|
93 | 101 | }
|
94 | 102 |
|
|
0 commit comments