Ensure new GraphQL fields are upgraded in persisted models
Old player data will not include newly added fields. Any time you add a field to a GraphQL type that maps to a persisted model (e.g., Hero), you must update the model upgrade path so legacy records load safely.
What to do when adding a new field:
Make it optional in Partial types:
Partial<Hero> (or equivalent) union in db/models/* to include the new key so old data can pass through the upgrader without compile errors.Provide a default in upgrade():
upgrade(data) function, initialize the new field with a sensible default. If the field is computed-only, set a conservative placeholder; the resolver should remain source of truth.Keep logic single-sourced:
upgrade() to satisfy typing; do not duplicate complex calculations.Regenerate code and validate:
yarn --cwd proofofcombat-server generateyarn --cwd proofofcombat-ui generateyarn agent:check to catch codegen or runbook drift.Common pitfalls:
Partial<T> leads to TypeScript errors when loading old data.upgrade() creates drift; prefer resolvers/helpers for truth, defaults for typing only..graphql queries in UI to request new fields after server changes.