You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LinksHandler throwing: The class "\App\Entity\xxx" cannot be retrieved from "\App\ApiResource\xxx". When using stateOptions with stateOption entityClass and Collections - GraphQL Query
#6590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Description
When converting from Entity ApiResource to DTOs with ApiResource and querying an API Resource which contains a OneToMany Relationship, an error is thrown by the LinksHandlerTrait which states: The class "\App\Entity\xxx" cannot be retrieved from "\App\ApiResource\xxx" which is unexpected, as the Entity should not be retrieved from the DTO Class.
Note: This works fine using the Entity ApiResource.
Comparing the Processed Data inside the File: api/vendor/api-platform/core/src/Doctrine/Common/State/LinksHandlerTrait.php at Line 80 - 85 i could see, that the Handler is fed with resourceClass \App\Entity\xxx which is compared to \Api\Resource\xxx and obviously fails. Debugging the same Data when defining the API Resource above an Entity i could see, that \App\Entity\xxx was compared against \App\Entity\xxx which does obviously work.
Possible Solution
I've looked into the LinksHandlerTrait File (api/vendor/api-platform/core/src/Doctrine/Common/State/LinksHandlerTrait.php), it seems that we could replace the $resourceClass ( which seems to be populated with the Entity Class ) with $context['resource_class']. If we do that, the query works just fine, but so far i have not checked any side effects regarding mutations etc.
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.
Just for visibility, there is an open pull request even if the issue itself is closed: #6592. Probably it would be wise to open the issue as bug since the pull request is kind of stale, but the issue is confirmed.
API Platform version(s) affected: 3.3.12
Description
When converting from Entity ApiResource to DTOs with ApiResource and querying an API Resource which contains a OneToMany Relationship, an error is thrown by the LinksHandlerTrait which states:
The class "\App\Entity\xxx" cannot be retrieved from "\App\ApiResource\xxx"
which is unexpected, as the Entity should not be retrieved from the DTO Class.Note: This works fine using the Entity ApiResource.
Comparing the Processed Data inside the File:
api/vendor/api-platform/core/src/Doctrine/Common/State/LinksHandlerTrait.php
at Line 80 - 85 i could see, that the Handler is fed with resourceClass\App\Entity\xxx
which is compared to\Api\Resource\xxx
and obviously fails. Debugging the same Data when defining the API Resource above an Entity i could see, that\App\Entity\xxx
was compared against\App\Entity\xxx
which does obviously work.How to reproduce
See my example Repository: https://github.com/KaiGrassnick/api-platform3-graphql-one-to-many-issue
Otherwise:
webonyx/graphql-php
)stateOptions
referring to the Entity ( example below )Example API Resources:
Possible Solution
I've looked into the LinksHandlerTrait File (
api/vendor/api-platform/core/src/Doctrine/Common/State/LinksHandlerTrait.php
), it seems that we could replace the$resourceClass
( which seems to be populated with the Entity Class ) with$context['resource_class']
. If we do that, the query works just fine, but so far i have not checked any side effects regarding mutations etc.Additional Context
Error Output:
The text was updated successfully, but these errors were encountered: