Interrogare i dati di WordPressCommenti
Commenti
Questi sono esempi di query per recuperare e aggiungere commenti.
Recuperare i commenti
Commenti di un articolo:
query {
post(by: { id: 1 }) {
comments {
id
content
author {
name
}
parent {
id
}
}
}
}Commenti e relative risposte, su più livelli:
query {
post(by: { id: 1499 }) {
comments(pagination: { limit: 5 }) {
...CommentFields
responses {
...CommentFields
responses {
...CommentFields
}
}
}
}
}
fragment CommentFields on Comment {
id
date
content
}Filtrare i commenti:
{
posts {
title
comments(
filter: { search: "insight" }
) {
id
content
}
}
}Contare i risultati dei commenti:
{
posts {
id
commentCount
}
}Paginare i commenti:
{
posts {
id
comments(
pagination: {
limit: 3,
offset: 3
}
) {
id
date
content
}
}
}Tutti i commenti del sito di un utente specifico:
{
commentCount(filter: { authorIDs: [1], parentID: null })
comments(filter: { authorIDs: [1], parentID: null }, pagination: { limit: -1 }) {
id
date
content
}
}Un commento specifico:
{
comment(by: { id: 272 }) {
id
date
content
author {
id
name
}
}
}Recuperare i valori meta:
{
posts {
id
comments{
id
metaValue(
key:"someKey"
)
}
}
}Aggiungere un commento
Gli utenti autenticati o non autenticati possono aggiungere commenti:
mutation {
addCommentToCustomPost(
input: { customPostID: 1459, commentAs: { html: "Lovely tango!" } }
) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
commentID
comment {
date
content
author {
id
name
}
}
}
}Possiamo anche utilizzare mutation annidate:
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
}
}
}
}
}Rispondere a un commento
Simile all'aggiunta di un commento, ma fornendo anche l'argomento 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
}
}
}
}Oppure utilizzare il campo più specifico 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
}
}
}
}Oppure navigare verso il commento padre utilizzando mutation annidate:
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