Files
Edu/services/parent-bff/src/entry/graphql.controller.ts

26 lines
800 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 v5Yoga 实例本身是 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<void> {
await this.yoga(req, res);
}
}