diff --git a/README.md b/README.md index 537cc2044c468a6c5ca231aeb4e4a45e7f758e5d..716a91e2ebaf189c067b32bc0897573e79ba6ed1 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,24 @@ cron.schedule('* * * * * *', () => { The library that enables this is `node-cron`. Be sure to check its [documentation](https://github.com/node-cron/node-cron#node-cron) for further details. +### Disable GraphQL + +There are cases where you might not want a graphql server at all. eg. If you are building a sevice with a single REST api endpoint with coko server. + +To disable graphql on the server, change the following value in your config: + +```js +// config/default.js + +module.exports = { + 'pubsweet-server': { + useGraphQLServer: false, + }, +} +``` + +_Note that this is `true` by default as using GraphQL will be the most common use case._ + ### CORS support for the client If you run your client on a different host/port than the server, you might run into issues where cross-origin requests are rejected. If that happens, make sure the following entries exist in your config. The server should take care of it once these are defined. diff --git a/src/app.js b/src/app.js index 2481b238648ebd41dc8df53db282a3fd9bab6db7..187d726cbcc3f8c683be0d39024224e0b274420c 100644 --- a/src/app.js +++ b/src/app.js @@ -86,8 +86,20 @@ const configureApp = app => { app.use('/api', api) // REST API - const gqlApi = require('./graphqlApi') - gqlApi(app) // GraphQL API + let useGraphQLServer = true + if ( + config.has('pubsweet-server.useGraphQLServer') && + config.get('pubsweet-server.useGraphQLServer') === false + ) { + useGraphQLServer = false + } + + logger.warn('useGraphQLServer', useGraphQLServer) + + if (useGraphQLServer) { + const gqlApi = require('./graphqlApi') + gqlApi(app) // GraphQL API + } app.use('/', index) // Serve the index page for front end