Kind: Graphql Type
Comment on a post
Comment represents a user-authored message attached to a post. It supports threaded discussions through an optional parent comment and a collection of nested replies, while tracking creation and update timestamps.
Diagram
mermaidgraph LR Comment[Comment] User[User] Post[Post] Parent[Parent Comment] Replies[Reply Comments] Comment -->|author| User Comment -->|post| Post Comment -->|parent: optional| Parent Comment -->|replies| Replies
Usage
tsimport { gql } from "@apollo/client";
const GET_POST_COMMENTS = gql`
query GetPostComments($postId: ID!) {
post(id: $postId) {
id
title
comments {
id
content
createdAt
updatedAt
author {
id
name
}
replies {
id
content
createdAt
author {
id
name
}
}
}
}
}
`;
// Example response shape:
// Comment includes its author, post relationship, optional parent,
// and recursively nested replies.
AI Coding Instructions
- Query
authorwhen rendering comments, sinceCommentonly stores the relationship rather than author display details. - Treat
parentas nullable; top-level comments do not have a parent comment. - Request
repliesexplicitly when implementing threaded discussion views, and limit nesting depth where needed to avoid overly large responses. - Use
createdAtandupdatedAtasDateTimevalues; convert them to local display formats in the client. - Associate new comments with a
Post, and provide a parent comment identifier only when creating a reply.
Relationships
- TYPE_OF →
User - TYPE_OF →
Post - TYPE_OF →
Comment - TYPE_OF →
Comment - TYPE_OF →
DateTime - TYPE_OF →
DateTime
Referenced By
addComment(TYPE_OF)newComment(TYPE_OF)Post(TYPE_OF)Comment(TYPE_OF)Comment(TYPE_OF)
Was this page helpful?