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.

60 lines
1.8 KiB

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