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

Updated graphiql view template with latest version from master branch #218

Merged
merged 1 commit into from
Oct 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/resources/views/graphiql.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
<html>
<head>
<style>
body {
html, body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
overflow: hidden;
}
#graphiql {
height: 100vh;
}
</style>
<link rel="stylesheet" href="https://unpkg.com/graphiql@^0.7.8/graphiql.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/superagent/3.3.2/superagent.min.js"></script>
<script src="https://unpkg.com/react@^15.0/dist/react.min.js"></script>
<script src="https://unpkg.com/react-dom@^15.0/dist/react-dom.min.js"></script>
<script src="https://unpkg.com/graphiql@^0.7.8/graphiql.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/graphiql/0.10.2/graphiql.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.4/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/graphiql/0.11.3/graphiql.min.js"></script>
</head>
<body>
<div id="graphiql">Loading...</div>
Expand Down Expand Up @@ -73,22 +74,29 @@ function updateURL() {
var newSearch = '?' + Object.keys(parameters).filter(function (key) {
return Boolean(parameters[key]);
}).map(function (key) {
return encodeURIComponent(key) + '=' +
encodeURIComponent(parameters[key]);
return encodeURIComponent(key) + '=' + encodeURIComponent(parameters[key]);
}).join('&');
history.replaceState(null, null, newSearch);
}

// Defines a GraphQL fetcher using the fetch API.
function graphQLFetcher(graphQLParams) {
return new Promise(function(resolve, reject) {
superagent.post('<?php echo $graphqlPath; ?>')
.send(graphQLParams)
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.end(function(err, response) {
resolve(response.body);
});
return fetch('<?php echo $graphqlPath; ?>', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(graphQLParams),
credentials: 'include',
}).then(function (response) {
return response.text();
}).then(function (responseBody) {
try {
return JSON.parse(responseBody);
} catch (error) {
return responseBody;
}
});
}

Expand Down