wikijs-fork/server/jobs/sync-graph-updates.js

42 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2019-01-13 20:37:45 +00:00
const _ = require('lodash')
const { createApolloFetch } = require('apollo-fetch')
/* global WIKI */
module.exports = async () => {
2019-01-13 20:37:45 +00:00
WIKI.logger.info(`Fetching latest updates from Graph endpoint...`)
try {
const apollo = createApolloFetch({
uri: WIKI.config.graphEndpoint
})
const resp = await apollo({
query: `query ($channel: ReleaseChannel!, $version: String!) {
releases {
checkForUpdates(channel: $channel, version: $version) {
channel
version
releaseDate
minimumVersionRequired
minimumNodeRequired
}
}
}`,
variables: {
2019-06-09 01:00:12 +00:00
channel: WIKI.config.channel,
2019-01-13 20:37:45 +00:00
version: WIKI.version
}
})
const info = _.get(resp, 'data.releases.checkForUpdates', false)
if (info) {
WIKI.system.updates = info
}
2019-01-13 20:37:45 +00:00
WIKI.logger.info(`Fetching latest updates from Graph endpoint: [ COMPLETED ]`)
} catch (err) {
WIKI.logger.error(`Fetching latest updates from Graph endpoint: [ FAILED ]`)
WIKI.logger.error(err.message)
}
}