UNPKG

graphql-anywhere-mongodb-express

Version:

express middleware that accepts graphql requests and runs them as mongo queries

22 lines 880 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const graphiql_html_1 = require("./graphiql-html"); const handle_async_1 = require("../handle-async"); function graphiqlMiddleware(options) { return handle_async_1.handleAsync((req, res) => { // Verify response accepts text/html if (!req.accepts('html')) { res.status(406).json({ message: `Request must accept content type of text/html` }); return; } // Send response const chunk = new Buffer(graphiql_html_1.graphiQLHtml(options), 'utf8'); res.setHeader('Content-Type', 'text/html; charset=utf-8'); res.setHeader('Content-Length', String(chunk.length)); res.end(chunk); }); } exports.graphiqlMiddleware = graphiqlMiddleware; //# sourceMappingURL=serve-graphiql-middleware.js.map