Commit b1c715a2 authored by Alexandru Munteanu's avatar Alexandru Munteanu

feat(pubsweet-server): add loaders object to gql context

parent 98fb9c0e
Pipeline #13068 passed with stages
in 11 minutes and 21 seconds
......@@ -18,6 +18,7 @@ const sse = require('pubsweet-sse')
const _ = require('lodash/fp')
const STATUS = require('http-status-codes')
const registerLoaders = require('./register-loaders')
const registerComponents = require('./register-components')
const configureApp = app => {
......@@ -71,6 +72,7 @@ const configureApp = app => {
app.locals.authsome = authsome
registerComponents(app)
registerLoaders(app)
// REST API
app.use('/api', api)
......
......@@ -27,9 +27,10 @@ const api = app => {
const server = new ApolloServer({
schema,
context: ({ req, res }) => ({
user: req.user,
connectors,
helpers,
connectors,
user: req.user,
loaders: req.loaders,
}),
formatError: err => {
const error = err.originalError || err
......
const logger = require('@pubsweet/logger')
const config = require('config')
const tryRequireRelative = require('./helpers/tryRequireRelative')
module.exports = app => {
logger.info(`Registering data loaders...`)
const loaders = config
.get('pubsweet.components')
.reduce((acc, componentName) => {
const component = tryRequireRelative(componentName)
if (component.loaders) {
return {
...acc,
[componentName.replace('component-', '')]: component.loaders,
}
}
return acc
}, {})
app.use((req, res, next) => {
req.loaders = loaders
next()
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment