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
}
}
}The ID of the element the comment was made on.
The date the comment was posted. Use Craft’s @formatDateTime directive to format it.
The comment text.
The URL of the GIF attached to the comment, or null when there isn’t one.
The name of the comment’s author.
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.
The URL of the page the comment was posted from.
The replies to the comment. It accepts the same arguments as the comments query.
The comment this one replies to, or null for a top-level comment.
The comment’s score, its upvotes minus its downvotes.
The number of upvotes the comment has.
The number of downvotes the comment has.
The number of times the comment has been flagged.
The ID of the user who posted the comment, or null for a guest. It’s only available when the schema can view users.
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
}
}
}The ID of the vote.
The ID of the session the vote was made from.
The IP address the vote was made from. Comments only stores it when Craft’s storeUserIps setting is enabled.
Whether the vote is an upvote.
Whether the vote is a downvote.
The ID of the comment the vote was made on.
The comment the vote was made on.
The ID of the user who voted, or null for a guest. It’s only available when the schema can view users.
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
}
}
}The ID of the flag.
The ID of the session the flag was made from.
The IP address the flag was made from. Comments only stores it when Craft’s storeUserIps setting is enabled.
The ID of the comment that was flagged.
The comment that was flagged.