Kind: Graphql Type
Blog post
Post is a GraphQL object type representing a blog post in the backend API, including its core content (title, content) and publication state (published, publishedAt). It acts as an aggregate root that links to related entities like author, comments, likes, and tags, while also exposing derived data such as commentCount. This type is typically returned by post-related queries and mutations and drives client rendering of post detail and list views.
Diagram
mermaidgraph LR Post[Post] User[User] Comment[Comment] Like[Like] Tag[Tag] Post -->|author: User!| User Post -->|comments: [Comment!]!| Comment Post -->|likes: [Like!]!| Like Post -->|tags: [Tag!]!| Tag Post -->|id: ID!| ID[(ID)] Post -->|title: String!| String[(String)] Post -->|content: String!| String2[(String)] Post -->|published: Boolean!| Bool[(Boolean)] Post -->|publishedAt: DateTime| DateTime[(DateTime)] Post -->|commentCount: Int!| Int[(Int)]
Usage
ts// Example using graphql-request in a Next.js/NestJS-compatible setup.
import { GraphQLClient, gql } from "graphql-request";
const client = new GraphQLClient(process.env.API_URL!, {
headers: {
// e.g. Authorization: `Bearer ${token}`,
},
});
const GET_POST = gql`
query GetPost($id: ID!) {
post(id: $id) {
id
title
content
published
publishedAt
commentCount
author {
id
name
}
tags {
id
name
}
comments {
id
content
author {
id
name
}
}
likes {
id
user {
id
name
}
}
}
}
`;
type GetPostResult = {
post: {
id: string;
title: string;
content: string;
published: boolean;
publishedAt: string | null;
commentCount: number;
author: { id: string; name: string };
tags: Array<{ id: string; name: string }>;
comments: Array<{ id: string; content: string; author: { id: string; name: string } }>;
likes: Array<{ id: string; user: { id: string; name: string } }>;
};
};
export async function fetchPost(id: string) {
const data = await client.request<GetPostResult>(GET_POST, { id });
return data.post;
}
// Usage:
// const post = await fetchPost("post_123");
// console.log(post.title, post.commentCount);
AI Coding Instructions
- Treat
Postas an aggregate: keepauthor,comments,likes, andtagsresolved consistently (avoid partial resolver behavior that returnsnullfor non-nullable fields). - Ensure
commentCount: Int!stays in sync withcomments(compute via DB aggregation where possible; avoid N+1 counting per post). - Respect publication semantics: if
publishedisfalse,publishedAtshould typically benull(enforce in mutations and resolvers). - When adding fields, keep GraphQL nullability intentional: only mark as non-null (
!) if the resolver/data layer can guarantee it under all conditions.
Relationships
- TYPE_OF →
DateTime - TYPE_OF →
User - TYPE_OF →
Comment - TYPE_OF →
Like - TYPE_OF →
Tag - TYPE_OF →
DateTime - TYPE_OF →
DateTime
Referenced By
post(TYPE_OF)createPost(TYPE_OF)updatePost(TYPE_OF)newPost(TYPE_OF)User(TYPE_OF)Comment(TYPE_OF)Like(TYPE_OF)Tag(TYPE_OF)PostConnection(TYPE_OF)
Was this page helpful?