fixed import cycle

This commit is contained in:
Wyatt Johnson
2018-02-16 17:11:02 -07:00
parent 0b547b173a
commit b600172380
6 changed files with 16 additions and 18 deletions
+3 -2
View File
@@ -5,7 +5,8 @@ const merge = require('lodash/merge');
const errors = require('../errors');
// Graph
const subscriptions = require('./subscriptions');
const { getBroker } = require('./subscriptions/broker');
const { getPubsub } = require('./subscriptions/pubsub');
const resolvers = require('./resolvers');
const mutators = require('./mutators');
const loaders = require('./loaders');
@@ -85,7 +86,7 @@ const defaultConnectors = {
Wordlist,
},
graph: {
subscriptions,
subscriptions: { getBroker, getPubsub },
resolvers,
mutators,
loaders,
-3
View File
@@ -2,7 +2,6 @@ const { SubscriptionManager } = require('graphql-subscriptions');
const { SubscriptionServer } = require('subscriptions-transport-ws');
const debug = require('debug')('talk:graph:subscriptions');
const { getBroker } = require('./broker');
const { getPubsub } = require('./pubsub');
const schema = require('../schema');
const Context = require('../context');
@@ -116,6 +115,4 @@ const createSubscriptionManager = server =>
module.exports = {
createSubscriptionManager,
getBroker,
getPubsub,
};
-4
View File
@@ -1,5 +1,4 @@
const { passport } = require('../services/passport');
const Context = require('../graph/context');
const debug = require('debug')('talk:middleware:authentication');
const authentication = (req, res, next) =>
@@ -23,9 +22,6 @@ const authentication = (req, res, next) =>
debug('user was not on request');
}
// Attach a new context to the request.
req.context = new Context(req);
next();
}
)(req, res, next);
+8
View File
@@ -0,0 +1,8 @@
const Context = require('../graph/context');
// Attach a new context to the request.
module.exports = (req, res, next) => {
req.context = new Context(req);
next();
};
+5 -1
View File
@@ -13,6 +13,7 @@ const staticMiddleware = require('express-static-gzip');
const { DISABLE_STATIC_SERVER } = require('../config');
const { passport } = require('../services/passport');
const { MOUNT_PATH } = require('../url');
const context = require('../middleware/context');
const router = express.Router();
@@ -100,9 +101,12 @@ plugins.get('server', 'passport').forEach(plugin => {
// Setup the PassportJS Middleware.
router.use(passport.initialize());
// Setup the Graph Context on the router.
router.use(authentication, context);
// Attach the authentication middleware, this will be responsible for decoding
// (if present) the JWT on the request.
router.use('/api', authentication, require('./api'));
router.use('/api', require('./api'));
//==============================================================================
// DEVELOPMENT ROUTES
-8
View File
@@ -1,17 +1,9 @@
const express = require('express');
const debug = require('debug')('talk:routes:plugins');
const plugins = require('../services/plugins');
const { connectors } = require('../graph');
const { set } = require('lodash');
const router = express.Router();
// Mount the connectors on the router.
router.use((req, res, next) => {
set(req, 'talk.connectors', connectors);
next();
});
// Inject server route plugins.
plugins.get('server', 'router').forEach(plugin => {
debug(`added plugin '${plugin.plugin.name}'`);