|
4 | 4 | <title>GraphiQL</title>
|
5 | 5 | <style>
|
6 | 6 | body {
|
7 |
| - height: 100%; |
8 | 7 | margin: 0;
|
9 |
| - width: 100%; |
10 | 8 | overflow: hidden;
|
11 | 9 | }
|
12 |
| - |
13 | 10 | #graphiql {
|
14 |
| - height: 100vh; |
| 11 | + height: 100dvh; |
| 12 | + } |
| 13 | + .loading { |
| 14 | + height: 100%; |
| 15 | + display: flex; |
| 16 | + align-items: center; |
| 17 | + justify-content: center; |
| 18 | + font-size: 4rem; |
15 | 19 | }
|
16 | 20 | </style>
|
17 |
| - <script src="https://unpkg.com/react@18/umd/react.production.min.js" crossorigin></script> |
18 |
| - <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" crossorigin></script> |
19 |
| - <script src="https://unpkg.com/graphiql/graphiql.min.js" type="application/javascript"></script> |
20 |
| - <link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" /> |
21 |
| - <script src="https://unpkg.com/@graphiql/plugin-explorer/dist/index.umd.js" crossorigin></script> |
22 |
| - <link rel="stylesheet" href="https://unpkg.com/@graphiql/plugin-explorer/dist/style.css"/> |
| 21 | + <link rel=" stylesheet" href=" https://esm.sh/[email protected]/dist/style.css" /> |
| 22 | + <link rel=" stylesheet" href=" https://esm.sh/@graphiql/[email protected]/dist/style.css" /> |
| 23 | + <script type="importmap"> |
| 24 | + { |
| 25 | + "imports": { |
| 26 | + "react": "https://esm.sh/[email protected]", |
| 27 | + "react/jsx-runtime": "https://esm.sh/[email protected]/jsx-runtime", |
| 28 | + "react-dom": "https://esm.sh/[email protected]", |
| 29 | + "react-dom/client": "https://esm.sh/[email protected]/client", |
| 30 | + "graphiql": "https://esm.sh/[email protected]?standalone&external=react,react/jsx-runtime,react-dom,@graphiql/react", |
| 31 | + "@graphiql/plugin-explorer": "https://esm.sh/@graphiql/[email protected]?standalone&external=react,react/jsx-runtime,react-dom,@graphiql/react,graphql", |
| 32 | + "@graphiql/react": "https://esm.sh/@graphiql/[email protected]?standalone&external=react,react/jsx-runtime,react-dom,graphql,@graphiql/toolkit", |
| 33 | + "@graphiql/toolkit": "https://esm.sh/@graphiql/[email protected]?standalone&external=graphql", |
| 34 | + "graphql": "https://esm.sh/[email protected]" |
| 35 | + } |
| 36 | + } |
| 37 | + </script> |
| 38 | + <script type="module"> |
| 39 | + import React from 'react'; |
| 40 | + import ReactDOM from 'react-dom/client'; |
| 41 | + import { GraphiQL } from 'graphiql'; |
| 42 | + import { createGraphiQLFetcher } from '@graphiql/toolkit'; |
| 43 | + import { explorerPlugin } from '@graphiql/plugin-explorer'; |
| 44 | + |
| 45 | + const params = new URLSearchParams(window.location.search); |
| 46 | + const path = params.get("path") || "/graphql"; |
| 47 | + const url = `${location.protocol}//${location.host}${path}`; |
| 48 | + const wsPath = params.get("wsPath") || "/graphql"; |
| 49 | + const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:'; |
| 50 | + const subscriptionUrl = `${wsProtocol}//${location.host}${wsPath}`; |
| 51 | + const gqlFetcher = createGraphiQLFetcher({'url': url, 'subscriptionUrl': subscriptionUrl}); |
| 52 | + const explorer = explorerPlugin(); |
| 53 | + const xsrfToken = document.cookie.match(new RegExp('(?:^| )XSRF-TOKEN=([^;]+)')); |
| 54 | + const headers = xsrfToken ? `{ "X-XSRF-TOKEN" : "${ xsrfToken[1] }" }` : `{}`; |
| 55 | + |
| 56 | + function App() { |
| 57 | + return React.createElement(GraphiQL, { |
| 58 | + fetcher: gqlFetcher, |
| 59 | + defaultVariableEditorOpen: true, |
| 60 | + headerEditorEnabled: true, |
| 61 | + shouldPersistHeaders: true, |
| 62 | + headers: headers, |
| 63 | + plugins: [explorer], |
| 64 | + }); |
| 65 | + } |
| 66 | + |
| 67 | + const container = document.getElementById('graphiql'); |
| 68 | + const root = ReactDOM.createRoot(container); |
| 69 | + root.render(React.createElement(App)); |
| 70 | + </script> |
23 | 71 | </head>
|
24 | 72 | <body>
|
25 |
| -<div id="graphiql">Loading...</div> |
26 |
| -<script> |
27 |
| - const params = new URLSearchParams(window.location.search); |
28 |
| - const path = params.get("path") || "/graphql"; |
29 |
| - const url = `${location.protocol}//${location.host}${path}`; |
30 |
| - const wsPath = params.get("wsPath") || "/graphql"; |
31 |
| - const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:'; |
32 |
| - const subscriptionUrl = `${wsProtocol}//${location.host}${wsPath}`; |
33 |
| - const gqlFetcher = GraphiQL.createFetcher({'url': url, 'subscriptionUrl': subscriptionUrl}); |
34 |
| - const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin(); |
35 |
| - const xsrfToken = document.cookie.match(new RegExp('(?:^| )XSRF-TOKEN=([^;]+)')); |
36 |
| - const headers = xsrfToken ? `{ "X-XSRF-TOKEN" : "${ xsrfToken[1] }" }` : `{}`; |
37 |
| - ReactDOM.render( |
38 |
| - React.createElement(GraphiQL, { |
39 |
| - fetcher: gqlFetcher, |
40 |
| - defaultVariableEditorOpen: true, |
41 |
| - headerEditorEnabled: true, |
42 |
| - shouldPersistHeaders: true, |
43 |
| - headers: headers, |
44 |
| - plugins: [explorerPlugin] |
45 |
| - }), |
46 |
| - document.getElementById('graphiql'), |
47 |
| - ); |
48 |
| -</script> |
| 73 | +<div id="graphiql"><div class="loading">Loading...</div></div> |
49 | 74 | </body>
|
50 | 75 | </html>
|
0 commit comments