feat: replace Directus with custom Node.js GraphQL backend
Removes Directus 11 and replaces it with a lean, purpose-built backend: - packages/backend/: Fastify v5 + GraphQL Yoga v5 + Pothos (code-first) with Drizzle ORM, Redis sessions (session_token cookie), argon2 auth, Nodemailer, fluent-ffmpeg, and full gamification system ported from bundle - Frontend: @directus/sdk replaced by graphql-request v7; services.ts fully rewritten with identical signatures; directus.ts now re-exports from api.ts - Cookie renamed directus_session_token → session_token - Dev proxy target updated 8055 → 4000 - compose.yml: Directus service removed, backend service added (port 4000) - Dockerfile.backend: new multi-stage image with ffmpeg - Dockerfile: bundle build step and ffmpeg removed from frontend image - data-migration.ts: one-time script to migrate all Directus/sexy_ tables Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
83
packages/backend/src/graphql/resolvers/articles.ts
Normal file
83
packages/backend/src/graphql/resolvers/articles.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { builder } from "../builder.js";
|
||||
import { ArticleType } from "../types/index.js";
|
||||
import { articles, users } from "../../db/schema/index.js";
|
||||
import { eq, and, lte, desc } from "drizzle-orm";
|
||||
|
||||
builder.queryField("articles", (t) =>
|
||||
t.field({
|
||||
type: [ArticleType],
|
||||
args: {
|
||||
featured: t.arg.boolean(),
|
||||
limit: t.arg.int(),
|
||||
},
|
||||
resolve: async (_root, args, ctx) => {
|
||||
let query = ctx.db
|
||||
.select()
|
||||
.from(articles)
|
||||
.where(lte(articles.publish_date, new Date()))
|
||||
.orderBy(desc(articles.publish_date));
|
||||
|
||||
if (args.limit) {
|
||||
query = (query as any).limit(args.limit);
|
||||
}
|
||||
|
||||
const articleList = await query;
|
||||
|
||||
return Promise.all(
|
||||
articleList.map(async (article: any) => {
|
||||
let author = null;
|
||||
if (article.author) {
|
||||
const authorUser = await ctx.db
|
||||
.select({
|
||||
first_name: users.first_name,
|
||||
last_name: users.last_name,
|
||||
avatar: users.avatar,
|
||||
description: users.description,
|
||||
})
|
||||
.from(users)
|
||||
.where(eq(users.id, article.author))
|
||||
.limit(1);
|
||||
author = authorUser[0] || null;
|
||||
}
|
||||
return { ...article, author };
|
||||
}),
|
||||
);
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
builder.queryField("article", (t) =>
|
||||
t.field({
|
||||
type: ArticleType,
|
||||
nullable: true,
|
||||
args: {
|
||||
slug: t.arg.string({ required: true }),
|
||||
},
|
||||
resolve: async (_root, args, ctx) => {
|
||||
const article = await ctx.db
|
||||
.select()
|
||||
.from(articles)
|
||||
.where(and(eq(articles.slug, args.slug), lte(articles.publish_date, new Date())))
|
||||
.limit(1);
|
||||
|
||||
if (!article[0]) return null;
|
||||
|
||||
let author = null;
|
||||
if (article[0].author) {
|
||||
const authorUser = await ctx.db
|
||||
.select({
|
||||
first_name: users.first_name,
|
||||
last_name: users.last_name,
|
||||
avatar: users.avatar,
|
||||
description: users.description,
|
||||
})
|
||||
.from(users)
|
||||
.where(eq(users.id, article[0].author))
|
||||
.limit(1);
|
||||
author = authorUser[0] || null;
|
||||
}
|
||||
|
||||
return { ...article[0], author };
|
||||
},
|
||||
}),
|
||||
);
|
||||
Reference in New Issue
Block a user