WordPress 데이터 쿼리댓글
댓글
다음은 댓글을 가져오고 추가하기 위한 쿼리 예시입니다.
댓글 가져오기
게시물의 댓글:
query {
post(by: { id: 1 }) {
comments {
id
content
author {
name
}
parent {
id
}
}
}
}댓글과 여러 단계의 답글:
query {
post(by: { id: 1499 }) {
comments(pagination: { limit: 5 }) {
...CommentFields
responses {
...CommentFields
responses {
...CommentFields
}
}
}
}
}
fragment CommentFields on Comment {
id
date
content
}댓글 필터링:
{
posts {
title
comments(
filter: { search: "insight" }
) {
id
content
}
}
}댓글 수 집계:
{
posts {
id
commentCount
}
}댓글 페이지네이션:
{
posts {
id
comments(
pagination: {
limit: 3,
offset: 3
}
) {
id
date
content
}
}
}특정 사용자의 사이트 전체 댓글:
{
commentCount(filter: { authorIDs: [1], parentID: null })
comments(filter: { authorIDs: [1], parentID: null }, pagination: { limit: -1 }) {
id
date
content
}
}특정 댓글:
{
comment(by: { id: 272 }) {
id
date
content
author {
id
name
}
}
}메타 값 가져오기:
{
posts {
id
comments{
id
metaValue(
key:"someKey"
)
}
}
}댓글 추가
로그인한 사용자와 로그인하지 않은 사용자 모두 댓글을 추가할 수 있습니다:
mutation {
addCommentToCustomPost(
input: { customPostID: 1459, commentAs: { html: "Lovely tango!" } }
) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
commentID
comment {
date
content
author {
id
name
}
}
}
}중첩 뮤테이션을 사용할 수도 있습니다:
mutation {
post(by: { id: 1459 }) {
id
title
addComment(input: { commentAs: { html: "Lovely tango!" } }) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
commentID
comment {
date
content
author {
id
name
}
}
}
}
}댓글에 답글 달기
댓글 추가와 유사하지만 parentCommentID 인수도 함께 지정합니다:
mutation {
addCommentToCustomPost(
input: {
customPostID: 1459
parentCommentID: 272
commentAs: { html: "Hi to you too" }
}
) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
commentID
comment {
date
content
author {
id
name
}
}
}
}더 구체적인 replyComment 필드를 사용할 수도 있습니다:
mutation {
replyComment(input: { parentCommentID: 272, commentAs: { html: "Hi to you too" } }) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
commentID
comment {
date
content
author {
id
name
}
}
}
}또는 중첩 뮤테이션을 사용하여 부모 댓글로 이동할 수도 있습니다:
mutation {
post(by: { id: 1459 }) {
comments(filter: { ids: 272 }) {
id
content
reply(input: { commentAs: { html: "Everything good?" } }) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
commentID
comment {
date
content
}
}
}
}
}