mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
- Refactoring without tests makes it riskier - Move some tests from resolver to middleware unit tests to live closer to where the validation happens, remove duplicate tests - DRY out code
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
export default {
|
|
Query: {
|
|
statistics: async (_parent, _args, { driver }) => {
|
|
const session = driver.session()
|
|
const response = {}
|
|
try {
|
|
const mapping = {
|
|
countUsers: 'User',
|
|
countPosts: 'Post',
|
|
countComments: 'Comment',
|
|
countNotifications: 'NOTIFIED',
|
|
countEmails: 'EmailAddress',
|
|
countFollows: 'FOLLOWS',
|
|
countShouts: 'SHOUTED',
|
|
}
|
|
const cypher = `
|
|
CALL apoc.meta.stats() YIELD labels, relTypesCount
|
|
RETURN labels, relTypesCount
|
|
`
|
|
const result = await session.run(cypher)
|
|
const [statistics] = await result.records.map(record => {
|
|
return {
|
|
...record.get('labels'),
|
|
...record.get('relTypesCount'),
|
|
}
|
|
})
|
|
Object.keys(mapping).forEach(key => {
|
|
const stat = statistics[mapping[key]]
|
|
response[key] = stat ? stat.toNumber() : 0
|
|
})
|
|
|
|
/*
|
|
* Note: invites count is calculated this way because invitation codes are not in use yet
|
|
*/
|
|
response.countInvites = response.countEmails - response.countUsers
|
|
return response
|
|
} finally {
|
|
session.close()
|
|
}
|
|
},
|
|
},
|
|
}
|