WordPress-gegevens opvragen
WordPress-gegevens opvragenOpmerkingen

Opmerkingen

Dit zijn voorbeelden van queries om opmerkingen op te halen en toe te voegen.

Opmerkingen ophalen

Opmerkingen van een bericht:

query {
  post(by: { id: 1 }) {
    comments {
      id
      content
      author {
        name
      }
      parent {
        id
      }
    }
  }
}

Opmerkingen en hun reacties, voor meerdere niveaus:

query {
  post(by: { id: 1499 }) {
    comments(pagination: { limit: 5 }) {
      ...CommentFields
      responses {
        ...CommentFields
        responses {
          ...CommentFields
        }
      }
    }
  }
}
 
fragment CommentFields on Comment {
  id
  date
  content
}

Opmerkingen filteren:

{
  posts {
    title
    comments(
      filter: { search: "insight" }
    ) {
      id
      content
    }
  }
}

Resultaten van opmerkingen tellen:

{
  posts {
    id
    commentCount
  }
}

Opmerkingen pagineren:

{
  posts {
    id
    comments(
      pagination: {
        limit: 3,
        offset: 3
      }
    ) {
      id
      date
      content
    }
  }
}

Alle opmerkingen op de site van een specifieke gebruiker:

{
  commentCount(filter: { authorIDs: [1], parentID: null })
  comments(filter: { authorIDs: [1], parentID: null }, pagination: { limit: -1 }) {
    id
    date
    content
  }
}

Een specifieke opmerking:

{
  comment(by: { id: 272 }) {
    id
    date
    content
    author {
      id
      name
    }
  }
}

Meta-waarden ophalen:

{
  posts {
    id
    comments{
      id
      metaValue(
        key:"someKey"
      )
    }
  }
}

Een opmerking toevoegen

Ingelogde of niet-ingelogde gebruikers kunnen opmerkingen toevoegen:

mutation {
  addCommentToCustomPost(
    input: { customPostID: 1459, commentAs: { html: "Lovely tango!" } }
  ) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    commentID
    comment {
      date
      content
      author {
        id
        name
      }
    }
  }
}

We kunnen ook geneste mutations gebruiken:

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
        }
      }
    }
  }
}

Reageren op een opmerking

Vergelijkbaar met het toevoegen van een opmerking, maar met ook het argument 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
      }
    }
  }
}

Of gebruik het meer specifieke veld 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
      }
    }
  }
}

Of navigeer naar de bovenliggende opmerking via geneste 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
        }
      }
    }
  }
}