1
1
import * as React from 'react' ;
2
2
import * as ReactDOMClient from 'react-dom/client' ;
3
3
4
- import { Voyager } from '../src' ;
4
+ import { Voyager , voyagerIntrospectionQuery } from '../src' ;
5
5
6
6
async function fetchPreset ( name : string ) {
7
7
const response = await fetch ( `./presets/${ name } _introspection.json` ) ;
@@ -30,22 +30,7 @@ Promise.all([
30
30
const withCredentials = currentUrl . searchParams . get ( 'withCredentials' ) ;
31
31
32
32
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 ;
49
34
50
35
const rootElement = document . getElementById ( 'root' ) ;
51
36
const reactRoot = ReactDOMClient . createRoot ( rootElement ) ;
@@ -58,3 +43,18 @@ Promise.all([
58
43
} ) ,
59
44
) ;
60
45
} ) ;
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