diff --git a/src/middleware/userMiddleware.js b/src/middleware/userMiddleware.js index d4648413a..db5595e87 100644 --- a/src/middleware/userMiddleware.js +++ b/src/middleware/userMiddleware.js @@ -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 } },