core icon indicating copy to clipboard operation
core copied to clipboard

GraphQL Doctrine PHP Enum Arrays

Open AlgronovM opened this issue 1 year ago • 1 comments

API Platform version(s) affected: x.y.z 3.2.17

Description
Fields mapped as SIMPLE_ARRAY get converted to paginated Collection instead of array, and are not even normalized.

Fields mapped as JSON get converted to array and are normalized correctly, however appear as untyped Iterable in graphQL schema. Just returning "[EMyEnum]" in TypeConverter does not work.

return new ListOfType($this->resolveType("EMyEnum"));

works in introspection, but fails in normalization.

For the correct normalization I had to inject TypesContainer and use

if($this->typesContainer->has("EMyEnum")){
	return new ListOfType($this->resolveType("EMyEnum"));
}

But it still doesn't work in denormalization: gets denormalized to strings instead of enums, and I had to convert each field in a MutationResolver manually.

How to reproduce

enum EMy string {
    case Foo = 'foo';
    case Bar = 'bar';
}
...
/** @var  Array<int, EMy> */
#[ORM\Column(type: Types::JSON, enumType: EMy::class)]
public array $myEnums = [];

AlgronovM avatar Apr 28 '24 09:04 AlgronovM

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 27 '24 20:06 stale[bot]