Closed CvekCoding closed 3 years ago
Yes it would be good to fix this (not sure about the return value though), could you open a PR? Thanks!
This whole DTO thing is messed up. :laughing:
I don't think that's the right fix. We should get the resource class from the input class.
@teohhanhui BTW you are right - DTO is not working, at least for GraphQl
.
When I investigated the reasons, I found the following:
I see only one place where DataTransformerInterface
class used:
https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/Serializer/AbstractItemNormalizer.php#L172-L187
To be invoked, AbstractItemNormalizer::supportDenormalization()
must return true
, which is possible only for ApiResource
class. But if DTO is not ApiResource
(which is desirable) no transformer will ever be called for Input DTO.
To fix this for me I did the hotfix here: https://github.com/api-platform/core/blob/0888bf33429a37d031345bf7c720f23010a50de4/src/GraphQl/Resolver/Factory/ItemMutationResolverFactory.php#L127
by removing priority for inputClass
:
$item = $this->normalizer->denormalize($args['input'], $resourceClass, ItemNormalizer::FORMAT, $context);
I understand that this is not the real fix, but it works for me and DTO
works perfect for me now. I wrote this to give you signal that DTO is broken.
Would love to see this, too. I am currently mapping a flat MySQL structure to DTOs containing non-resource subelements. This is breaking the GraphQL part.
@Siregacvek No, the ItemNormalizer is not used for input/output classes. See ObjectNormalizer in API Platform (we decorate ObjectNornalizer from Symfony).
Is this still an issue with the latest 2.4 branch (use 2.4.x-dev
in composer.json)? If yes, could you help us add a failing Behat test?
As a workaround, you can disable eager loading on the affected operation for now.
Greetings! We appreciate your concern but weren't able to reproduce this issue or it is more of a question. As described in the API Platform contributing guide, we use GitHub issues for bugs and feature requests only.
For support question ("How To", usage advice, or troubleshooting your own code), you have several options:
Feel free reach one of the support channels above. In the meantime we're closing this issue.
Hello. I noticed, that if I use DTO feature and DTO-object is not an
ApiResource
, then here I have exception: https://github.com/api-platform/core/blob/df7087816254085741820cd1513aeb5fdaaf13a1/src/Bridge/Doctrine/Orm/Extension/EagerLoadingExtension.php#L289What if we wrap this line like this?