Skip to content

Commit 159f237

Browse files
committed
docs: drop the 'bare single #[EnumValue] to silence' shortcut recommendation
Recommending users annotate a single case to silence the advisory is actively misleading: once the default flips, every other case would disappear from the schema — the exact opposite of what a user reaching for the shortcut wanted. The honest recommendation is 'annotate every case you want to keep exposed', which aligns their intent with the post-flip behaviour. - Warning message rewritten around 'add to every case you want exposed, omit only from cases you want hidden' instead of 'at least one case silences this notice'. - descriptions.md migration subsection mirrors the same framing. - Color/Size/Position test fixtures now annotate every case, not just the first one, so they demonstrate the correct migration pattern rather than the misleading shortcut.
1 parent a655c49 commit 159f237

5 files changed

Lines changed: 18 additions & 19 deletions

File tree

src/Mappers/Root/EnumTypeMapper.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,10 @@ private function mapByClassName(string $enumClass): EnumType|null
197197
*
198198
* Today every case is automatically exposed in the schema regardless of `#[EnumValue]` —
199199
* this call site keeps that behaviour intact. The notice announces the planned migration:
200-
* a future major release will require at least one `#[EnumValue]`-annotated case per
201-
* `#[Type]`-mapped enum, and only annotated cases will participate in the schema
202-
* (mirroring `#[Field]`'s opt-in model on classes). Partial annotation is deliberately
203-
* allowed and intentionally silent — leaving some cases unannotated is the mechanism that
204-
* hides internal cases from the public schema once the default flips, so it must not
205-
* itself produce a warning.
200+
* a future major release will require `#[EnumValue]` on each case that should participate
201+
* in the schema, and unannotated cases will be hidden (mirroring `#[Field]`'s opt-in
202+
* model on classes). Partial annotation is deliberately allowed and intentionally silent
203+
* so that leaving some cases unannotated can be used to hide them once the default flips.
206204
*
207205
* @param class-string<UnitEnum> $enumClass
208206
*/
@@ -211,8 +209,8 @@ private function warnEnumHasNoEnumValueAttribute(string $enumClass): void
211209
trigger_error(
212210
sprintf(
213211
'Enum "%s" is mapped to a GraphQL enum type but declares no #[EnumValue] attributes on any case. '
214-
. 'Today every case is automatically exposed; a future major release will require at least one #[EnumValue]-annotated case per #[Type]-mapped enum, and only annotated cases will participate in the schema (mirroring #[Field]\'s opt-in model on classes). '
215-
. 'Add #[EnumValue] to the case(s) you want to expose — annotating at least one case acknowledges the opt-in model and silences this notice. Cases left unannotated will be hidden from the schema after the future default flip, which is the intended way to keep internal values out of the public API.',
212+
. 'Today every case is automatically exposed; a future major release will require #[EnumValue] on each case that should participate in the schema, and unannotated cases will be hidden (mirroring #[Field]\'s opt-in model on classes). '
213+
. 'Add #[EnumValue] to every case you want to keep exposed. Omit it only from cases you want hidden from the public schema after the future default flip.',
216214
$enumClass,
217215
),
218216
E_USER_DEPRECATED,

tests/Fixtures/Integration/Models/Color.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
)]
1414
enum Color: string
1515
{
16-
// A bare #[EnumValue] acknowledges the opt-in migration without altering runtime behaviour.
17-
// Remove the attribute or annotate specific cases once the enum actually needs per-case
18-
// description/deprecation metadata.
1916
#[EnumValue]
2017
case Green = 'green';
18+
#[EnumValue]
2119
case Red = 'red';
2220
}

tests/Fixtures/Integration/Models/Position.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ enum Position: int
1212
{
1313
#[EnumValue]
1414
case Off = 0;
15+
#[EnumValue]
1516
case On = 1;
1617
}

tests/Fixtures/Integration/Models/Size.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ enum Size
1212
{
1313
#[EnumValue]
1414
case S;
15+
#[EnumValue]
1516
case M;
17+
#[EnumValue]
1618
case L;
1719
}

website/docs/descriptions.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ is an enum value.
131131

132132
### Future migration
133133

134-
A future major release will require at least one `#[EnumValue]`-annotated case per
135-
`#[Type]`-mapped enum; only annotated cases will be exposed in the schema (mirroring
136-
`#[Field]`'s opt-in model). Today every case is still auto-exposed, so nothing breaks.
137-
138-
GraphQLite emits a deprecation notice only when a `#[Type]`-mapped enum has **zero**
139-
`#[EnumValue]` attributes — annotating any single case silences it and acknowledges the
140-
model. Partial annotation is intentional: an unannotated case is how you hide a value from
141-
the public schema once the default flips.
134+
A future major release will require `#[EnumValue]` on each case that should participate in
135+
the schema; unannotated cases will be hidden (mirroring `#[Field]`'s opt-in model). Today
136+
every case is still auto-exposed, so nothing breaks. Add `#[EnumValue]` to every case you
137+
want to keep exposed — omitting it from a case is the mechanism for hiding internal values
138+
once the default flips.
139+
140+
GraphQLite emits a deprecation notice when a `#[Type]`-mapped enum has **zero**
141+
`#[EnumValue]` attributes at all (partial annotation is intentional and stays silent).
142142

143143
## Description uniqueness on `#[ExtendType]`
144144

0 commit comments

Comments
 (0)