2018-03-05 20:49:36 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
const fs = require('fs')
|
2018-06-24 04:20:35 +00:00
|
|
|
// const gqlTools = require('graphql-tools')
|
2018-03-05 20:49:36 +00:00
|
|
|
const path = require('path')
|
|
|
|
const autoload = require('auto-load')
|
2018-09-30 18:20:26 +00:00
|
|
|
const PubSub = require('graphql-subscriptions').PubSub
|
2018-11-18 21:38:00 +00:00
|
|
|
const { LEVEL, MESSAGE } = require('triple-beam')
|
|
|
|
const Transport = require('winston-transport')
|
2018-03-05 20:49:36 +00:00
|
|
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
WIKI.logger.info(`Loading GraphQL Schema...`)
|
|
|
|
|
2018-09-30 18:20:26 +00:00
|
|
|
// Init Subscription PubSub
|
|
|
|
|
|
|
|
WIKI.GQLEmitter = new PubSub()
|
|
|
|
|
2018-03-05 20:49:36 +00:00
|
|
|
// Schemas
|
|
|
|
|
|
|
|
let typeDefs = []
|
|
|
|
let schemas = fs.readdirSync(path.join(WIKI.SERVERPATH, 'graph/schemas'))
|
|
|
|
schemas.forEach(schema => {
|
|
|
|
typeDefs.push(fs.readFileSync(path.join(WIKI.SERVERPATH, `graph/schemas/${schema}`), 'utf8'))
|
|
|
|
})
|
|
|
|
|
|
|
|
// Resolvers
|
|
|
|
|
|
|
|
let resolvers = {}
|
|
|
|
const resolversObj = _.values(autoload(path.join(WIKI.SERVERPATH, 'graph/resolvers')))
|
|
|
|
resolversObj.forEach(resolver => {
|
|
|
|
_.merge(resolvers, resolver)
|
|
|
|
})
|
|
|
|
|
2018-10-08 04:17:31 +00:00
|
|
|
// Directives
|
|
|
|
|
|
|
|
let schemaDirectives = autoload(path.join(WIKI.SERVERPATH, 'graph/directives'))
|
|
|
|
|
2018-09-30 18:20:26 +00:00
|
|
|
// Live Trail Logger (admin)
|
|
|
|
|
2018-11-18 21:38:00 +00:00
|
|
|
class LiveTrailLogger extends Transport {
|
|
|
|
constructor(opts) {
|
|
|
|
super(opts)
|
|
|
|
|
|
|
|
this.name = 'liveTrailLogger'
|
|
|
|
this.level = 'debug'
|
|
|
|
}
|
|
|
|
|
|
|
|
log (info, callback = () => {}) {
|
|
|
|
WIKI.GQLEmitter.publish('livetrail', {
|
|
|
|
loggingLiveTrail: {
|
|
|
|
timestamp: new Date(),
|
|
|
|
level: info[LEVEL],
|
|
|
|
output: info[MESSAGE]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
callback(null, true)
|
|
|
|
}
|
2018-09-30 18:20:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WIKI.logger.add(new LiveTrailLogger({}))
|
2018-03-05 20:49:36 +00:00
|
|
|
|
|
|
|
WIKI.logger.info(`GraphQL Schema: [ OK ]`)
|
|
|
|
|
2018-06-24 04:20:35 +00:00
|
|
|
module.exports = {
|
|
|
|
typeDefs,
|
2018-10-08 04:17:31 +00:00
|
|
|
resolvers,
|
|
|
|
schemaDirectives
|
2018-06-24 04:20:35 +00:00
|
|
|
}
|