wikijs-fork/server/graph/resolvers/navigation.js
2020-04-18 18:33:22 -04:00

51 lines
1.2 KiB
JavaScript

const graphHelper = require('../../helpers/graph')
/* global WIKI */
module.exports = {
Query: {
async navigation () { return {} }
},
Mutation: {
async navigation () { return {} }
},
NavigationQuery: {
async tree (obj, args, context, info) {
return WIKI.models.navigation.getTree({ cache: false, locale: 'all' })
},
config (obj, args, context, info) {
return WIKI.config.nav
}
},
NavigationMutation: {
async updateTree (obj, args, context) {
try {
await WIKI.models.navigation.query().patch({
config: args.tree
}).where('key', 'site')
await WIKI.cache.set('nav:sidebar', args.tree, 300)
return {
responseResult: graphHelper.generateSuccess('Navigation updated successfully')
}
} catch (err) {
return graphHelper.generateError(err)
}
},
async updateConfig (obj, args, context) {
try {
WIKI.config.nav = {
mode: args.mode
}
await WIKI.configSvc.saveToDb(['nav'])
return {
responseResult: graphHelper.generateSuccess('Navigation config updated successfully')
}
} catch (err) {
return graphHelper.generateError(err)
}
}
}
}