Files
Edu/services/config-service/src/graphql/graphql.module.ts
SpecialX 9cedf0c437 feat(portal-shell): v2.0 P0 shadcn standardization + security + streaming + error handling
- shadcn/ui 标准化:废弃纸感令牌,统一 bg-background/text-foreground 等
- Tailwind v4 + @theme inline,移除 tailwind.config.js
- React 19 use() + Suspense 流式渲染,首屏骨架秒出
- 三级错误边界:Route → Section → Widget 层层兜底
- 错误上报:useErrorReport → sendBeacon → /api/log mock 端点
- 三层安全边界:L1 角色门禁 / L2 权限点门禁 / L3 数据范围
- 权限位图 base36 压缩:67 权限点 → ~14 字符,JWT 体积减少 ≥ 99%
- notify 统一 Toast 封装,禁止业务直接 import sonner
- PluginBoundary 替代 PluginLoader(错误边界 + Suspense + Skeleton 三件套)

验证:typecheck 0 错误 / lint 0 错误 / build 6 路由生成成功
2026-07-17 16:10:05 +08:00

60 lines
2.1 KiB
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.
/**
* config-service GraphQL 子图模块v2.1 M3
*
* Apollo Federation 2 子图,提供 4 类 Entity 查询:
* - PluginRegistry@key(fields: "pluginId")
* - RolePluginMapping
* - LayoutTemplate
* - UserLayoutOverride@key(fields: "userId")
*
* 强制约束:
* - @key 解析器必须使用 DataLoaderADR-035
* - RouterAuthGuard 校验 Router-Authorization HeaderADR-036
*/
import { Module } from "@nestjs/common";
import { GraphQLModule } from "@nestjs/graphql";
import { ApolloFederationDriver, ApolloDriverConfig } from "@nestjs/apollo";
import { join } from "node:path";
import { GraphqlContext } from "@edu/shared-ts/federation";
import { ConfigModule } from "../config-config/config.module.js";
import { PluginResolver } from "./resolvers/plugin.resolver.js";
import { LayoutTemplateResolver } from "./resolvers/layout-template.resolver.js";
import { UserLayoutResolver } from "./resolvers/user-layout.resolver.js";
import { PluginConfigResolver } from "./resolvers/plugin-config.resolver.js";
import { DataLoaderService } from "./dataloader.service.js";
@Module({
imports: [
ConfigModule,
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloFederationDriver,
// Federation 2 子图
autoSchemaFile: {
path: join(process.cwd(), "src/graphql/generated/schema.graphql"),
federation: 2,
},
// /graphql 端点Apollo Router 访问入口)
path: "/graphql",
// 禁用 playground生产环境通过 Router 访问)
playground: process.env.NODE_ENV === "development",
introspection: process.env.NODE_ENV === "development",
// Context 从 HTTP headers 构造
context: (ctx: {
req: { headers: Record<string, string | undefined> };
}) => ({
req: ctx.req,
graphqlContext: GraphqlContext.fromHeaders(ctx.req.headers),
}),
}),
],
providers: [
PluginResolver,
LayoutTemplateResolver,
UserLayoutResolver,
PluginConfigResolver,
DataLoaderService,
],
exports: [DataLoaderService],
})
export class GraphqlModule {}