refactor: knex remaining models
This commit is contained in:
51
server/graph/resolvers/page.js
Normal file
51
server/graph/resolvers/page.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const graphHelper = require('../../helpers/graph')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
async pages() { return {} }
|
||||
},
|
||||
Mutation: {
|
||||
async pages() { return {} }
|
||||
},
|
||||
PageQuery: {
|
||||
async list(obj, args, context, info) {
|
||||
return WIKI.db.groups.query().select(
|
||||
'groups.*',
|
||||
WIKI.db.groups.relatedQuery('users').count().as('userCount')
|
||||
)
|
||||
},
|
||||
async single(obj, args, context, info) {
|
||||
return WIKI.db.groups.query().findById(args.id)
|
||||
}
|
||||
},
|
||||
PageMutation: {
|
||||
async create(obj, args) {
|
||||
const group = await WIKI.db.pages.query().insertAndFetch({
|
||||
name: args.name
|
||||
})
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group created successfully.'),
|
||||
group
|
||||
}
|
||||
},
|
||||
async delete(obj, args) {
|
||||
await WIKI.db.groups.query().deleteById(args.id)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group has been deleted.')
|
||||
}
|
||||
},
|
||||
async update(obj, args) {
|
||||
await WIKI.db.groups.query().patch({ name: args.name }).where('id', args.id)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group has been updated.')
|
||||
}
|
||||
}
|
||||
},
|
||||
Page: {
|
||||
// comments(pg) {
|
||||
// return pg.$relatedQuery('comments')
|
||||
// }
|
||||
}
|
||||
}
|
78
server/graph/schemas/page.graphql
Normal file
78
server/graph/schemas/page.graphql
Normal file
@@ -0,0 +1,78 @@
|
||||
# ===============================================
|
||||
# PAGES
|
||||
# ===============================================
|
||||
|
||||
extend type Query {
|
||||
pages: PageQuery
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
pages: PageMutation
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# QUERIES
|
||||
# -----------------------------------------------
|
||||
|
||||
type PageQuery {
|
||||
list(
|
||||
filter: String
|
||||
orderBy: String
|
||||
): [PageMinimal]
|
||||
|
||||
single(
|
||||
id: Int!
|
||||
): Page
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# MUTATIONS
|
||||
# -----------------------------------------------
|
||||
|
||||
type PageMutation {
|
||||
create(
|
||||
description: String
|
||||
isPublished: Boolean
|
||||
locale: String
|
||||
path: String!
|
||||
publishEndDate: Date
|
||||
publishStartDate: Date
|
||||
tags: [String]
|
||||
title: String!
|
||||
): PageResponse
|
||||
|
||||
update(
|
||||
id: Int!
|
||||
name: String!
|
||||
): DefaultResponse
|
||||
|
||||
delete(
|
||||
id: Int!
|
||||
): DefaultResponse
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# TYPES
|
||||
# -----------------------------------------------
|
||||
|
||||
type PageResponse {
|
||||
responseResult: ResponseStatus!
|
||||
page: Page
|
||||
}
|
||||
|
||||
type PageMinimal {
|
||||
id: Int!
|
||||
name: String!
|
||||
userCount: Int
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
}
|
||||
|
||||
type Page {
|
||||
id: Int!
|
||||
name: String!
|
||||
rights: [Right]
|
||||
users: [User]
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
}
|
Reference in New Issue
Block a user