Skip to content

Commit 7d1b5ce

Browse files
committed
Upgrade to GraphiQL 5.0.0
This commit upgrades to GraphiQL 5.0.0 and uses fixed CDN URLs to avoid potential breakages in the future. Closes gh-1209
1 parent 7ee1621 commit 7d1b5ce

File tree

1 file changed

+30
-15
lines changed
  • spring-graphql/src/main/resources/graphiql

1 file changed

+30
-15
lines changed
Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
@@ -7,7 +7,6 @@
77
<style>
88
body {
99
margin: 0;
10-
overflow: hidden;
1110
}
1211
#graphiql {
1312
height: 100dvh;
@@ -20,49 +19,65 @@
2019
font-size: 4rem;
2120
}
2221
</style>
23-
<link rel="stylesheet" href="https://esm.sh/graphiql@4.0.0/dist/style.css"/>
24-
<link rel="stylesheet" href="https://esm.sh/@graphiql/plugin-explorer@4.0.0/dist/style.css"/>
22+
<link rel="stylesheet" href="https://esm.sh/graphiql@5.0.0/dist/style.css"/>
23+
<link rel="stylesheet" href="https://esm.sh/@graphiql/plugin-explorer@5.0.0/dist/style.css"/>
2524
<script type="importmap">
2625
{
2726
"imports": {
2827
"react": "https://esm.sh/[email protected]",
2928
"react/jsx-runtime": "https://esm.sh/[email protected]/jsx-runtime",
3029
"react-dom": "https://esm.sh/[email protected]",
3130
"react-dom/client": "https://esm.sh/[email protected]/client",
32-
"graphiql": "https://esm.sh/graphiql@4.0.0?standalone&external=react,react/jsx-runtime,react-dom,@graphiql/react",
33-
"@graphiql/plugin-explorer": "https://esm.sh/@graphiql/plugin-explorer@4.0.0?standalone&external=react,react/jsx-runtime,react-dom,@graphiql/react,graphql",
34-
"@graphiql/react": "https://esm.sh/@graphiql/react@0.30.0?standalone&external=react,react/jsx-runtime,react-dom,graphql,@graphiql/toolkit",
35-
"@graphiql/toolkit": "https://esm.sh/@graphiql/[email protected].2?standalone&external=graphql",
31+
"graphiql": "https://esm.sh/graphiql@5.0.0?standalone&external=react,react-dom,@graphiql/react,graphql",
32+
"@graphiql/plugin-explorer": "https://esm.sh/@graphiql/plugin-explorer@5.0.0?standalone&external=react,@graphiql/react,graphql",
33+
"@graphiql/react": "https://esm.sh/@graphiql/react@0.35.0?standalone&external=react,react-dom,graphql",
34+
"@graphiql/toolkit": "https://esm.sh/@graphiql/[email protected].3?standalone&external=graphql",
3635
"graphql": "https://esm.sh/[email protected]"
3736
}
3837
}
3938
</script>
4039
<script type="module">
4140
import React from 'react';
4241
import ReactDOM from 'react-dom/client';
43-
import { GraphiQL } from 'graphiql';
42+
import { GraphiQL, HISTORY_PLUGIN } from 'graphiql';
4443
import { createGraphiQLFetcher } from '@graphiql/toolkit';
4544
import { explorerPlugin } from '@graphiql/plugin-explorer';
4645

46+
import createJSONWorker from 'https://esm.sh/monaco-editor/esm/vs/language/json/json.worker.js?worker';
47+
import createGraphQLWorker from 'https://esm.sh/monaco-graphql/esm/graphql.worker.js?worker';
48+
import createEditorWorker from 'https://esm.sh/monaco-editor/esm/vs/editor/editor.worker.js?worker';
49+
50+
globalThis.MonacoEnvironment = {
51+
getWorker(_workerId, label) {
52+
switch (label) {
53+
case 'json':
54+
return createJSONWorker();
55+
case 'graphql':
56+
return createGraphQLWorker();
57+
}
58+
return createEditorWorker();
59+
},
60+
};
61+
4762
const params = new URLSearchParams(window.location.search);
4863
const path = params.get("path") || "/graphql";
4964
const url = `${location.protocol}//${location.host}${path}`;
5065
const wsPath = params.get("wsPath") || "/graphql";
5166
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
5267
const subscriptionUrl = `${wsProtocol}//${location.host}${wsPath}`;
5368
const gqlFetcher = createGraphiQLFetcher({'url': url, 'subscriptionUrl': subscriptionUrl});
54-
const explorer = explorerPlugin();
69+
const plugins = [HISTORY_PLUGIN, explorerPlugin()];
5570
const xsrfToken = document.cookie.match(new RegExp('(?:^| )XSRF-TOKEN=([^;]+)'));
56-
const headers = xsrfToken ? `{ "X-XSRF-TOKEN" : "${ xsrfToken[1] }" }` : `{}`;
71+
const initialHeaders = xsrfToken ? `{ "X-XSRF-TOKEN" : "${ xsrfToken[1] }" }` : `{}`;
5772

5873
function App() {
5974
return React.createElement(GraphiQL, {
6075
fetcher: gqlFetcher,
61-
defaultVariableEditorOpen: true,
76+
defaultEditorToolsVisibility: true,
6277
headerEditorEnabled: true,
6378
shouldPersistHeaders: true,
64-
headers: headers,
65-
plugins: [explorer],
79+
initialHeaders: initialHeaders,
80+
plugins: plugins,
6681
});
6782
}
6883

@@ -74,4 +89,4 @@
7489
<body>
7590
<div id="graphiql"><div class="loading">Loading...</div></div>
7691
</body>
77-
</html>
92+
</html>

0 commit comments

Comments
 (0)