Consultar datos de WordPressComentarios
Comentarios
Estos son ejemplos de consultas para obtener y añadir comentarios.
Obtener comentarios
Comentarios de una entrada:
query {
post(by: { id: 1 }) {
comments {
id
content
author {
name
}
parent {
id
}
}
}
}Comentarios y sus respuestas, para múltiples niveles:
query {
post(by: { id: 1499 }) {
comments(pagination: { limit: 5 }) {
...CommentFields
responses {
...CommentFields
responses {
...CommentFields
}
}
}
}
}
fragment CommentFields on Comment {
id
date
content
}Filtrar comentarios:
{
posts {
title
comments(
filter: { search: "insight" }
) {
id
content
}
}
}Contar resultados de comentarios:
{
posts {
id
commentCount
}
}Paginar comentarios:
{
posts {
id
comments(
pagination: {
limit: 3,
offset: 3
}
) {
id
date
content
}
}
}Todos los comentarios del sitio de un usuario específico:
{
commentCount(filter: { authorIDs: [1], parentID: null })
comments(filter: { authorIDs: [1], parentID: null }, pagination: { limit: -1 }) {
id
date
content
}
}Un comentario específico:
{
comment(by: { id: 272 }) {
id
date
content
author {
id
name
}
}
}Obtener valores meta:
{
posts {
id
comments{
id
metaValue(
key:"someKey"
)
}
}
}Añadir un comentario
Usuarios autenticados o no autenticados pueden añadir comentarios:
mutation {
addCommentToCustomPost(
input: { customPostID: 1459, commentAs: { html: "Lovely tango!" } }
) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
commentID
comment {
date
content
author {
id
name
}
}
}
}También podemos usar mutaciones anidadas:
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
}
}
}
}
}Responder a un comentario
Similar a añadir un comentario, pero proporcionando también el argumento 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
}
}
}
}O usa el campo más específico 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
}
}
}
}O navega al comentario padre usando mutaciones anidadas:
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