core
core copied to clipboard
GraphQL ReadStage->getItem() exception handling results in different behavior since 3.2.*
API Platform version(s) affected: 3.2.*
Description
GraphQL: In IriConverter->getResourceFromIri() the exception ApiPlatform\Exception\ItemNotFoundException is thrown, when not finding a proper data set. ReadStage->getItem() calls IriConverter->getResourceFromIri() and catches ItemNotFoundExceptions.
In version 3.1.25 catching the exceptions worked.
But since 3.2.0 class ReadStage uses ApiPlatform\Metadata\Exception\ItemNotFoundException instead of ApiPlatform\Exception\ItemNotFoundException, so the exceptions thrown instead catched.
How to reproduce
GraphQL item query that refers to a not existing ID.
In Version 3.1.25 the query returns null
Since version 3.2.0 the query returns null (as data) and also an "Internal server error".
Possible Solution
Catch both exceptions - or throw/catch the correct exception.
Additions:
- Changed
usestatement ofsrc/GraphQl/Resolver/Stage/ReadStage.php: 3.1.25 vs 3.2.12 - Related
try/catchinReadStage->getItem(): 3.1.25 / 3.2.12 - Unchanged throwing exception in
IriConverter->getResourceFromIri(): 3.1.25 / 3.2.12
Example query:
{
book(id: "books/not-existing-id") {
title
}
}
Response based on 3.1.25:
{
"data": {
"book": null
}
}
Response based on 3.2.12:
{
"errors": [
{
"message": "Internal server error"
}
],
"data": {
"book": null
}
}
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.
can you help fixing this?
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.
It's not "completed", it's still "not done"