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

Commit 04851f6

Browse files
committed
Refactor to support adding to post query
1 parent 062bfe6 commit 04851f6

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Query partial: retrieve comment fields.
2+
const commentsFields = `
3+
edges {
4+
node {
5+
databaseId
6+
content(format: RENDERED)
7+
parentDatabaseId
8+
approved
9+
id
10+
date
11+
parentId
12+
commentId
13+
type
14+
}
15+
}
16+
`
17+
export default commentsFields
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import commentsFields from './commentsFields'
2+
3+
// Query partial: retrieve comment post fields.
4+
const commentsPostFields = `
5+
comments(first: 10) {
6+
${commentsFields}
7+
}
8+
`
9+
export default commentsPostFields
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
import {gql} from '@apollo/client'
22
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-
`
3+
import commentsFields from '../_partials/commentsFields'
184

195
// Query: retrieve comments by post databaseId.
206
const queryCommentsByPostId = gql`
@@ -35,14 +21,9 @@ const queryCommentsByPostId = gql`
3521
where: {contentId: $id, order: $order, orderby: $orderby}
3622
) {
3723
${archivePageInfo}
38-
edges {
39-
node {
40-
...CommentFields
41-
}
42-
}
24+
${commentsFields}
4325
}
4426
}
45-
${commentFragment}
4627
`
4728

4829
export default queryCommentsByPostId

0 commit comments

Comments
 (0)