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