1
- <!DOCTYPE html>
1
+ <!doctype html>
2
2
< html lang ="en ">
3
3
< head >
4
4
< meta charset ="UTF-8 " />
7
7
< style >
8
8
body {
9
9
margin : 0 ;
10
- overflow : hidden;
11
10
}
12
11
# graphiql {
13
12
height : 100dvh ;
20
19
font-size : 4rem ;
21
20
}
22
21
</ 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 "/>
25
24
< script type ="importmap ">
26
25
{
27
26
"imports" : {
28
27
"react" :
"https://esm.sh/[email protected] " ,
29
28
"react/jsx-runtime" :
"https://esm.sh/[email protected] /jsx-runtime" ,
30
29
"react-dom" :
"https://esm.sh/[email protected] " ,
31
30
"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" ,
36
35
"graphql" :
"https://esm.sh/[email protected] "
37
36
}
38
37
}
39
38
</ script >
40
39
< script type ="module ">
41
40
import React from 'react' ;
42
41
import ReactDOM from 'react-dom/client' ;
43
- import { GraphiQL } from 'graphiql' ;
42
+ import { GraphiQL , HISTORY_PLUGIN } from 'graphiql' ;
44
43
import { createGraphiQLFetcher } from '@graphiql/toolkit' ;
45
44
import { explorerPlugin } from '@graphiql/plugin-explorer' ;
46
45
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
+
47
62
const params = new URLSearchParams ( window . location . search ) ;
48
63
const path = params . get ( "path" ) || "/graphql" ;
49
64
const url = `${ location . protocol } //${ location . host } ${ path } ` ;
50
65
const wsPath = params . get ( "wsPath" ) || "/graphql" ;
51
66
const wsProtocol = location . protocol === 'https:' ? 'wss:' : 'ws:' ;
52
67
const subscriptionUrl = `${ wsProtocol } //${ location . host } ${ wsPath } ` ;
53
68
const gqlFetcher = createGraphiQLFetcher ( { 'url' : url , 'subscriptionUrl' : subscriptionUrl } ) ;
54
- const explorer = explorerPlugin ( ) ;
69
+ const plugins = [ HISTORY_PLUGIN , explorerPlugin ( ) ] ;
55
70
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 ] } " }` : `{}` ;
57
72
58
73
function App ( ) {
59
74
return React . createElement ( GraphiQL , {
60
75
fetcher : gqlFetcher ,
61
- defaultVariableEditorOpen : true ,
76
+ defaultEditorToolsVisibility : true ,
62
77
headerEditorEnabled : true ,
63
78
shouldPersistHeaders : true ,
64
- headers : headers ,
65
- plugins : [ explorer ] ,
79
+ initialHeaders : initialHeaders ,
80
+ plugins : plugins ,
66
81
} ) ;
67
82
}
68
83
74
89
< body >
75
90
< div id ="graphiql "> < div class ="loading "> Loading...</ div > </ div >
76
91
</ body >
77
- </ html >
92
+ </ html >
0 commit comments