feat: GraphQL base implementation
This commit is contained in:
@@ -214,20 +214,17 @@ module.exports = function (passport) {
|
||||
|
||||
return wiki.db.User.create({
|
||||
provider: 'local',
|
||||
email: 'guest',
|
||||
email: 'guest@example.com',
|
||||
name: 'Guest',
|
||||
password: '',
|
||||
rights: [{
|
||||
role: 'read',
|
||||
path: '/',
|
||||
exact: false,
|
||||
deny: !wiki.config.public
|
||||
}]
|
||||
role: 'guest'
|
||||
}).then(() => {
|
||||
wiki.logger.info('[AUTH] Guest account created successfully!')
|
||||
return true
|
||||
}).catch((err) => {
|
||||
wiki.logger.error('[AUTH] An error occured while creating guest account:')
|
||||
wiki.logger.error(err)
|
||||
return err
|
||||
})
|
||||
}
|
||||
}).then(() => {
|
||||
@@ -241,17 +238,14 @@ module.exports = function (passport) {
|
||||
email: process.env.WIKI_ADMIN_EMAIL,
|
||||
name: 'Administrator',
|
||||
password: '$2a$04$MAHRw785Xe/Jd5kcKzr3D.VRZDeomFZu2lius4gGpZZ9cJw7B7Mna', // admin123 (default)
|
||||
rights: [{
|
||||
role: 'admin',
|
||||
path: '/',
|
||||
exact: false,
|
||||
deny: false
|
||||
}]
|
||||
role: 'admin'
|
||||
}).then(() => {
|
||||
wiki.logger.info('[AUTH] Root admin account created successfully!')
|
||||
return true
|
||||
}).catch((err) => {
|
||||
wiki.logger.error('[AUTH] An error occured while creating root admin account:')
|
||||
wiki.logger.error(err)
|
||||
return err
|
||||
})
|
||||
} else { return true }
|
||||
})
|
||||
|
@@ -64,8 +64,7 @@ module.exports = {
|
||||
// Sync DB
|
||||
|
||||
self.onReady = self.inst.sync({
|
||||
force: false,
|
||||
logging: wiki.logger.verbose
|
||||
force: false
|
||||
})
|
||||
|
||||
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