Skip to content

Commit f52c3fb

Browse files
committed
remove separate webpack config for demo
1 parent d0265a0 commit f52c3fb

8 files changed

+66
-647
lines changed

demo/index.html

+48
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,56 @@
107107
}
108108
}
109109
</style>
110+
<link rel="stylesheet" href="./voyager.css" />
111+
<script src="./voyager.standalone.js"></script>
110112
</head>
111113
<body>
114+
<script type="module">
115+
// FIXME: switch to import
116+
const { renderVoyager, voyagerIntrospectionQuery } = GraphQLVoyager;
117+
const PRESETS = {
118+
'Star Wars': await fetchPreset('swapi'),
119+
Yelp: await fetchPreset('yelp'),
120+
'Shopify Storefront': await fetchPreset('shopify'),
121+
GitHub: await fetchPreset('github'),
122+
};
123+
124+
const defaultPreset = PRESETS['Star Wars'];
125+
126+
const currentUrl = new URL(window.location.href);
127+
const url = currentUrl.searchParams.get('url');
128+
const withCredentials = currentUrl.searchParams.get('withCredentials');
129+
130+
const introspection =
131+
url != null ? fetchIntrospection(url, withCredentials) : defaultPreset;
132+
133+
renderVoyager(document.getElementById('root'), {
134+
introspection,
135+
introspectionPresets: PRESETS,
136+
allowToChangeSchema: true,
137+
hideVoyagerLogo: false,
138+
});
139+
140+
async function fetchPreset(name) {
141+
const response = await fetch(`./presets/${name}_introspection.json`);
142+
return response.json();
143+
}
144+
145+
async function fetchIntrospection(url, withCredentials) {
146+
const response = await fetch(url, {
147+
method: 'post',
148+
headers: {
149+
Accept: 'application/json',
150+
'Content-Type': 'application/json',
151+
},
152+
body: JSON.stringify({ query: voyagerIntrospectionQuery }),
153+
...(withCredentials === 'true'
154+
? { credentials: 'include', mode: 'cors' }
155+
: {}),
156+
});
157+
return response.json();
158+
}
159+
</script>
112160
<main id="root">
113161
<h1 style="text-align: center; color: #5d7e86">Loading...</h1>
114162
</main>

demo/index.ts

-53
This file was deleted.

demo/presets.ts

-14
This file was deleted.

0 commit comments

Comments
 (0)