Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
840eb7e7
Commit
840eb7e7
authored
Aug 13, 2017
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: GraphQL mutations for folder, group, tag, user
parent
1405b822
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
163 additions
and
5 deletions
+163
-5
_relations.js
server/models/_relations.js
+4
-2
graphql.js
server/modules/graphql.js
+4
-0
git-sync.js
server/queues/git-sync.js
+1
-1
upl-clear-temp.js
server/queues/upl-clear-temp.js
+1
-1
resolvers-folder.js
server/schemas/resolvers-folder.js
+29
-0
resolvers-group.js
server/schemas/resolvers-group.js
+36
-0
resolvers-tag.js
server/schemas/resolvers-tag.js
+57
-0
resolvers-user.js
server/schemas/resolvers-user.js
+8
-0
types.graphql
server/schemas/types.graphql
+23
-1
No files found.
server/models/_relations.js
View file @
840eb7e7
...
...
@@ -6,9 +6,11 @@
module
.
exports
=
db
=>
{
db
.
User
.
belongsToMany
(
db
.
Group
,
{
through
:
'userGroups'
})
db
.
Group
.
belongsToMany
(
db
.
User
,
{
through
:
'userGroups'
})
db
.
Group
.
hasMany
(
db
.
Right
,
{
as
:
'groupRights'
})
db
.
Document
.
hasMany
(
db
.
Tag
,
{
as
:
'documentTags'
})
db
.
Group
.
hasMany
(
db
.
Right
)
db
.
Document
.
belongsToMany
(
db
.
Tag
,
{
through
:
'documentTags'
})
db
.
Tag
.
belongsToMany
(
db
.
Document
,
{
through
:
'documentTags'
})
db
.
File
.
belongsTo
(
db
.
Folder
)
db
.
Folder
.
hasMany
(
db
.
File
)
db
.
Comment
.
belongsTo
(
db
.
Document
)
db
.
Comment
.
belongsTo
(
db
.
User
,
{
as
:
'author'
})
}
server/modules/graphql.js
View file @
840eb7e7
...
...
@@ -10,11 +10,15 @@ const _ = require('lodash')
const
typeDefs
=
fs
.
readFileSync
(
path
.
join
(
wiki
.
SERVERPATH
,
'schemas/types.graphql'
),
'utf8'
)
const
DateScalar
=
require
(
'../schemas/scalar-date'
)
const
FolderResolvers
=
require
(
'../schemas/resolvers-folder'
)
const
GroupResolvers
=
require
(
'../schemas/resolvers-group'
)
const
TagResolvers
=
require
(
'../schemas/resolvers-tag'
)
const
UserResolvers
=
require
(
'../schemas/resolvers-user'
)
const
resolvers
=
_
.
merge
(
FolderResolvers
,
GroupResolvers
,
TagResolvers
,
UserResolvers
,
DateScalar
)
...
...
server/queues/git-sync.js
View file @
840eb7e7
...
...
@@ -9,7 +9,7 @@ const moment = require('moment')
const
path
=
require
(
'path'
)
const
entryHelper
=
require
(
'../helpers/entry'
)
module
.
exports
=
(
job
,
done
)
=>
{
module
.
exports
=
(
job
)
=>
{
return
wiki
.
git
.
resync
().
then
(()
=>
{
// -> Stream all documents
...
...
server/queues/upl-clear-temp.js
View file @
840eb7e7
...
...
@@ -7,7 +7,7 @@ const fs = Promise.promisifyAll(require('fs-extra'))
const
moment
=
require
(
'moment'
)
const
path
=
require
(
'path'
)
module
.
exports
=
(
job
,
done
)
=>
{
module
.
exports
=
(
job
)
=>
{
return
fs
.
readdirAsync
(
wiki
.
UPLTEMPPATH
).
then
((
ls
)
=>
{
let
fifteenAgo
=
moment
().
subtract
(
15
,
'minutes'
)
...
...
server/schemas/resolvers-folder.js
0 → 100644
View file @
840eb7e7
'use strict'
/* global wiki */
module
.
exports
=
{
Query
:
{
folders
(
obj
,
args
,
context
,
info
)
{
return
wiki
.
db
.
Folder
.
findAll
({
where
:
args
})
}
},
Mutation
:
{
createFolder
(
obj
,
args
)
{
return
wiki
.
db
.
Folder
.
create
(
args
)
},
deleteGroup
(
obj
,
args
)
{
return
wiki
.
db
.
Folder
.
destroy
({
where
:
{
id
:
args
.
id
},
limit
:
1
})
}
},
Folder
:
{
files
(
grp
)
{
return
grp
.
getFiles
()
}
}
}
server/schemas/resolvers-group.js
View file @
840eb7e7
...
...
@@ -2,6 +2,8 @@
/* global wiki */
const
gql
=
require
(
'graphql'
)
module
.
exports
=
{
Query
:
{
groups
(
obj
,
args
,
context
,
info
)
{
...
...
@@ -9,8 +11,42 @@ module.exports = {
}
},
Mutation
:
{
assignUserToGroup
(
obj
,
args
)
{
return
wiki
.
db
.
Group
.
findById
(
args
.
groupId
).
then
(
grp
=>
{
if
(
!
grp
)
{
throw
new
gql
.
GraphQLError
(
'Invalid Group ID'
)
}
return
wiki
.
db
.
User
.
findById
(
args
.
userId
).
then
(
usr
=>
{
if
(
!
usr
)
{
throw
new
gql
.
GraphQLError
(
'Invalid User ID'
)
}
return
grp
.
addUser
(
usr
)
})
})
},
createGroup
(
obj
,
args
)
{
return
wiki
.
db
.
Group
.
create
(
args
)
},
deleteGroup
(
obj
,
args
)
{
return
wiki
.
db
.
Group
.
destroy
({
where
:
{
id
:
args
.
id
},
limit
:
1
})
},
removeUserFromGroup
(
obj
,
args
)
{
return
wiki
.
db
.
Group
.
findById
(
args
.
groupId
).
then
(
grp
=>
{
if
(
!
grp
)
{
throw
new
gql
.
GraphQLError
(
'Invalid Group ID'
)
}
return
wiki
.
db
.
User
.
findById
(
args
.
userId
).
then
(
usr
=>
{
if
(
!
usr
)
{
throw
new
gql
.
GraphQLError
(
'Invalid User ID'
)
}
return
grp
.
removeUser
(
usr
)
})
})
}
},
Group
:
{
...
...
server/schemas/resolvers-tag.js
0 → 100644
View file @
840eb7e7
'use strict'
/* global wiki */
const
gql
=
require
(
'graphql'
)
module
.
exports
=
{
Query
:
{
tags
(
obj
,
args
,
context
,
info
)
{
return
wiki
.
db
.
Tag
.
findAll
({
where
:
args
})
}
},
Mutation
:
{
assignTagToDocument
(
obj
,
args
)
{
return
wiki
.
db
.
Tag
.
findById
(
args
.
tagId
).
then
(
tag
=>
{
if
(
!
tag
)
{
throw
new
gql
.
GraphQLError
(
'Invalid Tag ID'
)
}
return
wiki
.
db
.
Document
.
findById
(
args
.
documentId
).
then
(
doc
=>
{
if
(
!
doc
)
{
throw
new
gql
.
GraphQLError
(
'Invalid Document ID'
)
}
return
tag
.
addDocument
(
doc
)
})
})
},
createTag
(
obj
,
args
)
{
return
wiki
.
db
.
Tag
.
create
(
args
)
},
deleteTag
(
obj
,
args
)
{
return
wiki
.
db
.
Tag
.
destroy
({
where
:
{
id
:
args
.
id
},
limit
:
1
})
},
removeTagFromDocument
(
obj
,
args
)
{
return
wiki
.
db
.
Tag
.
findById
(
args
.
tagId
).
then
(
tag
=>
{
if
(
!
tag
)
{
throw
new
gql
.
GraphQLError
(
'Invalid Tag ID'
)
}
return
wiki
.
db
.
Document
.
findById
(
args
.
documentId
).
then
(
doc
=>
{
if
(
!
doc
)
{
throw
new
gql
.
GraphQLError
(
'Invalid Document ID'
)
}
return
tag
.
removeDocument
(
doc
)
})
})
}
},
Tag
:
{
documents
(
tag
)
{
return
tag
.
getDocuments
()
}
}
}
server/schemas/resolvers-user.js
View file @
840eb7e7
...
...
@@ -11,6 +11,14 @@ module.exports = {
Mutation
:
{
createUser
(
obj
,
args
)
{
return
wiki
.
db
.
User
.
create
(
args
)
},
deleteUser
(
obj
,
args
)
{
return
wiki
.
db
.
User
.
destroy
({
where
:
{
id
:
args
.
id
},
limit
:
1
})
}
},
User
:
{
...
...
server/schemas/types.graphql
View file @
840eb7e7
...
...
@@ -73,6 +73,7 @@ type Folder implements Base {
createdAt
:
Date
updatedAt
:
Date
name
:
String
!
files
:
[
File
]
}
type
Group
implements
Base
{
...
...
@@ -107,7 +108,8 @@ type Tag implements Base {
id
:
Int
!
createdAt
:
Date
updatedAt
:
Date
key
:
String
!
key
:
String
!,
documents
:
[
Document
]
}
# A User
...
...
@@ -138,13 +140,23 @@ type Query {
# Mutations (Create, Update, Delete)
type
Mutation
{
assignTagToDocument
(
tagId
:
Int
!
documentId
:
Int
!
):
Boolean
assignUserToGroup
(
userId
:
Int
!
groupId
:
Int
!
):
Boolean
createFolder
(
name
:
String
!
):
Folder
createGroup
(
name
:
String
!
):
Group
createTag
(
name
:
String
!
):
Tag
createUser
(
email
:
String
!
name
:
String
...
...
@@ -152,12 +164,22 @@ type Mutation {
providerId
:
String
role
:
UserRole
!
):
User
deleteFolder
(
id
:
Int
!
):
Boolean
deleteGroup
(
id
:
Int
!
):
Boolean
deleteTag
(
id
:
Int
!
):
Boolean
deleteUser
(
id
:
Int
!
):
Boolean
removeTagFromDocument
(
tagId
:
Int
!
documentId
:
Int
!
):
Boolean
removeUserFromGroup
(
userId
:
Int
!
groupId
:
Int
!
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment