Skip to content

Instantly share code, notes, and snippets.

@hanachin
Last active December 3, 2021 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanachin/874eccafa1176ae3e607fdca45dbea9a to your computer and use it in GitHub Desktop.
Save hanachin/874eccafa1176ae3e607fdca45dbea9a to your computer and use it in GitHub Desktop.
<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