Adds @RequirePermission to 19 TS GraphQL resolvers across 5 subgraphs (iam, config-service, core-edu, content, msg) per audit report §6.1. Maps: iam user/role -> IAM_USER_READ; config-service 5 queries -> CONFIG_USER; core-edu classInfo -> CLASS_READ, exam -> EXAM_READ, grade -> GRADE_READ, homework -> HOMEWORK_READ, datascope visibleGrades/visibleExams -> GRADE_READ/EXAM_READ; content chapter/knowledgePoint/question/ textbook -> CONTENT_*_READ; msg notifications -> MSG_NOTIFICATION_READ, template -> MSG_NOTIFICATION_MANAGE. Federation resolveReference left unguarded. Python subgraphs (data-ana, ai) deferred to follow-up infrastructure work.
85 lines
1.9 KiB
TypeScript
85 lines
1.9 KiB
TypeScript
/**
|
||
* content KnowledgePoint Resolver(v2.1 M1)
|
||
*
|
||
* Apollo Federation 子图:KnowledgePoint Entity
|
||
* - @key(fields: "id") 支持跨子图引用
|
||
* - @ResolveReference 使用 DataLoader 批量加载(ADR-035)
|
||
*/
|
||
import {
|
||
Resolver,
|
||
Query,
|
||
Args,
|
||
ID,
|
||
ResolveReference,
|
||
ObjectType,
|
||
Field,
|
||
Directive,
|
||
} from "@nestjs/graphql";
|
||
import {
|
||
DataLoaderService,
|
||
type KnowledgePointEntity,
|
||
} from "../dataloader.service.js";
|
||
import {
|
||
Permissions,
|
||
RequirePermission,
|
||
} from "../../middleware/permission.guard.js";
|
||
|
||
/**
|
||
* KnowledgePoint ObjectType(Federation @key)
|
||
* 对应 content_knowledge_points 表
|
||
*/
|
||
@ObjectType()
|
||
@Directive(`@key(fields: "id")`)
|
||
export class KnowledgePoint {
|
||
@Field(() => ID)
|
||
id!: string;
|
||
|
||
@Field()
|
||
chapterId!: string;
|
||
|
||
@Field()
|
||
title!: string;
|
||
|
||
@Field(() => String, { nullable: true })
|
||
description: string | null = null;
|
||
|
||
@Field()
|
||
difficulty!: number;
|
||
|
||
@Field()
|
||
createdAt!: Date;
|
||
|
||
@Field()
|
||
updatedAt!: Date;
|
||
}
|
||
|
||
@Resolver(() => KnowledgePoint)
|
||
export class KnowledgePointResolver {
|
||
constructor(private readonly loader: DataLoaderService) {}
|
||
|
||
/**
|
||
* Federation Reference Resolver
|
||
*
|
||
* 当其他子图通过 @key 引用 KnowledgePoint 时,Router 调用此方法解析。
|
||
* 使用 DataLoader 批量加载,消除 N+1 查询(ADR-035)。
|
||
*/
|
||
@ResolveReference()
|
||
async resolveReference(ref: {
|
||
id: string;
|
||
}): Promise<KnowledgePointEntity | null> {
|
||
return this.loader.knowledgePointLoader.load(ref.id);
|
||
}
|
||
|
||
/**
|
||
* Query: knowledgePoint(id) → KnowledgePoint
|
||
* 通过 Apollo Router 访问,直连被 RouterAuthGuard 拒绝(ADR-036)
|
||
*/
|
||
@Query(() => KnowledgePoint, { nullable: true })
|
||
@RequirePermission(Permissions.CONTENT_KNOWLEDGE_POINT_READ)
|
||
async knowledgePoint(
|
||
@Args("id", { type: () => ID }) id: string,
|
||
): Promise<KnowledgePointEntity | null> {
|
||
return this.loader.knowledgePointLoader.load(id);
|
||
}
|
||
}
|