import { All, Controller, Inject, Req, Res } from "@nestjs/common"; import type { Request, Response } from "express"; import type { YogaInstance } from "../graphql/yoga.js"; /** * GraphQL Yoga 端点 Controller(对齐 02-architecture-design.md §1.1)。 * * - POST /graphql:执行 GraphQL query / mutation * - GET /graphql:开发环境返回 GraphiQL playground(生产关闭) * * graphql-yoga v5:Yoga 实例本身是 callable handler,直接调用 yoga(req, res)。 */ @Controller("v1/graphql") export class GraphqlController { private readonly yoga: YogaInstance; constructor(@Inject("YOGA_INSTANCE") yoga: YogaInstance) { this.yoga = yoga; } @All() async handle(@Req() req: Request, @Res() res: Response): Promise { await this.yoga(req, res); } }