|
| 1 | +<!doctype html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 6 | + <title>GraphiQL</title> |
| 7 | + <style> |
| 8 | + body { |
| 9 | + margin: 0; |
| 10 | + } |
| 11 | + #graphiql { |
| 12 | + height: 100dvh; |
| 13 | + } |
| 14 | + .loading { |
| 15 | + height: 100%; |
| 16 | + display: flex; |
| 17 | + align-items: center; |
| 18 | + justify-content: center; |
| 19 | + font-size: 4rem; |
| 20 | + } |
| 21 | + </style> |
| 22 | + <link rel="stylesheet" href="https://esm.sh/graphiql@5.2.1/dist/style.css"/> |
| 23 | + <link rel="stylesheet" href="https://esm.sh/@graphiql/plugin-explorer@5.1.1/dist/style.css"/> |
| 24 | + <script type="importmap"> |
| 25 | + { |
| 26 | + "imports": { |
| 27 | + "react": "https://esm.sh/react@19.1.0", |
| 28 | + "react/": "https://esm.sh/react@19.1.0/", |
| 29 | + "react-dom": "https://esm.sh/react-dom@19.1.0", |
| 30 | + "react-dom/": "https://esm.sh/react-dom@19.1.0/", |
| 31 | + "graphiql": "https://esm.sh/graphiql@5.2.1?standalone&external=react,react-dom,@graphiql/react,graphql", |
| 32 | + "graphiql/": "https://esm.sh/graphiql@5.2.1/", |
| 33 | + "@graphiql/plugin-explorer": "https://esm.sh/@graphiql/plugin-explorer@5.1.1?standalone&external=react,@graphiql/react,graphql", |
| 34 | + "@graphiql/react": "https://esm.sh/@graphiql/react@0.37.2?standalone&external=react,react-dom,graphql,@graphiql/toolkit,@emotion/is-prop-valid", |
| 35 | + "@graphiql/toolkit": "https://esm.sh/@graphiql/toolkit@0.11.3?standalone&external=graphql", |
| 36 | + "graphql": "https://esm.sh/graphql@16.11.0", |
| 37 | + "@emotion/is-prop-valid": "data:text/javascript," |
| 38 | + } |
| 39 | + } |
| 40 | + </script> |
| 41 | + <script type="module"> |
| 42 | + import React from 'react'; |
| 43 | + import ReactDOM from 'react-dom/client'; |
| 44 | + import { GraphiQL, HISTORY_PLUGIN } from 'graphiql'; |
| 45 | + import { createGraphiQLFetcher } from '@graphiql/toolkit'; |
| 46 | + import { explorerPlugin } from '@graphiql/plugin-explorer'; |
| 47 | + import 'graphiql/setup-workers/esm.sh'; |
| 48 | + |
| 49 | + const params = new URLSearchParams(window.location.search); |
| 50 | + const path = params.get('path') || '/graphql'; |
| 51 | + const url = `${location.protocol}//${location.host}${path}`; |
| 52 | + const wsPath = params.get('wsPath') || '/graphql'; |
| 53 | + const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:'; |
| 54 | + const subscriptionUrl = `${wsProtocol}//${location.host}${wsPath}`; |
| 55 | + const gqlFetcher = createGraphiQLFetcher({'url': url, 'subscriptionUrl': subscriptionUrl}); |
| 56 | + const plugins = [HISTORY_PLUGIN, explorerPlugin()]; |
| 57 | + const xsrfToken = document.cookie.match(new RegExp('(?:^| )XSRF-TOKEN=([^;]+)')); |
| 58 | + const initialHeaders = xsrfToken ? `{ 'X-XSRF-TOKEN' : '${ xsrfToken[1] }' }` : undefined; |
| 59 | + |
| 60 | + function App() { |
| 61 | + return React.createElement(GraphiQL, { |
| 62 | + fetcher: gqlFetcher, |
| 63 | + defaultEditorToolsVisibility: true, |
| 64 | + headerEditorEnabled: true, |
| 65 | + shouldPersistHeaders: true, |
| 66 | + initialHeaders: initialHeaders, |
| 67 | + plugins: plugins, |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | + const container = document.getElementById('graphiql'); |
| 72 | + const root = ReactDOM.createRoot(container); |
| 73 | + root.render(React.createElement(App)); |
| 74 | + </script> |
| 75 | +</head> |
| 76 | +<body> |
| 77 | + <div id="graphiql"><div class="loading">Loading...</div></div> |
| 78 | +</body> |
| 79 | +</html> |
0 commit comments