@@ -20,12 +20,16 @@ pub fn graphiql_source(
20
20
21
21
let stylesheet_source = r#"
22
22
<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
+ }
29
33
</style>
30
34
"# ;
31
35
let fetcher_source = r#"
@@ -50,33 +54,37 @@ pub fn graphiql_source(
50
54
return null
51
55
}
52
56
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',
59
71
},
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
+ });
70
76
});
71
77
}
72
78
73
79
var fetcher = usingSubscriptions ? window.GraphiQLSubscriptionsFetcher.graphQLFetcher(subscriptionsClient, graphQLFetcher) : graphQLFetcher;
74
80
75
81
ReactDOM.render(
76
82
React.createElement(GraphiQL, {
77
- fetcher,
83
+ fetcher,
84
+ defaultVariableEditorOpen: true,
78
85
}),
79
- document.querySelector('#app'));
86
+ document.getElementById('graphiql'),
87
+ );
80
88
</script>
81
89
"# ;
82
90
@@ -87,16 +95,22 @@ pub fn graphiql_source(
87
95
<head>
88
96
<title>GraphQL</title>
89
97
{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" />
91
107
</head>
92
108
<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>
100
114
<script>var GRAPHQL_URL = '{graphql_url}';</script>
101
115
<script>var usingSubscriptions = {using_subscriptions};</script>
102
116
<script>var GRAPHQL_SUBSCRIPTIONS_URL = '{graphql_subscriptions_url}';</script>
0 commit comments