wikijs-fork/server/graph/resolvers/navigation.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

const graphHelper = require('../../helpers/graph')
/* global WIKI */
module.exports = {
Query: {
2020-04-12 22:05:48 +00:00
async navigation () { return {} }
},
Mutation: {
2020-04-12 22:05:48 +00:00
async navigation () { return {} }
},
NavigationQuery: {
2020-04-12 22:05:48 +00:00
async tree (obj, args, context, info) {
return WIKI.models.navigation.getTree({ cache: false, locale: 'all', bypassAuth: true })
2020-04-12 22:05:48 +00:00
},
config (obj, args, context, info) {
return WIKI.config.nav
}
},
NavigationMutation: {
2020-04-12 22:05:48 +00:00
async updateTree (obj, args, context) {
try {
2018-10-22 02:25:17 +00:00
await WIKI.models.navigation.query().patch({
config: args.tree
}).where('key', 'site')
for (const tree of args.tree) {
await WIKI.cache.set(`nav:sidebar:${tree.locale}`, tree.items, 300)
}
2018-10-22 02:25:17 +00:00
return {
responseResult: graphHelper.generateSuccess('Navigation updated successfully')
}
} catch (err) {
return graphHelper.generateError(err)
}
2020-04-12 22:05:48 +00:00
},
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)
}
}
}
}