From a3eb518dcccaebd0f48c708c189ad2fcb07f0f73 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sun, 21 Aug 2022 13:50:18 +0200 Subject: fix(comments): load all comments on a post Previously, only the first 10 comments was loaded. So I update the fetching method to retrieve all the comments on a post. Also, I choose to order comments on client side because of a bug with WPGraphQL. Finally, I renamed the Comment type to SingleComment to avoid conflict with existing types. --- src/services/graphql/comments.query.ts | 37 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'src/services/graphql/comments.query.ts') diff --git a/src/services/graphql/comments.query.ts b/src/services/graphql/comments.query.ts index ef93e89..5110db3 100644 --- a/src/services/graphql/comments.query.ts +++ b/src/services/graphql/comments.query.ts @@ -1,21 +1,32 @@ /** * Query the comments data by post id. */ -export const commentsQuery = `query CommentsByPostId($contentId: ID!) { - comments(where: {contentId: $contentId, order: ASC, orderby: COMMENT_DATE}) { - nodes { - approved - author { - node { - gravatarUrl - name - url +export const commentsQuery = `query CommentsByPostId($contentId: ID!, $first: Int = 10, $after: String = "") { + comments( + where: {contentId: $contentId} + first: $first + after: $after + ) { + edges { + cursor + node { + approved + author { + node { + gravatarUrl + name + url + } } + content + databaseId + date + parentDatabaseId } - content - databaseId - date - parentDatabaseId + } + pageInfo { + hasNextPage + endCursor } } }`; -- cgit v1.2.3