Skip to content

Commit b375146

Browse files
Empty2k12LegNeato
andauthored
Update GraphiQL (#1069)
* Update GraphiQL Source * pass through request headers from header box --------- Co-authored-by: Christian Legnitto <[email protected]>
1 parent 421c8c9 commit b375146

File tree

1 file changed

+46
-32
lines changed

1 file changed

+46
-32
lines changed

juniper/src/http/graphiql.rs

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ pub fn graphiql_source(
2020

2121
let stylesheet_source = r#"
2222
<style>
23-
html, body, #app {
24-
height: 100%;
25-
margin: 0;
26-
overflow: hidden;
27-
width: 100%;
28-
}
23+
body {
24+
height: 100%;
25+
margin: 0;
26+
width: 100%;
27+
overflow: hidden;
28+
}
29+
30+
#graphiql {
31+
height: 100vh;
32+
}
2933
</style>
3034
"#;
3135
let fetcher_source = r#"
@@ -50,33 +54,37 @@ pub fn graphiql_source(
5054
return null
5155
}
5256
53-
function graphQLFetcher(params) {
54-
return fetch(GRAPHQL_URL, {
55-
method: 'post',
56-
headers: {
57-
'Accept': 'application/json',
58-
'Content-Type': 'application/json',
57+
function graphQLFetcher(graphQLParams, opts) {
58+
const { headers = {} } = opts;
59+
60+
return fetch(
61+
GRAPHQL_URL,
62+
{
63+
method: 'post',
64+
headers: {
65+
Accept: 'application/json',
66+
'Content-Type': 'application/json',
67+
...headers,
68+
},
69+
body: JSON.stringify(graphQLParams),
70+
credentials: 'omit',
5971
},
60-
credentials: 'include',
61-
body: JSON.stringify(params)
62-
}).then(function (response) {
63-
return response.text();
64-
}).then(function (body) {
65-
try {
66-
return JSON.parse(body);
67-
} catch (error) {
68-
return body;
69-
}
72+
).then(function (response) {
73+
return response.json().catch(function () {
74+
return response.text();
75+
});
7076
});
7177
}
7278
7379
var fetcher = usingSubscriptions ? window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLFetcher) : graphQLFetcher;
7480
7581
ReactDOM.render(
7682
React.createElement(GraphiQL, {
77-
fetcher,
83+
fetcher,
84+
defaultVariableEditorOpen: true,
7885
}),
79-
document.querySelector('#app'));
86+
document.getElementById('graphiql'),
87+
);
8088
</script>
8189
"#;
8290

@@ -87,16 +95,22 @@ pub fn graphiql_source(
8795
<head>
8896
<title>GraphQL</title>
8997
{stylesheet_source}
90-
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/[email protected]/graphiql.min.css">
98+
<script
99+
crossorigin
100+
src="https://unpkg.com/react@17/umd/react.development.js"
101+
></script>
102+
<script
103+
crossorigin
104+
src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"
105+
></script>
106+
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
91107
</head>
92108
<body>
93-
<div id="app"></div>
94-
<script src="//cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>
95-
<script src="//unpkg.com/[email protected]/browser/client.js"></script>
96-
<script src="//unpkg.com/[email protected]/browser/client.js"></script>
97-
<script src="//cdnjs.cloudflare.com/ajax/libs/react/16.10.2/umd/react.production.min.js"></script>
98-
<script src="//cdnjs.cloudflare.com/ajax/libs/react-dom/16.10.2/umd/react-dom.production.min.js"></script>
99-
<script src="//cdn.jsdelivr.net/npm/[email protected]/graphiql.min.js"></script>
109+
<div id="graphiql">Loading...</div>
110+
<script
111+
src="https://unpkg.com/graphiql/graphiql.min.js"
112+
type="application/javascript"
113+
></script>
100114
<script>var GRAPHQL_URL = '{graphql_url}';</script>
101115
<script>var usingSubscriptions = {using_subscriptions};</script>
102116
<script>var GRAPHQL_SUBSCRIPTIONS_URL = '{graphql_subscriptions_url}';</script>

0 commit comments

Comments
 (0)