feat: GraphQL schema
This commit is contained in:
parent
62067caa62
commit
437b88bf58
@ -64,6 +64,7 @@
|
|||||||
"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",
|
"graphql": "~0.10.5",
|
||||||
|
"graphql-tools": "/home/nick1.1.0",
|
||||||
"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",
|
||||||
|
@ -48,9 +48,9 @@ if (numWorkers > numCPUs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cluster.isMaster) {
|
if (cluster.isMaster) {
|
||||||
wiki.logger.info('--------------------------')
|
wiki.logger.info('=======================================')
|
||||||
wiki.logger.info('Wiki.js is initializing...')
|
wiki.logger.info('= Wiki.js =============================')
|
||||||
wiki.logger.info('--------------------------')
|
wiki.logger.info('=======================================')
|
||||||
|
|
||||||
require('./master').then(() => {
|
require('./master').then(() => {
|
||||||
// -> Create background workers
|
// -> Create background workers
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
module.exports = db => {
|
module.exports = db => {
|
||||||
db.User.belongsToMany(db.Group, { through: 'userGroups' })
|
db.User.belongsToMany(db.Group, { through: 'userGroups' })
|
||||||
|
db.Group.belongsToMany(db.User, { through: 'userGroups' })
|
||||||
db.Group.hasMany(db.Right, { as: 'groupRights' })
|
db.Group.hasMany(db.Right, { as: 'groupRights' })
|
||||||
db.Document.hasMany(db.Tag, { as: 'documentTags' })
|
db.Document.hasMany(db.Tag, { as: 'documentTags' })
|
||||||
db.File.belongsTo(db.Folder)
|
db.File.belongsTo(db.Folder)
|
||||||
|
@ -2,66 +2,27 @@
|
|||||||
|
|
||||||
/* global wiki */
|
/* global wiki */
|
||||||
|
|
||||||
const gql = require('graphql')
|
const gqlTools = require('graphql-tools')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
const User = new gql.GraphQLObjectType({
|
const typeDefs = fs.readFileSync(path.join(wiki.SERVERPATH, 'schemas/types.graphql'), 'utf8')
|
||||||
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({
|
const GroupResolvers = require('../schemas/resolvers-group')
|
||||||
name: 'Query',
|
const UserResolvers = require('../schemas/resolvers-user')
|
||||||
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({
|
const resolvers = {
|
||||||
query: Query
|
Query: {
|
||||||
|
groups: GroupResolvers.Query,
|
||||||
|
users: UserResolvers.Query
|
||||||
|
},
|
||||||
|
Group: GroupResolvers.Type,
|
||||||
|
User: UserResolvers.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
const Schema = gqlTools.makeExecutableSchema({
|
||||||
|
typeDefs,
|
||||||
|
resolvers
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = Schema
|
module.exports = Schema
|
||||||
|
14
server/schemas/resolvers-group.js
Normal file
14
server/schemas/resolvers-group.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
/* global wiki */
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Query(obj, args, context, info) {
|
||||||
|
return wiki.db.Group.findAll({ where: args })
|
||||||
|
},
|
||||||
|
Type: {
|
||||||
|
users(grp) {
|
||||||
|
return grp.getUsers()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
server/schemas/resolvers-user.js
Normal file
14
server/schemas/resolvers-user.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
/* global wiki */
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Query(obj, args, context, info) {
|
||||||
|
return wiki.db.User.findAll({ where: args })
|
||||||
|
},
|
||||||
|
Type: {
|
||||||
|
groups(usr) {
|
||||||
|
return usr.getGroups()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
136
server/schemas/types.graphql
Normal file
136
server/schemas/types.graphql
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
# SCALARS
|
||||||
|
|
||||||
|
scalar Date
|
||||||
|
|
||||||
|
# ENUMS
|
||||||
|
|
||||||
|
enum UserRole {
|
||||||
|
guest
|
||||||
|
user
|
||||||
|
admin
|
||||||
|
}
|
||||||
|
|
||||||
|
enum FileType {
|
||||||
|
binary
|
||||||
|
image
|
||||||
|
}
|
||||||
|
|
||||||
|
enum RightRole {
|
||||||
|
read
|
||||||
|
write
|
||||||
|
manage
|
||||||
|
}
|
||||||
|
|
||||||
|
# INTERFACES
|
||||||
|
|
||||||
|
interface Base {
|
||||||
|
id: Int!
|
||||||
|
createdOn: Date
|
||||||
|
updatedOn: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
# TYPES
|
||||||
|
|
||||||
|
type Comment implements Base {
|
||||||
|
id: Int!
|
||||||
|
createdOn: Date
|
||||||
|
updatedOn: Date
|
||||||
|
content: String
|
||||||
|
document: Document!
|
||||||
|
author: User!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Document implements Base {
|
||||||
|
id: Int!
|
||||||
|
createdOn: Date
|
||||||
|
updatedOn: Date
|
||||||
|
path: String!
|
||||||
|
title: String!
|
||||||
|
subtitle: String
|
||||||
|
parentPath: String
|
||||||
|
parentTitle: String
|
||||||
|
isDirectory: Boolean!
|
||||||
|
isEntry: Boolean!
|
||||||
|
searchContent: String
|
||||||
|
tags: [Tag]
|
||||||
|
}
|
||||||
|
|
||||||
|
type File implements Base {
|
||||||
|
id: Int!
|
||||||
|
createdOn: Date
|
||||||
|
updatedOn: Date
|
||||||
|
category: FileType!
|
||||||
|
mime: String!
|
||||||
|
extra: String
|
||||||
|
filename: String!
|
||||||
|
basename: String!
|
||||||
|
filesize: Int!
|
||||||
|
folder: Folder
|
||||||
|
}
|
||||||
|
|
||||||
|
type Folder implements Base {
|
||||||
|
id: Int!
|
||||||
|
createdOn: Date
|
||||||
|
updatedOn: Date
|
||||||
|
name: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Group implements Base {
|
||||||
|
id: Int!
|
||||||
|
createdOn: Date
|
||||||
|
updatedOn: Date
|
||||||
|
name: String!
|
||||||
|
users: [User]
|
||||||
|
rights: [Right]
|
||||||
|
}
|
||||||
|
|
||||||
|
type Right implements Base {
|
||||||
|
id: Int!
|
||||||
|
createdOn: Date
|
||||||
|
updatedOn: Date
|
||||||
|
path: String!
|
||||||
|
role: RightRole!
|
||||||
|
exact: Boolean!
|
||||||
|
allow: Boolean!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Setting implements Base {
|
||||||
|
id: Int!
|
||||||
|
createdOn: Date
|
||||||
|
updatedOn: Date
|
||||||
|
key: String!
|
||||||
|
config: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tag implements Base {
|
||||||
|
id: Int!
|
||||||
|
createdOn: Date
|
||||||
|
updatedOn: Date
|
||||||
|
key: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
type User implements Base {
|
||||||
|
id: Int!
|
||||||
|
createdOn: Date
|
||||||
|
updatedOn: Date
|
||||||
|
email: String!
|
||||||
|
provider: String
|
||||||
|
providerId: String
|
||||||
|
name: String
|
||||||
|
role: UserRole!
|
||||||
|
groups: [Group]
|
||||||
|
}
|
||||||
|
|
||||||
|
# QUERY
|
||||||
|
|
||||||
|
type Query {
|
||||||
|
comments(id: Int): [Comment]
|
||||||
|
documents(id: Int, path: String): [Document]
|
||||||
|
files(id: Int): [File]
|
||||||
|
folders(id: Int, name: String): [Folder]
|
||||||
|
groups(id: Int, name: String): [Group]
|
||||||
|
rights(id: Int): [Right]
|
||||||
|
settings(key: String): [Setting]
|
||||||
|
tags(key: String): [Tag]
|
||||||
|
users(id: Int, email: String, provider: String, providerId: String, role: UserRole): [User]
|
||||||
|
}
|
14
yarn.lock
14
yarn.lock
@ -1794,6 +1794,10 @@ depd@1.1.0, depd@^1.1.0, depd@~1.1.0:
|
|||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.0.tgz#e1bd82c6aab6ced965b97b88b17ed3e528ca18c3"
|
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.0.tgz#e1bd82c6aab6ced965b97b88b17ed3e528ca18c3"
|
||||||
|
|
||||||
|
deprecated-decorator@^0.1.6:
|
||||||
|
version "0.1.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz#00966317b7a12fe92f3cc831f7583af329b86c37"
|
||||||
|
|
||||||
destroy@~1.0.4:
|
destroy@~1.0.4:
|
||||||
version "1.0.4"
|
version "1.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
|
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
|
||||||
@ -2926,6 +2930,16 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6,
|
|||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
|
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
|
||||||
|
|
||||||
|
graphql-tools@/home/nick1.1.0:
|
||||||
|
version "1.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/graphql-tools/-/graphql-tools-1.1.0.tgz#8d86ea6997b0dea3089b62dc655e47146a663ebb"
|
||||||
|
dependencies:
|
||||||
|
deprecated-decorator "^0.1.6"
|
||||||
|
lodash "^4.3.0"
|
||||||
|
uuid "^3.0.1"
|
||||||
|
optionalDependencies:
|
||||||
|
"@types/graphql" "^0.9.0"
|
||||||
|
|
||||||
graphql@~0.10.5:
|
graphql@~0.10.5:
|
||||||
version "0.10.5"
|
version "0.10.5"
|
||||||
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.10.5.tgz#c9be17ca2bdfdbd134077ffd9bbaa48b8becd298"
|
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.10.5.tgz#c9be17ca2bdfdbd134077ffd9bbaa48b8becd298"
|
||||||
|
Loading…
Reference in New Issue
Block a user