Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove separate webpack config for demo #322

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,56 @@
}
}
</style>
<link rel="stylesheet" href="./voyager.css" />
<script src="./voyager.standalone.js"></script>
</head>
<body>
<script type="module">
// FIXME: switch to import
const { renderVoyager, voyagerIntrospectionQuery } = GraphQLVoyager;
const PRESETS = {
'Star Wars': await fetchPreset('swapi'),
Yelp: await fetchPreset('yelp'),
'Shopify Storefront': await fetchPreset('shopify'),
GitHub: await fetchPreset('github'),
};

const defaultPreset = PRESETS['Star Wars'];

const currentUrl = new URL(window.location.href);
const url = currentUrl.searchParams.get('url');
const withCredentials = currentUrl.searchParams.get('withCredentials');

const introspection =
url != null ? fetchIntrospection(url, withCredentials) : defaultPreset;

renderVoyager(document.getElementById('root'), {
introspection,
introspectionPresets: PRESETS,
allowToChangeSchema: true,
hideVoyagerLogo: false,
});

async function fetchPreset(name) {
const response = await fetch(`./presets/${name}_introspection.json`);
return response.json();
}

async function fetchIntrospection(url, withCredentials) {
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();
}
</script>
<main id="root">
<h1 style="text-align: center; color: #5d7e86">Loading...</h1>
</main>
Expand Down
53 changes: 0 additions & 53 deletions demo/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions demo/presets.ts

This file was deleted.

Loading