@graphql-yoga/render-graphiql
Version:
46 lines (44 loc) • 1.55 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderGraphiQL = void 0;
const graphiql_js_1 = require("./graphiql.js");
const renderGraphiQL = (opts) => /* HTML */ `
<html lang="en">
<head>
<meta charset="utf-8" />
<title>${opts?.title || 'Yoga GraphiQL'}</title>
<link rel="icon" href="${opts?.favicon || graphiql_js_1.favicon}" />
<style>
${graphiql_js_1.css}
</style>
</head>
<body id="body" class="no-focus-outline">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script>
function prepareBlob(workerContent) {
const blob = new Blob([workerContent], { type: 'application/javascript' });
return URL.createObjectURL(blob);
}
const workers = {
editorWorkerService: prepareBlob(${JSON.stringify(graphiql_js_1.editorWorkerService)}),
json: prepareBlob(${JSON.stringify(graphiql_js_1.jsonWorker)}),
graphql: prepareBlob(${JSON.stringify(graphiql_js_1.graphqlWorker)}),
};
self['MonacoEnvironment'] = {
globalAPI: false,
getWorkerUrl: function (moduleId, label) {
return workers[label];
},
};
${graphiql_js_1.js};
YogaGraphiQL.renderYogaGraphiQL(
window.document.querySelector('#root'),
${JSON.stringify(opts ?? {})},
);
</script>
</body>
</html>
`;
exports.renderGraphiQL = renderGraphiQL;