GraphQL

Interfaces & Types

These are the GraphQL interfaces and types Comments adds. The Queries and Mutations pages show them in use.

Comments

The CommentInterface Interface

The interface implemented by every comment. Comments use a single type, Comment, which also holds any custom fields from the comment form’s layout. Request those inside a ... on Comment fragment, as shown in Querying Custom Fields.

As well as the fields below, the interface includes Craft’s standard element and structure fields, such as id, uid, status, siteId, dateCreated, dateUpdated, level, prev and next.

{
  comments(ownerId: 2460, limit: 1) {
    id
    name
    comment
    gifUrl
    votes
    flags
    user {
      fullName
    }
  }
}

ownerId

The ID of the element the comment was made on.

commentDate

The date the comment was posted. Use Craft’s @formatDateTime directive to format it.

comment

The comment text.

gifUrl

The URL of the GIF attached to the comment, or null when there isn’t one.

name

The name of the comment’s author.

email

The email address a guest posted the comment with. It’s null for comments posted by a logged-in user, whose address belongs to their user account. A public schema always returns null, so query email with a private schema’s token from your own server.

url

The URL of the page the comment was posted from.

children

The replies to the comment. It accepts the same arguments as the comments query.

parent

The comment this one replies to, or null for a top-level comment.

votes

The comment’s score, its upvotes minus its downvotes.

upvotes

The number of upvotes the comment has.

downvotes

The number of downvotes the comment has.

flags

The number of times the comment has been flagged.

userId

The ID of the user who posted the comment, or null for a guest. It’s only available when the schema can view users.

user

The user who posted the comment. It’s only available when the schema can view users.

Votes and Flags

The VoteInterface Interface

The interface implemented by the Vote type, which the voteComment mutation returns.

mutation UpvoteComment($id: ID!) {
  voteComment(id: $id, upvote: true) {
    id
    upvote
    downvote
    comment {
      votes
    }
  }
}

id

The ID of the vote.

sessionId

The ID of the session the vote was made from.

lastIp

The IP address the vote was made from. Comments only stores it when Craft’s storeUserIps setting is enabled.

upvote

Whether the vote is an upvote.

downvote

Whether the vote is a downvote.

commentId

The ID of the comment the vote was made on.

comment

The comment the vote was made on.

userId

The ID of the user who voted, or null for a guest. It’s only available when the schema can view users.

user

The user who voted. It’s only available when the schema can view users.

The FlagInterface Interface

The interface implemented by the Flag type, which the flagComment mutation returns.

mutation FlagComment($id: ID!) {
  flagComment(id: $id) {
    id
    commentId
    comment {
      flags
    }
  }
}

id

The ID of the flag.

sessionId

The ID of the session the flag was made from.

lastIp

The IP address the flag was made from. Comments only stores it when Craft’s storeUserIps setting is enabled.

commentId

The ID of the comment that was flagged.

comment

The comment that was flagged.