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:
2026-03-12 17:13:08 +01:00
parent 505d59b813
commit bfd058ae58
4 changed files with 42 additions and 10 deletions

View File

@@ -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,