mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
I find it dirty to access the database in a middleware, ie. I would like to put all access on the database as close to the resolver as possible. However, in this case that would mean to put the authorization check in the resolver, where nobody expects it to be. CC @appinteractive
22 lines
579 B
JavaScript
22 lines
579 B
JavaScript
import { neo4jgraphql } from 'neo4j-graphql-js'
|
|
|
|
export default {
|
|
Mutation: {
|
|
CreatePost: async (object, params, context, resolveInfo) => {
|
|
const result = await neo4jgraphql(object, params, context, resolveInfo, false)
|
|
|
|
const session = context.driver.session()
|
|
await session.run(
|
|
'MATCH (author:User {id: $userId}), (post:Post {id: $postId}) ' +
|
|
'MERGE (post)<-[:WROTE]-(author) ' +
|
|
'RETURN author', {
|
|
userId: context.user.id,
|
|
postId: result.id
|
|
})
|
|
session.close()
|
|
|
|
return result
|
|
}
|
|
}
|
|
}
|