glesys / butler-graphql

An opinionated GraphQL package for Laravel.
MIT License
34 stars 5 forks source link

Cast backed enum to its value when return type is a 'leaf' #50

Closed ttrig closed 2 years ago

ttrig commented 2 years ago

tldr; Eloquent models casting enums was catched by the fieldFromArray (because of ArrayAccess) and the enum instance was returned instead of its value resulting in a "Expected a value of type "MyEnum" but received: instance of App\Enums\MyEnum" error.

emil-nasso commented 2 years ago

Should we maybe add a test for something that is "fully wrapped"?

[String!]! => [$phpEnum]

Mostly to make sure that the recursion of getWrappedType works as we expect.

Edit: We don't have support for "converting" lists of php-enums to [String!]!. This would be considered a "bonus" in my eyes. Not needed for this PR.