Skip to content

Commit 39ec4ec

Browse files
Switch demo to use pass promise as introspection (#304)
1 parent c9f869e commit 39ec4ec

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

demo/index.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import * as ReactDOMClient from 'react-dom/client';
33

4-
import { Voyager } from '../src';
4+
import { Voyager, voyagerIntrospectionQuery } from '../src';
55

66
async function fetchPreset(name: string) {
77
const response = await fetch(`./presets/${name}_introspection.json`);
@@ -30,22 +30,7 @@ Promise.all([
3030
const withCredentials = currentUrl.searchParams.get('withCredentials');
3131

3232
const introspection =
33-
url != null
34-
? async (introspectionQuery: string) => {
35-
const response = await fetch(url, {
36-
method: 'post',
37-
headers: {
38-
Accept: 'application/json',
39-
'Content-Type': 'application/json',
40-
},
41-
body: JSON.stringify({ query: introspectionQuery }),
42-
...(withCredentials === 'true'
43-
? { credentials: 'include', mode: 'cors' }
44-
: {}),
45-
});
46-
return response.json();
47-
}
48-
: defaultPreset;
33+
url != null ? fetchIntrospection(url, withCredentials) : defaultPreset;
4934

5035
const rootElement = document.getElementById('root');
5136
const reactRoot = ReactDOMClient.createRoot(rootElement);
@@ -58,3 +43,18 @@ Promise.all([
5843
}),
5944
);
6045
});
46+
47+
async function fetchIntrospection(url: string, withCredentials: string) {
48+
const response = await fetch(url, {
49+
method: 'post',
50+
headers: {
51+
Accept: 'application/json',
52+
'Content-Type': 'application/json',
53+
},
54+
body: JSON.stringify({ query: voyagerIntrospectionQuery }),
55+
...(withCredentials === 'true'
56+
? { credentials: 'include', mode: 'cors' }
57+
: {}),
58+
});
59+
return response.json();
60+
}

0 commit comments

Comments
 (0)