diff --git a/app/graphiql.js b/app/graphiql.js index d320482d..23e4a770 100644 --- a/app/graphiql.js +++ b/app/graphiql.js @@ -1,10 +1,14 @@ const path = require('path') +const express = require('express') +const router = express.Router() -module.exports = (req, res, next) => { +router.get('/', (req, res, next) => { if (req.query.query) { // Forward GET requests with query URL parameter to GraphQL server next() } else { res.sendFile(path.join(__dirname, 'graphiql.html')) } -} +}) + +module.exports = router diff --git a/index.js b/index.js index d90aad43..dbdd878d 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const DEBUG = cds.debug('adapters') const GraphQLAdapter = require('./lib/GraphQLAdapter') let services -const _collectServicesAndMountAdapter = (srv, options) => { +const collectServicesAndMountAdapter = (srv, options) => { if (!services) { services = {} cds.on('served', () => { @@ -15,4 +15,4 @@ const _collectServicesAndMountAdapter = (srv, options) => { services[srv.name] = srv } -module.exports = _collectServicesAndMountAdapter +module.exports = collectServicesAndMountAdapter diff --git a/lib/GraphQLAdapter.js b/lib/GraphQLAdapter.js index 6dc63f4e..ed73877a 100644 --- a/lib/GraphQLAdapter.js +++ b/lib/GraphQLAdapter.js @@ -20,7 +20,7 @@ function GraphQLAdapter(options) { next() }) - if (options.graphiql) router.get('/', graphiql) + if (options.graphiql) router.use(graphiql) router.use((req, res) => createHandler({ schema, context: { req, res }, ...options })(req, res)) return router }