feat: GraphQL base implementation
This commit is contained in:
@@ -37,6 +37,7 @@
|
|||||||
"node": ">=6.11.1"
|
"node": ">=6.11.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"apollo-server-express": "~1.0.4",
|
||||||
"auto-load": "~3.0.0",
|
"auto-load": "~3.0.0",
|
||||||
"axios": "~0.16.2",
|
"axios": "~0.16.2",
|
||||||
"bcryptjs-then": "~1.0.1",
|
"bcryptjs-then": "~1.0.1",
|
||||||
@@ -62,6 +63,7 @@
|
|||||||
"follow-redirects": "~1.2.4",
|
"follow-redirects": "~1.2.4",
|
||||||
"fs-extra": "~4.0.0",
|
"fs-extra": "~4.0.0",
|
||||||
"git-wrapper2-promise": "~0.2.9",
|
"git-wrapper2-promise": "~0.2.9",
|
||||||
|
"graphql": "~0.10.5",
|
||||||
"highlight.js": "~9.12.0",
|
"highlight.js": "~9.12.0",
|
||||||
"i18next": "~8.4.3",
|
"i18next": "~8.4.3",
|
||||||
"i18next-express-middleware": "~1.0.5",
|
"i18next-express-middleware": "~1.0.5",
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ const session = require('express-session')
|
|||||||
const SessionRedisStore = require('connect-redis')(session)
|
const SessionRedisStore = require('connect-redis')(session)
|
||||||
const graceful = require('node-graceful')
|
const graceful = require('node-graceful')
|
||||||
const socketio = require('socket.io')
|
const socketio = require('socket.io')
|
||||||
|
const graphqlApollo = require('apollo-server-express')
|
||||||
|
const graphqlSchema = require('./modules/graphql')
|
||||||
|
|
||||||
var mw = autoload(path.join(wiki.SERVERPATH, '/middlewares'))
|
var mw = autoload(path.join(wiki.SERVERPATH, '/middlewares'))
|
||||||
var ctrl = autoload(path.join(wiki.SERVERPATH, '/controllers'))
|
var ctrl = autoload(path.join(wiki.SERVERPATH, '/controllers'))
|
||||||
@@ -167,6 +169,8 @@ app.use(mw.flash)
|
|||||||
|
|
||||||
app.use('/', ctrl.auth)
|
app.use('/', ctrl.auth)
|
||||||
|
|
||||||
|
app.use('/graphql', graphqlApollo.graphqlExpress({ schema: graphqlSchema }))
|
||||||
|
app.use('/graphiql', graphqlApollo.graphiqlExpress({ endpointURL: '/graphql' }))
|
||||||
app.use('/uploads', mw.auth, ctrl.uploads)
|
app.use('/uploads', mw.auth, ctrl.uploads)
|
||||||
app.use('/admin', mw.auth, ctrl.admin)
|
app.use('/admin', mw.auth, ctrl.admin)
|
||||||
app.use('/', mw.auth, ctrl.pages)
|
app.use('/', mw.auth, ctrl.pages)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
/* global app */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Security Middleware
|
* Security Middleware
|
||||||
*
|
*
|
||||||
@@ -12,7 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
module.exports = function (req, res, next) {
|
module.exports = function (req, res, next) {
|
||||||
// -> Disable X-Powered-By
|
// -> Disable X-Powered-By
|
||||||
app.disable('x-powered-by')
|
req.app.disable('x-powered-by')
|
||||||
|
|
||||||
// -> Disable Frame Embedding
|
// -> Disable Frame Embedding
|
||||||
res.set('X-Frame-Options', 'deny')
|
res.set('X-Frame-Options', 'deny')
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
deny: false
|
deny: false
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
return db.User.create(nUsr)
|
return wiki.db.User.create(nUsr)
|
||||||
}
|
}
|
||||||
return user || Promise.reject(new Error(wiki.lang.t('auth:errors:notyetauthorized')))
|
return user || Promise.reject(new Error(wiki.lang.t('auth:errors:notyetauthorized')))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -214,20 +214,17 @@ module.exports = function (passport) {
|
|||||||
|
|
||||||
return wiki.db.User.create({
|
return wiki.db.User.create({
|
||||||
provider: 'local',
|
provider: 'local',
|
||||||
email: 'guest',
|
email: 'guest@example.com',
|
||||||
name: 'Guest',
|
name: 'Guest',
|
||||||
password: '',
|
password: '',
|
||||||
rights: [{
|
role: 'guest'
|
||||||
role: 'read',
|
|
||||||
path: '/',
|
|
||||||
exact: false,
|
|
||||||
deny: !wiki.config.public
|
|
||||||
}]
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
wiki.logger.info('[AUTH] Guest account created successfully!')
|
wiki.logger.info('[AUTH] Guest account created successfully!')
|
||||||
|
return true
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
wiki.logger.error('[AUTH] An error occured while creating guest account:')
|
wiki.logger.error('[AUTH] An error occured while creating guest account:')
|
||||||
wiki.logger.error(err)
|
wiki.logger.error(err)
|
||||||
|
return err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
@@ -241,17 +238,14 @@ module.exports = function (passport) {
|
|||||||
email: process.env.WIKI_ADMIN_EMAIL,
|
email: process.env.WIKI_ADMIN_EMAIL,
|
||||||
name: 'Administrator',
|
name: 'Administrator',
|
||||||
password: '$2a$04$MAHRw785Xe/Jd5kcKzr3D.VRZDeomFZu2lius4gGpZZ9cJw7B7Mna', // admin123 (default)
|
password: '$2a$04$MAHRw785Xe/Jd5kcKzr3D.VRZDeomFZu2lius4gGpZZ9cJw7B7Mna', // admin123 (default)
|
||||||
rights: [{
|
role: 'admin'
|
||||||
role: 'admin',
|
|
||||||
path: '/',
|
|
||||||
exact: false,
|
|
||||||
deny: false
|
|
||||||
}]
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
wiki.logger.info('[AUTH] Root admin account created successfully!')
|
wiki.logger.info('[AUTH] Root admin account created successfully!')
|
||||||
|
return true
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
wiki.logger.error('[AUTH] An error occured while creating root admin account:')
|
wiki.logger.error('[AUTH] An error occured while creating root admin account:')
|
||||||
wiki.logger.error(err)
|
wiki.logger.error(err)
|
||||||
|
return err
|
||||||
})
|
})
|
||||||
} else { return true }
|
} else { return true }
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -64,8 +64,7 @@ module.exports = {
|
|||||||
// Sync DB
|
// Sync DB
|
||||||
|
|
||||||
self.onReady = self.inst.sync({
|
self.onReady = self.inst.sync({
|
||||||
force: false,
|
force: false
|
||||||
logging: wiki.logger.verbose
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|||||||
67
server/modules/graphql.js
Normal file
67
server/modules/graphql.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
/* global wiki */
|
||||||
|
|
||||||
|
const gql = require('graphql')
|
||||||
|
|
||||||
|
const User = new gql.GraphQLObjectType({
|
||||||
|
name: 'User',
|
||||||
|
description: 'A User',
|
||||||
|
fields() {
|
||||||
|
return {
|
||||||
|
id: {
|
||||||
|
type: gql.GraphQLInt,
|
||||||
|
resolve(usr) {
|
||||||
|
return usr.id
|
||||||
|
}
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
type: gql.GraphQLString,
|
||||||
|
resolve(usr) {
|
||||||
|
return usr.email
|
||||||
|
}
|
||||||
|
},
|
||||||
|
provider: {
|
||||||
|
type: gql.GraphQLString,
|
||||||
|
resolve(usr) {
|
||||||
|
return usr.provider
|
||||||
|
}
|
||||||
|
},
|
||||||
|
providerId: {
|
||||||
|
type: gql.GraphQLString,
|
||||||
|
resolve(usr) {
|
||||||
|
return usr.providerId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const Query = new gql.GraphQLObjectType({
|
||||||
|
name: 'Query',
|
||||||
|
description: 'Root Query',
|
||||||
|
fields() {
|
||||||
|
return {
|
||||||
|
users: {
|
||||||
|
type: new gql.GraphQLList(User),
|
||||||
|
args: {
|
||||||
|
id: {
|
||||||
|
type: gql.GraphQLInt
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
type: gql.GraphQLString
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resolve(root, args) {
|
||||||
|
return wiki.db.User.findAll({ where: args })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const Schema = new gql.GraphQLSchema({
|
||||||
|
query: Query
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = Schema
|
||||||
Reference in New Issue
Block a user