Commit e7ad416
feat(schema)!: enforce mandatory filters + nonNull-filterable relations on WhereUnique (#471)
`WhereUnique` historically carried only `unique` fields, so a singular
`entity(where: { id })` lookup could bypass the cascade the plural
`entities(where: { … })` query enforced through `filterable: { nonNull:
true }`. Two practical consequences this commit closes:
1. A model with `filterable: { nonNull: true }` on a simple/enum field
(e.g. `Relation.status`) makes `RelationWhere.status` non-nullable —
every plural query must opt in — but `RelationWhereUnique` never
exposed `status`, so the singular `relation(where: { id })` slipped
past the same enforcement.
2. A child model with a relation FK marked `filterable: { nonNull: true
}` couldn't nest the related model's Where on a singular lookup —
`report(where: { id, relation: { status: [ACTIVE] } })` was a schema
error because `ReportWhereUnique` only had `id`.
This commit extends `${model.name}WhereUnique` to include:
- non-relation fields marked `filterable: { nonNull: true }`, typed as
`[T]!` with the model's `filterable.default` honored — same shape and
nullability as the plural Where, so the cascade is enforced
- relation FK fields marked `filterable: { nonNull: true }`, typed as
`RelatedWhere!` — every consumer of the singular query must nest the
related model's Where; the related model's own mandatory filters are
in turn enforced at the inner Where level
Both additions are non-nullable inputs, so the typegen surfaces every
existing `entity(where: { id })` call site that needs to opt into the
cascade — the same "surface everything via typegen" pattern that drove
the original `filterable: { nonNull: true }` design for plural queries.
Just `filterable: true` relations are NOT exposed here on purpose: the
intent is enforcement, and the existing plural Where is where optional
filters belong. To enable the cascade for a new relation FK, mark it
`filterable: { nonNull: true }` in the model spec — typegen will then
fail every site that needs updating.
BREAKING CHANGE: `${model.name}WhereUnique` now carries non-nullable
fields when the model has `filterable: { nonNull: true }` simple/enum
fields or relation FKs. Any consumer schema with such fields will see
its `entity(where: { … })` queries fail typegen until they opt into
the cascade by providing those fields. Upgrade requires updating every
singular-by-id query to nest the mandatory filters (the typegen errors
list exactly the sites that need touching).
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent fda01f5 commit e7ad416
1 file changed
Lines changed: 30 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
138 | 164 | | |
139 | 165 | | |
140 | 166 | | |
| |||
0 commit comments