core icon indicating copy to clipboard operation
core copied to clipboard

GraphQL ReadStage->getItem() exception handling results in different behavior since 3.2.*

Open zwentastic opened this issue 1 year ago • 5 comments

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.

zwentastic avatar Jan 24 '24 15:01 zwentastic

Additions:

  • Changed use statement of src/GraphQl/Resolver/Stage/ReadStage.php: 3.1.25 vs 3.2.12
  • Related try/catch in ReadStage->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
  }
}

zwentastic avatar Jan 25 '24 12:01 zwentastic

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 Mar 26 '24 04:03 stale[bot]

can you help fixing this?

soyuka avatar Mar 26 '24 08:03 soyuka

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 May 25 '24 13:05 stale[bot]

It's not "completed", it's still "not done"

zwentastic avatar Jun 03 '24 04:06 zwentastic