Zapytania o dane WordPressKomentarze
Komentarze
Są to przykłady queries do pobierania i dodawania komentarzy.
Pobieranie komentarzy
Komentarze z posta:
query {
post(by: { id: 1 }) {
comments {
id
content
author {
name
}
parent {
id
}
}
}
}Komentarze i ich odpowiedzi, na wielu poziomach:
query {
post(by: { id: 1499 }) {
comments(pagination: { limit: 5 }) {
...CommentFields
responses {
...CommentFields
responses {
...CommentFields
}
}
}
}
}
fragment CommentFields on Comment {
id
date
content
}Filtrowanie komentarzy:
{
posts {
title
comments(
filter: { search: "insight" }
) {
id
content
}
}
}Liczenie wyników komentarzy:
{
posts {
id
commentCount
}
}Stronicowanie komentarzy:
{
posts {
id
comments(
pagination: {
limit: 3,
offset: 3
}
) {
id
date
content
}
}
}Wszystkie komentarze na stronie od konkretnego użytkownika:
{
commentCount(filter: { authorIDs: [1], parentID: null })
comments(filter: { authorIDs: [1], parentID: null }, pagination: { limit: -1 }) {
id
date
content
}
}Konkretny komentarz:
{
comment(by: { id: 272 }) {
id
date
content
author {
id
name
}
}
}Pobieranie wartości meta:
{
posts {
id
comments{
id
metaValue(
key:"someKey"
)
}
}
}Dodawanie komentarza
Zalogowani lub niezalogowani użytkownicy mogą dodawać komentarze:
mutation {
addCommentToCustomPost(
input: { customPostID: 1459, commentAs: { html: "Lovely tango!" } }
) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
commentID
comment {
date
content
author {
id
name
}
}
}
}Możemy również użyć zagnieżdżonych mutations:
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
}
}
}
}
}Odpowiadanie na komentarz
Podobnie jak dodawanie komentarza, ale z podaniem argumentu 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
}
}
}
}Lub użyć bardziej szczegółowego pola 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
}
}
}
}Lub przejść do komentarza nadrzędnego za pomocą zagnieżdżonych mutations:
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
}
}
}
}
}Prev
Next