Skip to content

Instantly share code, notes, and snippets.

@hanachin
Last active Dec 3, 2021
Embed
What would you like to do?
<html>
<head>
<title>Simple GraphiQL Example</title>
<link href="https://unpkg.com/graphiql/graphiql.min.css" rel="stylesheet" />
</head>
<body style="margin: 0;">
<div id="graphiql" style="height: 100vh;"></div>
<script type="module">
await import('https://unpkg.com/react/umd/react.production.min.js')
await import('https://unpkg.com/react-dom/umd/react-dom.production.min.js')
await import('https://unpkg.com/graphiql/graphiql.min.js')
const graphQLFetcher = graphQLParams =>
fetch('http://localhost:4567/graphql', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(graphQLParams),
})
.then(response => response.json())
.catch(() => response.text());
ReactDOM.render(
React.createElement(GraphiQL, { fetcher: graphQLFetcher }),
document.getElementById('graphiql'),
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment