Update resolver for paginated notifications

This commit is contained in:
mattwr18 2019-10-29 18:02:49 +01:00
parent 4448c12f2e
commit f34c8f44e0
2 changed files with 6 additions and 5 deletions

View File

@ -18,9 +18,8 @@ export default {
notifications: async (_parent, args, context, _resolveInfo) => {
const { user: currentUser } = context
const session = context.driver.session()
let notifications
let whereClause
let orderByClause
let notifications, whereClause, orderByClause
switch (args.read) {
case true:
whereClause = 'WHERE notification.read = TRUE'
@ -41,13 +40,15 @@ export default {
default:
orderByClause = ''
}
const offset = args.offset ? `SKIP ${args.offset}` : ''
const limit = args.first ? `LIMIT ${args.first}` : ''
try {
const cypher = `
MATCH (resource {deleted: false, disabled: false})-[notification:NOTIFIED]->(user:User {id:$id})
${whereClause}
RETURN resource, notification, user
${orderByClause}
${offset} ${limit}
`
const result = await session.run(cypher, { id: currentUser.id })
notifications = await result.records.map(transformReturnType)

View File

@ -23,7 +23,7 @@ enum NotificationReason {
}
type Query {
notifications(read: Boolean, orderBy: NotificationOrdering): [NOTIFIED]
notifications(read: Boolean, orderBy: NotificationOrdering, first: Int, offset: Int): [NOTIFIED]
}
type Mutation {