refactor: knex remaining models

This commit is contained in:
NGPixel
2018-05-20 18:50:51 -04:00
parent c9b643fbf0
commit 17b2117b39
22 changed files with 426 additions and 447 deletions

View 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')
// }
}
}

View 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!
}