Files
Edu/apps/portal-shell/codegen.yml
SpecialX f623dcf4a7 feat(portal-shell): extract gql documents to operations layer
M1 Task 3: 从 31 widget 抽取 51 个 gql 文档到 7 个 operations 文件

- universal(7) + sidebar(3) + topbar(3) + teacher(6) + student(8) + parent(4) + admin(20) = 51 DOC

- operations/index.ts barrel 统一出口

- codegen.yml 启用 documents + skipDocumentsValidation(services 子图字段待补齐)

- 生成 types.ts (28KB) + operations.ts (10KB)
2026-07-17 12:37:36 +08:00

57 lines
2.4 KiB
YAML

# graphql-codegen configuration
#
# Schema source: combined-schema.graphql (generated by scripts/normalize-schema.ts
# from services subgraph SDL files, with federation `extend type Query` normalized).
#
# Subgraph list (7 with GraphQL): iam / config-service / core-edu / content /
# msg / data-ana / ai (classes has no GraphQL subgraph yet).
#
# Outputs:
# - __generated__/types.ts: all GraphQL schema types (always generated)
# - __generated__/operations.ts: DocumentNode constants emitted from
# operations/*.graphql.ts via typescript-document-nodes plugin.
#
# Related: spec section 2.4
schema:
- src/lib/api/__generated__/combined-schema.graphql
documents: src/lib/api/operations/**/*.graphql.ts
# Schema validation is skipped because services/ai subgraph has invalid input
# types (ChatRequestInput.messages references output type ChatMessage; same
# for ChatResponseInput.usage → Usage). normalize-schema.ts rewrites those
# field types to String as a codegen-only sanitize.
skipSchemaValidation: true
generates:
src/lib/api/__generated__/types.ts:
plugins:
- typescript
src/lib/api/__generated__/operations.ts:
# typescript-document-nodes only: emits typed DocumentNode constants
# from the gql templates in operations/*.graphql.ts. We deliberately
# omit typescript-operations here because portal-shell widgets use
# forward-looking spec fields (grades, myClasses, lessonPlans, etc.)
# that are not yet present in services subgraph SDL; once services
# catch up we can re-add typescript-operations for full query typing.
plugins:
- typescript-document-nodes
config:
preResolveTypes: true
skipTypename: true
exportTypeKeyOnly: true
useTypeImports: true
# Generated operations.ts should import `gql` from @apollo/client (the
# package portal-shell actually uses) instead of the default graphql-tag.
gqlImport: "@apollo/client#gql"
# Skip document validation against schema. portal-shell widgets use spec
# forward-looking fields (grades, myClasses, lessonPlans, etc.) not yet
# implemented in services subgraph SDL. Without this flag, codegen would
# emit 44 "Cannot query field X on type Query" errors and refuse to write
# operations.ts. The runtime apollo-router validates documents at request
# time, so skipping here only affects codegen-time type generation.
# Once services catch up, remove this flag to re-enable validation.
skipDocumentsValidation: true