Skip to content

Commit a0b43de

Browse files
committed
docs: restore User Feed and Posts with Comment Count examples
1 parent 4e8f632 commit a0b43de

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

.agents/skills/constructive-graphql/references/codegen-relations.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,68 @@ const authorsWithCounts = authors.map(author => ({
484484
}));
485485
```
486486
487+
### Posts with Comment Count and Latest Comment
488+
489+
```typescript
490+
const posts = await db.post.findMany({
491+
select: {
492+
id: true,
493+
title: true,
494+
comments: {
495+
select: { id: true, body: true, createdAt: true },
496+
orderBy: { createdAt: 'DESC' },
497+
},
498+
},
499+
}).execute().unwrap();
500+
501+
const postsWithStats = posts.map(post => ({
502+
id: post.id,
503+
title: post.title,
504+
commentCount: post.comments.length,
505+
latestComment: post.comments[0] ?? null,
506+
}));
507+
```
508+
509+
### User Feed with Mixed Content
510+
511+
```typescript
512+
const user = await db.user.findOne({
513+
id: userId,
514+
select: {
515+
id: true,
516+
name: true,
517+
// Own posts
518+
posts: {
519+
select: { id: true, title: true, createdAt: true },
520+
orderBy: { createdAt: 'DESC' },
521+
first: 10,
522+
},
523+
// Comments made
524+
comments: {
525+
select: {
526+
id: true,
527+
body: true,
528+
createdAt: true,
529+
post: { select: { id: true, title: true } },
530+
},
531+
orderBy: { createdAt: 'DESC' },
532+
first: 10,
533+
},
534+
// Favorites
535+
favorites: {
536+
select: {
537+
post: {
538+
select: { id: true, title: true, author: { select: { name: true } } },
539+
},
540+
createdAt: true,
541+
},
542+
orderBy: { createdAt: 'DESC' },
543+
first: 10,
544+
},
545+
},
546+
}).execute().unwrap();
547+
```
548+
487549
### Full M:N Lifecycle
488550
489551
```typescript

0 commit comments

Comments
 (0)