Assign post to current user on creation

This commit is contained in:
Grzegorz Leoniec 2019-02-04 17:19:26 +01:00
parent 3583259aa6
commit ca076bbcb9
No known key found for this signature in database
GPG Key ID: 3AA43686D4EB1377

View File

@ -11,6 +11,24 @@ export default {
UpdateUser: async (resolve, root, args, context, info) => {
const result = await resolve(root, args, context, info)
await createOrUpdateLocations(args.id, args.locationName, context.driver)
return result
},
CreatePost: async (resolve, root, args, context, info) => {
const result = await resolve(root, args, context, info)
try {
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()
// eslint-disable-next-line no-empty
} catch (err) {}
return result
}
},