refactor follow, unfollow, shout, unshout to custom mutations, but don't add date-time to relation yet
Created by: Tirokk
Authored by Tirokk Merged
Together with @mattwr18 .
Pullrequest
Issues
- relates #219 (closed)
-
Customises mutations follow, unfollow, shout, unshout. -
Add date-time to relation.
How2Test
-
$ docker-compose exec backend yarn test:jest backend/src/resolvers/follow.spec.js backend/src/resolvers/shout.spec.js
Merge request reports
Activity
1 export default { 2 Mutation: { 3 shout: async (_object, params, context, _resolveInfo) => { 4 const { id, type } = params 5 6 const session = context.driver.session() 7 let transactionRes = await session.run( Created by: Tirokk
Authored by mattwr18
Outdated (history rewrite) - original diff
@@ -0,0 +1,51 @@ +export default { + Mutation: { + shout: async (_object, params, context, _resolveInfo) => { + const { id, type } = params + + const session = context.driver.session() + let sessionRes = await session.run(
I don't love the name
sessionRes
I feel like we should be naming it what is the actual result, which would tempt me to name itisShouted
, but then I see on line 19, we seem to get a list of records back that we then need to grabisShouted
from.I was having a read here https://neo4j.com/docs/driver-manual/current/sessions-transactions/, and it seems the result is from the transaction, not the session. Maybe it would be better
transactionRes
, but maybe I'm just being pedantic, and can be ignored.Created by: Tirokk
Authored by Tirokk
I am really happy to rename
sessionRes
to ´transactionRes´ @mattwr18 . That is a very good clarification we can use in the future for all customised mutations.I am happy especially if there is nothing else to mention from your side.
1 export default { 2 Mutation: { 3 shout: async (_object, params, context, _resolveInfo) => { 4 const { id, type } = params 5 6 const session = context.driver.session() 7 let transactionRes = await session.run( 8 `MATCH (node {id: $id})<-[:WROTE]-(userWritten:User), (user:User {id: $userId}) 9 WHERE $type IN labels(node) AND NOT userWritten.id = $userId Created by: Tirokk
Authored by roschaefer
Outdated (history rewrite) - original diff
@@ -0,0 +1,51 @@ +export default { + Mutation: { + shout: async (_object, params, context, _resolveInfo) => { + const { id, type } = params + + const session = context.driver.session() + let transactionRes = await session.run( + `MATCH (node {id: $id})<-[:WROTE]-(userWritten:User), (user:User {id: $userId}) + WHERE $type IN labels(node) AND NOT userWritten.id = $userId
A future improvement could be that you can omit the
ShoutTypeEnum
. I mean: The server knows what you can shout and what not, right? So, instead of having the type of the shouted object sent to the server, you just send the id and the server checks if the labels of the matched, shouted object intersects with a well-known set of shoutable objects (by a set of labels['Project', 'Post', ...]
).For now it is fine though!
Created by: Tirokk
Authored by Tirokk
That is a concurrence between two things:
- KISS: Keep it stupid simple …
- But redundancy may be good for think and error checking: What type has the Webapp programmer thought to be shouted or followed and does this fit to what can be … on the server side?
I think you just like to KISS …
!?