Skip to content

Commit

Permalink
Switch demo to use pass promise as introspection (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored May 3, 2023
1 parent c9f869e commit 39ec4ec
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions demo/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import * as ReactDOMClient from 'react-dom/client';

import { Voyager } from '../src';
import { Voyager, voyagerIntrospectionQuery } from '../src';

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

const introspection =
url != null
? async (introspectionQuery: string) => {
const response = await fetch(url, {
method: 'post',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({ query: introspectionQuery }),
...(withCredentials === 'true'
? { credentials: 'include', mode: 'cors' }
: {}),
});
return response.json();
}
: defaultPreset;
url != null ? fetchIntrospection(url, withCredentials) : defaultPreset;

const rootElement = document.getElementById('root');
const reactRoot = ReactDOMClient.createRoot(rootElement);
Expand All @@ -58,3 +43,18 @@ Promise.all([
}),
);
});

async function fetchIntrospection(url: string, withCredentials: string) {
const response = await fetch(url, {
method: 'post',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({ query: voyagerIntrospectionQuery }),
...(withCredentials === 'true'
? { credentials: 'include', mode: 'cors' }
: {}),
});
return response.json();
}

0 comments on commit 39ec4ec

Please sign in to comment.