From fac6205e957c9fbe0145606bc82a32973db1a339 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Thu, 17 Oct 2024 15:03:37 +0200 Subject: [PATCH] Serialize `BackedEnum` instances by name, not value --- CHANGELOG.md | 6 ++++++ src/Type/Definition/EnumType.php | 2 +- tests/Type/PhpEnumType/BackedPhpEnum.php | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 738b5746e..5f021dde0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Type/Definition/EnumType.php b/src/Type/Definition/EnumType.php index 087788728..f094147df 100644 --- a/src/Type/Definition/EnumType.php +++ b/src/Type/Definition/EnumType.php @@ -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)) { diff --git a/tests/Type/PhpEnumType/BackedPhpEnum.php b/tests/Type/PhpEnumType/BackedPhpEnum.php index 3a6293c8a..958f506ef 100644 --- a/tests/Type/PhpEnumType/BackedPhpEnum.php +++ b/tests/Type/PhpEnumType/BackedPhpEnum.php @@ -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'; }