diff --git a/graph/index.js b/graph/index.js index 021770d36..3413f2d78 100644 --- a/graph/index.js +++ b/graph/index.js @@ -1,32 +1,14 @@ const schema = require('./schema'); const Context = require('./context'); -const plugins = require('../services/plugins'); +const setupFunctions = require('./setupFunctions'); const {connectionOptions} = require('../services/redis'); const {RedisPubSub} = require('graphql-redis-subscriptions'); const {SubscriptionManager} = require('graphql-subscriptions'); const {SubscriptionServer} = require('subscriptions-transport-ws'); -const _ = require('lodash'); const pubsub = new RedisPubSub(connectionOptions); -let setupFunctions = { - commentAdded: (options, args) => ({ - commentAdded: { - filter: (comment) => comment.asset_id === args.asset_id - }, - }), -}; - -/** - * Plugin support requires that we merge in existing setupFunctions with our new - * plugin based ones. This allows plugins to extend existing setupFunctions as well - * as provide new ones. - */ -setupFunctions = plugins.get('server', 'setupFunctions').reduce((acc, {setupFunctions}) => { - return _.merge(acc, setupFunctions); -}, setupFunctions); - module.exports = { pubsub, createGraphOptions: (req) => ({ diff --git a/graph/setupFunctions.js b/graph/setupFunctions.js new file mode 100644 index 000000000..ed4d6ffa9 --- /dev/null +++ b/graph/setupFunctions.js @@ -0,0 +1,21 @@ +const plugins = require('../services/plugins'); +const _ = require('lodash'); + +// Core setup functions +let setupFunctions = { + commentAdded: (options, args) => ({ + commentAdded: { + filter: (comment) => comment.asset_id === args.asset_id + }, + }), +}; + +/** + * Plugin support requires that we merge in existing setupFunctions with our new + * plugin based ones. This allows plugins to extend existing setupFunctions as well + * as provide new ones. + */ +module.exports = plugins.get('server', 'setupFunctions').reduce((acc, {setupFunctions}) => { + + return _.merge(acc, setupFunctions); +}, setupFunctions);