diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-08-21 13:50:18 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-08-21 13:50:18 +0200 |
| commit | a3eb518dcccaebd0f48c708c189ad2fcb07f0f73 (patch) | |
| tree | 21d8350b85f47c41c382ef64ce0b91003d363a84 /src/services/graphql/comments.query.ts | |
| parent | a0d00743cbbdb77b27c1a3d5711407ffed5befac (diff) | |
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.
Diffstat (limited to 'src/services/graphql/comments.query.ts')
| -rw-r--r-- | src/services/graphql/comments.query.ts | 37 |
1 files changed, 24 insertions, 13 deletions
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 } } }`; |
