Skip to content

Commit 247eeb8

Browse files
use top-level await in examples & middleware (#344)
1 parent 4b62afa commit 247eeb8

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

example/cdn/index.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
</head>
2727
<body>
2828
<div id="voyager">Loading...</div>
29-
<script>
29+
<script type="module">
3030
const { init, voyagerIntrospectionQuery: query } = GraphQLVoyager;
31-
const introspection = fetch(
31+
const response = await fetch(
3232
'https://swapi-graphql.netlify.app/.netlify/functions/index',
3333
{
3434
method: 'post',
@@ -39,7 +39,8 @@
3939
body: JSON.stringify({ query }),
4040
credentials: 'omit',
4141
},
42-
).then((response) => response.json());
42+
);
43+
const introspection = await response.json();
4344

4445
// Render <Voyager /> into the body.
4546
GraphQLVoyager.init(document.getElementById('voyager'), {

example/webpack/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
</head>
2020
<body>
2121
<div id="voyager">Loading...</div>
22-
<script src="/webpack-dev-server.js"></script>
2322
<script src="/main.js"></script>
2423
</body>
2524
</html>

example/webpack/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as ReactDOMClient from 'react-dom/client';
22

33
import { Voyager, voyagerIntrospectionQuery } from 'graphql-voyager';
44

5-
const introspection = fetch(
5+
const response = await fetch(
66
'https://swapi-graphql.netlify.app/.netlify/functions/index',
77
{
88
method: 'post',
@@ -13,7 +13,8 @@ const introspection = fetch(
1313
body: JSON.stringify({ query: voyagerIntrospectionQuery }),
1414
credentials: 'omit',
1515
},
16-
).then((response) => response.json());
16+
);
17+
const introspection = await response.json();
1718

1819
const reactRoot = ReactDOMClient.createRoot(document.getElementById('voyager'));
1920
reactRoot.render(

example/webpack/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@types/react-dom": "^18.0.11",
1616
"ts-loader": "5.3.3",
1717
"typescript": "4.7.2",
18-
"webpack": "5.73.0",
18+
"webpack": "5.83.0",
1919
"webpack-cli": "4.10.0",
2020
"webpack-dev-server": "4.9.1"
2121
}

example/webpack/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"noImplicitAny": true,
44
"noEmit": true,
5-
"module": "es2015",
5+
"module": "esnext",
66
"moduleResolution": "node",
77
"target": "es2021",
88
"jsx": "react-jsx"

src/middleware/render-voyager-page.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ export default function renderVoyagerPage(options: MiddlewareOptions) {
3737
<main id="voyager">
3838
<h1 style="text-align: center; color: #5d7e86;"> Loading... </h1>
3939
</main>
40-
<script>
40+
<script type="module">
4141
window.addEventListener('load', function(event) {
42-
const query = GraphQLVoyager.voyagerIntrospectionQuery;
43-
const introspection = fetch('${endpointUrl}', {
42+
const response = fetch('${endpointUrl}', {
4443
method: 'post',
4544
headers: Object.assign({}, {
4645
'Accept': 'application/json',
4746
'Content-Type': 'application/json',
4847
}, ${headersJS}),
49-
body: JSON.stringify({query}),
48+
body: JSON.stringify({
49+
query: GraphQLVoyager.voyagerIntrospectionQuery,
50+
}),
5051
credentials: 'include',
51-
}).then(response => response.json());
52+
});
53+
const introspection = await response.json();
5254
5355
GraphQLVoyager.init(document.getElementById('voyager'), {
5456
introspection,

0 commit comments

Comments
 (0)