core icon indicating copy to clipboard operation
core copied to clipboard

GraphQL ReadProvider "Item from read provider should be a nullable object."

Open nuryagdym opened this issue 2 years ago • 2 comments

API Platform version(s) affected: 3.2.7

Description
I am getting "Item from read provider should be a nullable object." error when I request a single item via GraphQL query if item with that id does not exist. When item exists then it is working properly.

I debugged a little bit and found following infos:

  • error is thrown here: https://github.com/api-platform/core/blob/a749fe8494a5b3ca41139a418ed1e29c3e7b33a6/src/GraphQl/State/Provider/ReadProvider.php#L82

  • on line 66 of ReadProvider ItemNotFoundException was thrown and caught here: https://github.com/api-platform/core/blob/a749fe8494a5b3ca41139a418ed1e29c3e7b33a6/src/GraphQl/State/Provider/ReadProvider.php#L68

I am new to GraphQL so I don't know if it is the correct behaviour. How to reproduce
Try to fetch an item that does not exist via GraphQL API

Possible Solution
Should not it just return null if item is not found instead of throwing an exception?

Additional Context

nuryagdym avatar Dec 29 '23 14:12 nuryagdym

Same here

Zippovich2 avatar Jan 15 '24 12:01 Zippovich2

please update to latest 3.2.

we should probably just use the same logic that I see at https://github.com/api-platform/core/blob/a749fe8494a5b3ca41139a418ed1e29c3e7b33a6/src/GraphQl/State/Provider/ReadProvider.php#L71

I would be curious to see what test fail on this use case. Feel free to patch it.

soyuka avatar Jan 15 '24 13:01 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 Mar 15 '24 20:03 stale[bot]