fix: modules non-string config + live trail logging
This commit is contained in:
@@ -3,11 +3,18 @@ const fs = require('fs')
|
||||
// const gqlTools = require('graphql-tools')
|
||||
const path = require('path')
|
||||
const autoload = require('auto-load')
|
||||
const PubSub = require('graphql-subscriptions').PubSub
|
||||
const util = require('util')
|
||||
const winston = require('winston')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
WIKI.logger.info(`Loading GraphQL Schema...`)
|
||||
|
||||
// Init Subscription PubSub
|
||||
|
||||
WIKI.GQLEmitter = new PubSub()
|
||||
|
||||
// Schemas
|
||||
|
||||
let typeDefs = []
|
||||
@@ -24,10 +31,25 @@ resolversObj.forEach(resolver => {
|
||||
_.merge(resolvers, resolver)
|
||||
})
|
||||
|
||||
// const Schema = gqlTools.makeExecutableSchema({
|
||||
// typeDefs,
|
||||
// resolvers
|
||||
// })
|
||||
// Live Trail Logger (admin)
|
||||
|
||||
let LiveTrailLogger = winston.transports.LiveTrailLogger = function (options) {
|
||||
this.name = 'livetrailLogger'
|
||||
this.level = 'debug'
|
||||
}
|
||||
util.inherits(LiveTrailLogger, winston.Transport)
|
||||
LiveTrailLogger.prototype.log = function (level, msg, meta, callback) {
|
||||
WIKI.GQLEmitter.publish('livetrail', {
|
||||
loggingLiveTrail: {
|
||||
timestamp: new Date(),
|
||||
level,
|
||||
output: msg
|
||||
}
|
||||
})
|
||||
callback(null, true)
|
||||
}
|
||||
|
||||
WIKI.logger.add(new LiveTrailLogger({}))
|
||||
|
||||
WIKI.logger.info(`GraphQL Schema: [ OK ]`)
|
||||
|
||||
|
@@ -68,7 +68,7 @@ module.exports = {
|
||||
await WIKI.models.authentication.query().patch({
|
||||
isEnabled: str.isEnabled,
|
||||
config: _.reduce(str.config, (result, value, key) => {
|
||||
_.set(result, `${value.key}.value`, value.value)
|
||||
_.set(result, `${value.key}`, _.get(JSON.parse(value.value), 'v', null))
|
||||
return result
|
||||
}, {}),
|
||||
selfRegistration: str.selfRegistration,
|
||||
|
@@ -10,6 +10,11 @@ module.exports = {
|
||||
Mutation: {
|
||||
async logging() { return {} }
|
||||
},
|
||||
Subscription: {
|
||||
loggingLiveTrail: {
|
||||
subscribe: () => WIKI.GQLEmitter.asyncIterator('livetrail')
|
||||
}
|
||||
},
|
||||
LoggingQuery: {
|
||||
async loggers(obj, args, context, info) {
|
||||
let loggers = await WIKI.models.loggers.getLoggers()
|
||||
|
@@ -42,7 +42,7 @@ module.exports = {
|
||||
await WIKI.models.searchEngines.query().patch({
|
||||
isEnabled: searchEngine.isEnabled,
|
||||
config: _.reduce(searchEngine.config, (result, value, key) => {
|
||||
_.set(result, `${value.key}`, value.value)
|
||||
_.set(result, `${value.key}`, _.get(JSON.parse(value.value), 'v', null))
|
||||
return result
|
||||
}, {})
|
||||
}).where('key', searchEngine.key)
|
||||
|
@@ -43,7 +43,7 @@ module.exports = {
|
||||
isEnabled: tgt.isEnabled,
|
||||
mode: tgt.mode,
|
||||
config: _.reduce(tgt.config, (result, value, key) => {
|
||||
_.set(result, `${value.key}`, value.value)
|
||||
_.set(result, `${value.key}`, _.get(JSON.parse(value.value), 'v', null))
|
||||
return result
|
||||
}, {})
|
||||
}).where('key', tgt.key)
|
||||
|
@@ -250,3 +250,5 @@ type Mutation {
|
||||
filename: String!
|
||||
): File
|
||||
}
|
||||
|
||||
type Subscription
|
||||
|
@@ -10,6 +10,10 @@ extend type Mutation {
|
||||
logging: LoggingMutation
|
||||
}
|
||||
|
||||
extend type Subscription {
|
||||
loggingLiveTrail: LoggerTrailLine
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# QUERIES
|
||||
# -----------------------------------------------
|
||||
@@ -52,3 +56,9 @@ input LoggerInput {
|
||||
level: String!
|
||||
config: [KeyValuePairInput]
|
||||
}
|
||||
|
||||
type LoggerTrailLine {
|
||||
level: String!
|
||||
output: String!
|
||||
timestamp: Date!
|
||||
}
|
||||
|
@@ -129,7 +129,13 @@ module.exports = async () => {
|
||||
const graphqlSchema = require('./graph')
|
||||
const apolloServer = new ApolloServer({
|
||||
...graphqlSchema,
|
||||
context: ({ req, res }) => ({ req, res })
|
||||
context: ({ req, res }) => ({ req, res }),
|
||||
subscriptions: {
|
||||
onConnect: (connectionParams, webSocket) => {
|
||||
|
||||
},
|
||||
path: '/graphql-subscriptions'
|
||||
}
|
||||
})
|
||||
apolloServer.applyMiddleware({ app })
|
||||
|
||||
@@ -169,6 +175,7 @@ module.exports = async () => {
|
||||
|
||||
app.set('port', WIKI.config.port)
|
||||
WIKI.server = http.createServer(app)
|
||||
apolloServer.installSubscriptionHandlers(WIKI.server)
|
||||
|
||||
WIKI.server.listen(WIKI.config.port, WIKI.config.bindIP)
|
||||
WIKI.server.on('error', (error) => {
|
||||
|
Reference in New Issue
Block a user