Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/graphiql.js
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -15,4 +15,4 @@ const _collectServicesAndMountAdapter = (srv, options) => {
services[srv.name] = srv
}

module.exports = _collectServicesAndMountAdapter
module.exports = collectServicesAndMountAdapter
2 changes: 1 addition & 1 deletion lib/GraphQLAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down