import { Router } from "express"; import type { Request } from "express"; import { graphqlClient } from "../lib/graphqlClient"; import { respondWithError } from "../lib/error"; import { BlogStatsDocument, type BlogStatsQuery, } from "../../shared/generated/graphql"; const router = Router(); // GET /api/blog/stats interface GqlRequest extends Request { gql?: typeof graphqlClient; } router.get("/stats", async (req: GqlRequest, res) => { try { const client = req.gql || graphqlClient; const data = await client.request(BlogStatsDocument, {}); res.json(data.blog); } catch (error) { respondWithError(res, error, "Failed to fetch blog stats"); } }); export default router;