feat: apollo upgrade to 2.0 + dev improvements + localization

This commit is contained in:
NGPixel
2018-06-24 00:20:35 -04:00
parent 99d7078c2c
commit 49834461a6
16 changed files with 1088 additions and 565 deletions

View File

@@ -171,6 +171,7 @@ module.exports = class User extends Model {
}
static async login (opts, context) {
console.info(context)
if (_.has(WIKI.auth.strategies, opts.strategy)) {
_.set(context.req, 'body.email', opts.username)
_.set(context.req, 'body.password', opts.password)

View File

@@ -1,6 +1,6 @@
const _ = require('lodash')
const fs = require('fs')
const gqlTools = require('graphql-tools')
// const gqlTools = require('graphql-tools')
const path = require('path')
const autoload = require('auto-load')
@@ -24,11 +24,14 @@ resolversObj.forEach(resolver => {
_.merge(resolvers, resolver)
})
const Schema = gqlTools.makeExecutableSchema({
typeDefs,
resolvers
})
// const Schema = gqlTools.makeExecutableSchema({
// typeDefs,
// resolvers
// })
WIKI.logger.info(`GraphQL Schema: [ OK ]`)
module.exports = Schema
module.exports = {
typeDefs,
resolvers
}

View File

@@ -29,8 +29,6 @@ module.exports = {
osLabel = `${os.type()} - ${osInfo.dist} (${osInfo.codename || os.platform()}) ${osInfo.release || os.release()} ${os.arch()}`
}
console.info(WIKI.db.knex.client)
return {
configFile: path.join(process.cwd(), 'config.yml'),
currentVersion: WIKI.version,

View File

@@ -21,7 +21,10 @@ module.exports = {
.select('id', 'email', 'name', 'provider', 'role', 'createdAt', 'updatedAt')
},
async single(obj, args, context, info) {
return WIKI.db.users.query().findById(args.id)
let usr = await WIKI.db.users.query().findById(args.id)
usr.password = ''
usr.tfaSecret = ''
return usr
}
},
UserMutation: {

View File

@@ -13,14 +13,6 @@ enum RightRole {
manage
}
# INTERFACES
interface Base {
id: Int!
createdAt: Date
updatedAt: Date
}
# TYPES
type KeyValuePair {
@@ -43,7 +35,7 @@ type ResponseStatus {
message: String
}
type Comment implements Base {
type Comment {
id: Int!
createdAt: Date
updatedAt: Date
@@ -52,7 +44,7 @@ type Comment implements Base {
author: User!
}
type Document implements Base {
type Document {
id: Int!
createdAt: Date
updatedAt: Date
@@ -68,7 +60,7 @@ type Document implements Base {
tags: [Tag]
}
type File implements Base {
type File {
id: Int!
createdAt: Date
updatedAt: Date
@@ -81,7 +73,7 @@ type File implements Base {
folder: Folder
}
type Folder implements Base {
type Folder {
id: Int!
createdAt: Date
updatedAt: Date
@@ -89,7 +81,7 @@ type Folder implements Base {
files: [File]
}
type Right implements Base {
type Right {
id: Int!
createdAt: Date
updatedAt: Date
@@ -106,7 +98,7 @@ type SearchResult {
tags: [String]
}
type Setting implements Base {
type Setting {
id: Int!
createdAt: Date
updatedAt: Date
@@ -115,7 +107,7 @@ type Setting implements Base {
}
# Tags are attached to one or more documents
type Tag implements Base {
type Tag {
id: Int!
createdAt: Date
updatedAt: Date

View File

@@ -9,8 +9,7 @@ const http = require('http')
const path = require('path')
const session = require('express-session')
const SessionRedisStore = require('connect-redis')(session)
const graphqlApollo = require('apollo-server-express')
const graphqlSchema = require('./graph')
const { ApolloServer } = require('apollo-server-express')
// const oauth2orize = require('oauth2orize')
/* global WIKI */
@@ -124,23 +123,34 @@ module.exports = async () => {
}
// ----------------------------------------
// Controllers
// Apollo Server (GraphQL)
// ----------------------------------------
const graphqlSchema = require('./graph')
const apolloServer = new ApolloServer({
...graphqlSchema,
context: ({ req, res }) => ({ req, res })
})
apolloServer.applyMiddleware({ app })
// ----------------------------------------
// Routing
// ----------------------------------------
app.use('/', ctrl.auth)
app.use('/graphql', (req, res, next) => {
graphqlApollo.graphqlExpress({
schema: graphqlSchema,
context: { req, res },
formatError: (err) => {
return {
message: err.message
}
}
})(req, res, next)
})
app.use('/graphiql', graphqlApollo.graphiqlExpress({ endpointURL: '/graphql' }))
// app.use('/graphql', (req, res, next) => {
// graphqlApollo.graphqlExpress({
// schema: graphqlSchema,
// context: { req, res },
// formatError: (err) => {
// return {
// message: err.message
// }
// }
// })(req, res, next)
// })
// app.use('/graphiql', graphqlApollo.graphiqlExpress({ endpointURL: '/graphql' }))
app.use('/', mw.auth, ctrl.common)