graphql-recipes
graphql-recipes copied to clipboard
No way to display likes (Instagram Clone)
If you build it that way, we don't know if the user has already liked a post?!
@dabit3 i am right here?
Have you found a way to do so?
@patrianova I guess there is no out of the box way for this.
likes: [PostLike] @connection(keyName: "postLikesByPostId", fields: ["id"])
this is a bad idea. if there are more likes than 1MB Data, than you can't count here the likes, and you don't know if your user has liked this post.
So you could use a table for likesCount. Every time a user likes a post, you can count up in this table for this post. And for the "Show if user liked it already" problem, you could save a document in a table with: user_id+post_id as id.
every post has to check than if there is a entry with this id.
else you could use elasticSearch for this. But this is a more expansive and self scaling way.
Any idea else?
@davidbiller reading a bit more, I believe you could use resolvers to do this. Pipeline resolvers seems to be an option where upon a request to posts you could then rapidly search if that particular post is liked by the user requesting and create a field on the document on the fly indicating it.
You'd keep the PostLike relationship and that's where you execute your mutation (create a record) and on the queries to fetch the result you implement the custom resolver.
This said, I haven't done anything related to this yet and it would be great to have @dabit3 giving us some direction if possible.
@davidbiller reading a bit more, I believe you could use resolvers to do this. Pipeline resolvers seems to be an option where upon a request to posts you could then rapidly search if that particular post is liked by the user requesting and create a field on the document on the fly indicating it.
You'd keep the PostLike relationship and that's where you execute your mutation (create a record) and on the queries to fetch the result you implement the custom resolver.
This said, I haven't done anything related to this yet and it would be great to have @dabit3 giving us some direction if possible.
But how would you search? as a scan? this takes to long in dynamoDB if there are 100k entries. When the user scrolls through the images.
you wouldn't do this per post but rather on the query that returns them.
if you get the first 100 posts on a query, on the resolver of this query is where you'd iterate through the 100 posts and search if it has been liked or not.
see below https://docs.aws.amazon.com/appsync/latest/devguide/pipeline-resolvers.html
you wouldn't do this per post but rather on the query that returns them.
if you get the first 100 posts on a query, on the resolver of this query is where you'd iterate through the 100 posts and search if it has been liked or not.
see below https://docs.aws.amazon.com/appsync/latest/devguide/pipeline-resolvers.html
But the pipeline resolver is using the scan operator of dynamodb?
@davidbiller I'm not quite there yet :) but I'm assuming you could run two graphql queries on the resolver and merge them programmatically. I'll do some reading and let you know what I find out. If you do find an answer, please share here.
@davidbiller I'm not quite there yet :) but I'm assuming you could run two graphql queries on the resolver and merge them programmatically. I'll do some reading and let you know what I find out. If you do find an answer, please share here.
Ja, this is the problem here, you only can search in dynamoDB with a index key or with scans. And scans are expansive and it takes to long.
@dabit3 any soultion ?