feat: dynamic magazine category filter from published articles
Add articleCategories GraphQL query returning distinct categories from published articles; magazine page fetches them at load time and renders only categories that actually have content. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { builder } from "../builder";
|
||||
import { ArticleType, ArticleListType, AdminArticleListType } from "../types/index";
|
||||
import { articles, users } from "../../db/schema/index";
|
||||
import { eq, and, lte, desc, asc, ilike, or, count, arrayContains, type SQL } from "drizzle-orm";
|
||||
import { eq, and, lte, desc, asc, ilike, or, count, arrayContains, isNotNull, type SQL } from "drizzle-orm";
|
||||
import { requireAdmin } from "../../lib/acl";
|
||||
import type { DB } from "../../db/connection";
|
||||
|
||||
@@ -74,6 +74,20 @@ builder.queryField("articles", (t) =>
|
||||
}),
|
||||
);
|
||||
|
||||
builder.queryField("articleCategories", (t) =>
|
||||
t.field({
|
||||
type: ["String"],
|
||||
resolve: async (_root, _args, ctx) => {
|
||||
const rows = await ctx.db
|
||||
.selectDistinct({ category: articles.category })
|
||||
.from(articles)
|
||||
.where(and(lte(articles.publish_date, new Date()), isNotNull(articles.category)))
|
||||
.orderBy(asc(articles.category));
|
||||
return rows.map((r) => r.category!);
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
builder.queryField("article", (t) =>
|
||||
t.field({
|
||||
type: ArticleType,
|
||||
|
||||
Reference in New Issue
Block a user