2018-03-05 20:49:36 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
const fs = require('fs')
|
2018-06-24 04:20:35 +00:00
|
|
|
// const gqlTools = require('graphql-tools')
|
2018-03-05 20:49:36 +00:00
|
|
|
const path = require('path')
|
|
|
|
const autoload = require('auto-load')
|
|
|
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
WIKI.logger.info(`Loading GraphQL Schema...`)
|
|
|
|
|
|
|
|
// Schemas
|
|
|
|
|
|
|
|
let typeDefs = []
|
|
|
|
let schemas = fs.readdirSync(path.join(WIKI.SERVERPATH, 'graph/schemas'))
|
|
|
|
schemas.forEach(schema => {
|
|
|
|
typeDefs.push(fs.readFileSync(path.join(WIKI.SERVERPATH, `graph/schemas/${schema}`), 'utf8'))
|
|
|
|
})
|
|
|
|
|
|
|
|
// Resolvers
|
|
|
|
|
|
|
|
let resolvers = {}
|
|
|
|
const resolversObj = _.values(autoload(path.join(WIKI.SERVERPATH, 'graph/resolvers')))
|
|
|
|
resolversObj.forEach(resolver => {
|
|
|
|
_.merge(resolvers, resolver)
|
|
|
|
})
|
|
|
|
|
2018-06-24 04:20:35 +00:00
|
|
|
// const Schema = gqlTools.makeExecutableSchema({
|
|
|
|
// typeDefs,
|
|
|
|
// resolvers
|
|
|
|
// })
|
2018-03-05 20:49:36 +00:00
|
|
|
|
|
|
|
WIKI.logger.info(`GraphQL Schema: [ OK ]`)
|
|
|
|
|
2018-06-24 04:20:35 +00:00
|
|
|
module.exports = {
|
|
|
|
typeDefs,
|
|
|
|
resolvers
|
|
|
|
}
|