79361070

Date: 2025-01-16 10:03:44
Score: 2
Natty:
Report link
const getCommentsForPost = async (postId) => {
  // This is assuming that the postId is not null
  let nextToken = null;
  let allComments = [];

  do {
    const result = await API.graphql(
    graphqlOperation(listComments, { filter: { 
       commentPostId: { eq: postId } 
    // No need for limits
      }, 
     nextToken 
     })
   );

const comments = result.data.listComments.items;
allComments.push(...comments);
nextToken = result.data.listComments.nextToken;
} while (nextToken);

return allComments;
};

This should get the comments for a particular post without any error. Also could you clarify if you are getting the comments only when you view a single post details, or you are trying to get multiple posts comments.

Either way, this function can still get the comments that you need

Reasons:
  • RegEx Blacklisted phrase (2.5): could you clarify
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Demehin Ibukunoluwa George