File tree 6 files changed +16
-13
lines changed
6 files changed +16
-13
lines changed Original file line number Diff line number Diff line change 26
26
</ head >
27
27
< body >
28
28
< div id ="voyager "> Loading...</ div >
29
- < script >
29
+ < script type =" module " >
30
30
const { init, voyagerIntrospectionQuery : query } = GraphQLVoyager ;
31
- const introspection = fetch (
31
+ const response = await fetch (
32
32
'https://swapi-graphql.netlify.app/.netlify/functions/index' ,
33
33
{
34
34
method : 'post' ,
39
39
body : JSON . stringify ( { query } ) ,
40
40
credentials : 'omit' ,
41
41
} ,
42
- ) . then ( ( response ) => response . json ( ) ) ;
42
+ ) ;
43
+ const introspection = await response . json ( ) ;
43
44
44
45
// Render <Voyager /> into the body.
45
46
GraphQLVoyager . init ( document . getElementById ( 'voyager' ) , {
Original file line number Diff line number Diff line change 19
19
</ head >
20
20
< body >
21
21
< div id ="voyager "> Loading...</ div >
22
- < script src ="/webpack-dev-server.js "> </ script >
23
22
< script src ="/main.js "> </ script >
24
23
</ body >
25
24
</ html >
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import * as ReactDOMClient from 'react-dom/client';
2
2
3
3
import { Voyager , voyagerIntrospectionQuery } from 'graphql-voyager' ;
4
4
5
- const introspection = fetch (
5
+ const response = await fetch (
6
6
'https://swapi-graphql.netlify.app/.netlify/functions/index' ,
7
7
{
8
8
method : 'post' ,
@@ -13,7 +13,8 @@ const introspection = fetch(
13
13
body : JSON . stringify ( { query : voyagerIntrospectionQuery } ) ,
14
14
credentials : 'omit' ,
15
15
} ,
16
- ) . then ( ( response ) => response . json ( ) ) ;
16
+ ) ;
17
+ const introspection = await response . json ( ) ;
17
18
18
19
const reactRoot = ReactDOMClient . createRoot ( document . getElementById ( 'voyager' ) ) ;
19
20
reactRoot . render (
Original file line number Diff line number Diff line change 15
15
"@types/react-dom" : " ^18.0.11" ,
16
16
"ts-loader" : " 5.3.3" ,
17
17
"typescript" : " 4.7.2" ,
18
- "webpack" : " 5.73 .0" ,
18
+ "webpack" : " 5.83 .0" ,
19
19
"webpack-cli" : " 4.10.0" ,
20
20
"webpack-dev-server" : " 4.9.1"
21
21
}
Original file line number Diff line number Diff line change 2
2
"compilerOptions" : {
3
3
"noImplicitAny" : true ,
4
4
"noEmit" : true ,
5
- "module" : " es2015 " ,
5
+ "module" : " esnext " ,
6
6
"moduleResolution" : " node" ,
7
7
"target" : " es2021" ,
8
8
"jsx" : " react-jsx"
Original file line number Diff line number Diff line change @@ -37,18 +37,20 @@ export default function renderVoyagerPage(options: MiddlewareOptions) {
37
37
<main id="voyager">
38
38
<h1 style="text-align: center; color: #5d7e86;"> Loading... </h1>
39
39
</main>
40
- <script>
40
+ <script type="module" >
41
41
window.addEventListener('load', function(event) {
42
- const query = GraphQLVoyager.voyagerIntrospectionQuery;
43
- const introspection = fetch('${ endpointUrl } ', {
42
+ const response = fetch('${ endpointUrl } ', {
44
43
method: 'post',
45
44
headers: Object.assign({}, {
46
45
'Accept': 'application/json',
47
46
'Content-Type': 'application/json',
48
47
}, ${ headersJS } ),
49
- body: JSON.stringify({query}),
48
+ body: JSON.stringify({
49
+ query: GraphQLVoyager.voyagerIntrospectionQuery,
50
+ }),
50
51
credentials: 'include',
51
- }).then(response => response.json());
52
+ });
53
+ const introspection = await response.json();
52
54
53
55
GraphQLVoyager.init(document.getElementById('voyager'), {
54
56
introspection,
You can’t perform that action at this time.
0 commit comments