You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.8 KiB

  1. const _ = require('lodash')
  2. const graphHelper = require('../../helpers/graph')
  3. /* global WIKI */
  4. module.exports = {
  5. Query: {
  6. async logging() { return {} }
  7. },
  8. Mutation: {
  9. async logging() { return {} }
  10. },
  11. Subscription: {
  12. loggingLiveTrail: {
  13. subscribe: () => WIKI.GQLEmitter.asyncIterator('livetrail')
  14. }
  15. },
  16. LoggingQuery: {
  17. async loggers(obj, args, context, info) {
  18. let loggers = await WIKI.models.loggers.getLoggers()
  19. loggers = loggers.map(logger => {
  20. const loggerInfo = _.find(WIKI.data.loggers, ['key', logger.key]) || {}
  21. return {
  22. ...loggerInfo,
  23. ...logger,
  24. config: _.sortBy(_.transform(logger.config, (res, value, key) => {
  25. const configData = _.get(loggerInfo.props, key, {})
  26. res.push({
  27. key,
  28. value: JSON.stringify({
  29. ...configData,
  30. value
  31. })
  32. })
  33. }, []), 'key')
  34. }
  35. })
  36. if (args.filter) { loggers = graphHelper.filter(loggers, args.filter) }
  37. if (args.orderBy) { loggers = graphHelper.orderBy(loggers, args.orderBy) }
  38. return loggers
  39. }
  40. },
  41. LoggingMutation: {
  42. async updateLoggers(obj, args, context) {
  43. try {
  44. for (let logger of args.loggers) {
  45. await WIKI.models.loggers.query().patch({
  46. isEnabled: logger.isEnabled,
  47. level: logger.level,
  48. config: _.reduce(logger.config, (result, value, key) => {
  49. _.set(result, `${value.key}`, value.value)
  50. return result
  51. }, {})
  52. }).where('key', logger.key)
  53. }
  54. return {
  55. responseResult: graphHelper.generateSuccess('Loggers updated successfully')
  56. }
  57. } catch (err) {
  58. return graphHelper.generateError(err)
  59. }
  60. }
  61. }
  62. }