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.

58 lines
1.7 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, {})
  21. res.push({
  22. key,
  23. value: JSON.stringify({
  24. ...configData,
  25. value
  26. })
  27. })
  28. }, []), 'key')
  29. }
  30. })
  31. if (args.filter) { renderers = graphHelper.filter(renderers, args.filter) }
  32. if (args.orderBy) { renderers = graphHelper.orderBy(renderers, args.orderBy) }
  33. return renderers
  34. }
  35. },
  36. RenderingMutation: {
  37. async updateRenderers(obj, args, context) {
  38. try {
  39. for (let rdr of args.renderers) {
  40. await WIKI.models.storage.query().patch({
  41. isEnabled: rdr.isEnabled,
  42. config: _.reduce(rdr.config, (result, value, key) => {
  43. _.set(result, `${value.key}`, value.value)
  44. return result
  45. }, {})
  46. }).where('key', rdr.key)
  47. }
  48. return {
  49. responseResult: graphHelper.generateSuccess('Renderers updated successfully')
  50. }
  51. } catch (err) {
  52. return graphHelper.generateError(err)
  53. }
  54. }
  55. }
  56. }