Skip to content

Commit fac6205

Browse files
authored
Serialize BackedEnum instances by name, not value
1 parent 3bc2778 commit fac6205

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ You can find and compare releases at the [GitHub release page](https://github.co
99

1010
## Unreleased
1111

12+
## v15.14.3
13+
14+
### Fixed
15+
16+
- Serialize `BackedEnum` instances by name, not value https://github.com/webonyx/graphql-php/pull/1618
17+
1218
## v15.14.2
1319

1420
### Changed

src/Type/Definition/EnumType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function serialize($value)
137137
}
138138

139139
if (is_a($value, \BackedEnum::class)) {
140-
return $value->value;
140+
return $value->name;
141141
}
142142

143143
if (is_a($value, \UnitEnum::class)) {

tests/Type/PhpEnumType/BackedPhpEnum.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
enum BackedPhpEnum: string
66
{
7-
case A = 'A';
7+
case A = 'a';
88
case B = 'B';
9-
case C = 'C';
9+
case C = 'the value does not really matter';
1010
}

0 commit comments

Comments
 (0)