Skip to content
This repository was archived by the owner on Feb 10, 2019. It is now read-only.

Commit c80b697

Browse files
authored
Merge pull request #218 from 4levels/feature/relay
Updated graphiql view template with latest version from master branch
2 parents 11ef6fb + 8ea1d49 commit c80b697

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src/resources/views/graphiql.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
<html>
33
<head>
44
<style>
5-
body {
5+
html, body {
66
height: 100%;
77
margin: 0;
8+
padding: 0;
89
width: 100%;
910
overflow: hidden;
1011
}
1112
#graphiql {
1213
height: 100vh;
1314
}
1415
</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>
2021
</head>
2122
<body>
2223
<div id="graphiql">Loading...</div>
@@ -73,22 +74,29 @@ function updateURL() {
7374
var newSearch = '?' + Object.keys(parameters).filter(function (key) {
7475
return Boolean(parameters[key]);
7576
}).map(function (key) {
76-
return encodeURIComponent(key) + '=' +
77-
encodeURIComponent(parameters[key]);
77+
return encodeURIComponent(key) + '=' + encodeURIComponent(parameters[key]);
7878
}).join('&');
7979
history.replaceState(null, null, newSearch);
8080
}
8181

8282
// Defines a GraphQL fetcher using the fetch API.
8383
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+
}
92100
});
93101
}
94102

0 commit comments

Comments
 (0)