Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 062bfe6

Browse files
committed
Add Comments Query
1 parent 7019827 commit 062bfe6

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed
Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
1-
/*
2-
query MyQuery {
3-
comments(where: {contentId: "1148"}) {
4-
pageInfo {
5-
endCursor
6-
hasNextPage
7-
hasPreviousPage
8-
startCursor
9-
}
10-
edges {
11-
node {
12-
databaseId
13-
content(format: RENDERED)
14-
parentDatabaseId
15-
approved
16-
id
1+
import {gql} from '@apollo/client'
2+
import archivePageInfo from '../_partials/archivePageInfo'
3+
4+
// Fragment: retrieve comment fields.
5+
const commentFragment = gql`
6+
fragment CommentFields on Comment {
7+
databaseId
8+
content(format: RENDERED)
9+
parentDatabaseId
10+
approved
11+
id
12+
date
13+
parentId
14+
commentId
15+
type
16+
}
17+
`
18+
19+
// Query: retrieve comments by post databaseId.
20+
const queryCommentsByPostId = gql`
21+
query GET_COMMENTS_BY_POST_ID(
22+
$id: ID!
23+
$first: Int
24+
$last: Int
25+
$after: String
26+
$before: String
27+
$order: OrderEnum = ASC
28+
$orderby: CommentsConnectionOrderbyEnum = COMMENT_DATE
29+
) {
30+
comments(
31+
first: $first
32+
last: $last
33+
after: $after
34+
before: $before
35+
where: {contentId: $id, order: $order, orderby: $orderby}
36+
) {
37+
${archivePageInfo}
38+
edges {
39+
node {
40+
...CommentFields
41+
}
1742
}
1843
}
1944
}
20-
}
21-
*/
45+
${commentFragment}
46+
`
47+
48+
export default queryCommentsByPostId

0 commit comments

Comments
 (0)