Files
Edu/apps/portal-shell/codegen.yml
SpecialX 0beeff6329 feat(portal-shell): restore codegen typescript-operations for data-ana domain (P1-7)
ARCHITECTURE.md §10 P1-7: dashboard domain's 6 operations strictly
match the schema, so disable skipDocumentsValidation for that output
and restore per-operation type generation.

Changes:
- codegen.yml: add dashboard-types.ts output (typescript +
  typescript-operations plugins, skipDocumentsValidation: false);
  move documents config into each generates entry
- dashboard.ts: remove 14 handwritten interfaces and 6 internal query
  type aliases; derive types via NonNullable<GetXxxQuery['xxx']> so
  the public hook API shape stays unchanged
- admin/student/teacher page.tsx: add ?? "--" / ?? 0 null guards on
  StatCard value props to match schema nullable semantics (parent page
  already uses toFixed chain, no change needed)

Acceptance (ARCHITECTURE.md §10 P1-7):
- codegen 3 outputs all SUCCESS
- tsc 0 errors / eslint 0 errors / vitest 231 passed / next build ok
- 6 operations strictly match schema with 0 errors

Refs: ARCHITECTURE.md §5.3 data layer / §10 P1-7
2026-07-22 15:37:06 +08:00

79 lines
3.7 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.
# - __generated__/dashboard-types.ts: per-operation types for data-ana domain
# (skipDocumentsValidation: false). Other domains still reference forward-looking
# spec fields not yet in services subgraph SDL; they remain on the global
# skipDocumentsValidation: true. As services catch up, additional per-domain
# outputs can be added (config → core-edu → content → msg → iam order).
#
# Related: spec section 2.4 / 5.3, ARCHITECTURE.md §10 P1-7
schema:
- src/lib/api/__generated__/combined-schema.graphql
# 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.
# Per-domain typed outputs (e.g. dashboard-types.ts) cover the
# operations whose fields DO match the schema today (P1-7).
documents: src/lib/api/operations/**/*.graphql.ts
plugins:
- typescript-document-nodes
# P1-7: data-ana domain (dashboard.graphql.ts) — skipDocumentsValidation
# closed because all 6 operations strictly match the schema. Generates
# per-operation types so lib/api/dashboard.ts can drop its hand-written
# interfaces. Config domain closure deferred until LayoutTemplateGql
# schema adds `availableSlots` (admin.graphql.ts GET_LAYOUT_TEMPLATES_DOC
# queries that field but it is not yet in the subgraph SDL).
src/lib/api/__generated__/dashboard-types.ts:
documents: src/lib/api/operations/dashboard.graphql.ts
plugins:
- typescript
- typescript-operations
config:
skipDocumentsValidation: false
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.
# Per-output overrides (see dashboard-types.ts above) close this flag for
# specific domains whose operations DO match the schema (P1-7).
skipDocumentsValidation: true