Comment
Represents a comment object, including its author and replies.
Type Definition
type Comment {
id: Int
customer: Customer
isAuthor: Boolean
parentCount: Int
comments: [Comment]
comment: String
createdAt: String
updatedAt: String
}Fields
| Field | Type | Nullable | Description | Related Type |
|---|---|---|---|---|
id | Int | Yes | Unique identifier for this comment. | |
customer | Customer | Yes | The customer who posted this comment, or false if not a customer. | Customer |
isAuthor | Boolean | Yes | Whether the comment poster is the blog author. | |
parentCount | Int | Yes | Number of parent comments for this comment. | |
comments | [Comment] | Yes | List of replies to this comment. | Comment |
comment | String | Yes | The comment text content. | |
createdAt | String | Yes | RFC 2822 formatted timestamp when the comment was created. | |
updatedAt | String | Yes | RFC 2822 formatted timestamp when the comment was last updated. |
Relationships
- customer: Links to the
Customerobject representing the author of the comment. This field may benullorfalseif the comment was posted by a non-customer. - comments: An array of
Commentobjects representing replies to this comment, enabling nested comment threads. - The
parentCountfield indicates how many parent comments exist above this comment in the thread hierarchy.
Usage Examples
Basic Query
Fetch basic details of a comment including its ID, author status, and text content:
{
comment(id: 12345) {
id
isAuthor
comment
createdAt
}
}Field Selection
Retrieve a comment with its author details and reply count:
{
comment(id: 12345) {
id
customer {
id
name
email
}
parentCount
comment
}
}Nested Queries
Fetch a comment along with its replies and nested reply authors:
{
comment(id: 12345) {
id
comment
comments {
id
comment
customer {
id
name
}
}
}
}Filtering and Sorting
While the Comment type itself does not define filtering or sorting arguments, these operations typically occur at the query level where comments are requested. For example, to fetch comments sorted by creation date:
{
comments(filter: { postId: 67890 }, sort: CREATED_AT_DESC, first: 10) {
edges {
node {
id
comment
createdAt
}
}
}
}Note: The above filtering and sorting example assumes the existence of a comments query with appropriate arguments, which is outside the scope of the Comment object type.
Implements
The Comment type does not explicitly implement any GraphQL interfaces.
Connections
The comments field provides a connection to nested Comment objects representing replies to the current comment, enabling recursive traversal of comment threads.
Related Types
- Customer: Represents the author of the comment when applicable.
- Comment: The type is self-referential through the
commentsfield, allowing nested replies.
Best Practices
- When querying comments with nested replies, limit the depth or number of nested comments to avoid performance issues.
- Use selective field queries to fetch only the necessary data, especially when retrieving customer information.
- Consider caching comment data where possible, as comments and their replies may not change frequently.
- Use the
createdAtandupdatedAttimestamps to implement client-side sorting or synchronization logic.
Notes
- All fields in the
Commenttype are optional and may returnnullif data is unavailable. - The
createdAtandupdatedAttimestamps follow the RFC 2822 format. - The API currently requires no authentication to query comments, but this may change in future versions.
- The
customerfield may befalseornullif the comment was posted by a non-customer user. - No computed or derived fields are defined on the
Commenttype. - No field arguments are defined on the
Commentfields themselves; filtering and sorting are handled at the query level.
For all queries, use the endpoint:
https://www.mystoreurl.com/graphql/0.8.0Example error handling pattern in JavaScript when querying comments:
async function fetchComment(commentId) {
const query = `
query GetComment($id: Int!) {
comment(id: $id) {
id
comment
customer {
id
name
}
}
}
`;
try {
const response = await fetch('https://www.mystoreurl.com/graphql/0.8.0', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query, variables: { id: commentId } }),
});
const { data, errors } = await response.json();
if (errors) {
console.error('GraphQL errors:', errors);
return null;
}
return data.comment;
} catch (error) {
console.error('Network error:', error);
return null;
}
}