Skip to content

Commit

Permalink
Serialize BackedEnum instances by name, not value
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia authored Oct 17, 2024
1 parent 3bc2778 commit fac6205
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ You can find and compare releases at the [GitHub release page](https://github.co

## Unreleased

## v15.14.3

### Fixed

- Serialize `BackedEnum` instances by name, not value https://github.com/webonyx/graphql-php/pull/1618

## v15.14.2

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Definition/EnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function serialize($value)
}

if (is_a($value, \BackedEnum::class)) {
return $value->value;
return $value->name;
}

if (is_a($value, \UnitEnum::class)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Type/PhpEnumType/BackedPhpEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

enum BackedPhpEnum: string
{
case A = 'A';
case A = 'a';
case B = 'B';
case C = 'C';
case C = 'the value does not really matter';
}

0 comments on commit fac6205

Please sign in to comment.