// GraphQL Schema 加载器（从 .graphql 文件加载 SDL，B1 裁决）
import { readFileSync } from "node:fs";
import path from "node:path";
import { makeExecutableSchema } from "@graphql-tools/schema";
import type { IResolvers } from "@graphql-tools/utils";

/** schema 文件路径（monorepo 相对路径） */
const SCHEMA_PATH = path.resolve(
  process.cwd(),
  "../../packages/shared-ts/contracts/graphql/teacher-bff.schema.graphql",
);

/**
 * 加载 GraphQL schema（从 SDL 文件 + resolvers 构建可执行 schema）
 * schema 文件位于 packages/shared-ts/contracts/graphql/（ARB-001 仲裁产物）
 */
export function loadSchema(
  resolvers: IResolvers,
): ReturnType<typeof makeExecutableSchema> {
  const typeDefs = readFileSync(SCHEMA_PATH, "utf-8");
  return makeExecutableSchema({ typeDefs, resolvers });
}
