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
I was using the gem in on of my previous projects, and while I was testing out multiple scenarios, I found a query where the error handling could be improved.
In case we are querying for multiple nodes, and one of the nodes fail, we receive the same error message for both nodes. In my example we are using encoded IDs, and the failure happens on the ID decoding.
Query example:
As mentioned in the query above, one of the IDs is correct and can be decoded, the other one is incorrect, and when we try to decode the ID, it will raise an error.
As I mentioned, the same error will be returned for both nodes (which is incorrect):
{
"errors": [
{
"message": "Invalid User id decoded: \"VjEtSm9iLXF3ZQ\" -> \"qwe\" (expected an integer)",
"path": [
"nodes",
0
],
},
{
"message": "Invalid User id decoded: \"VjEtSm9iLXF3ZQ\" -> \"qwe\" (expected an integer)",
"path": [
"nodes",
1
],
}
],
"data": {
"nodes": [
null,
null
]
}
}
There might be a few possible solutions for this case:
Return the data that can be fetched for one of the nodes, and return the error for the second one
Return the error for the node that fails and do not return any data for the other one (maybe for security reasons?)
Add a config for this, so we would be able to either do 1. or 2.
As a workaround I updated the code in ApolloFederation::EntitiesField._entities where I did rescue from StandardError, and simply just returned the error instead of raising it. That way the above mentioned 1. solution applies.
Inside the loop I just implemented it like:
rescueStandardError=>ee.class.new(e.message)
The text was updated successfully, but these errors were encountered:
istvanfazakas
changed the title
[IMPROVEMENT] - Improve error handling when having multiple nodes in query
Fix error handling when having multiple nodes in query
Nov 2, 2024
I was using the gem in on of my previous projects, and while I was testing out multiple scenarios, I found a query where the error handling could be improved.
In case we are querying for multiple nodes, and one of the nodes fail, we receive the same error message for both nodes. In my example we are using encoded IDs, and the failure happens on the ID decoding.
Query example:
As mentioned in the query above, one of the IDs is correct and can be decoded, the other one is incorrect, and when we try to decode the ID, it will raise an error.
As I mentioned, the same error will be returned for both nodes (which is incorrect):
There might be a few possible solutions for this case:
1.
or2.
As a workaround I updated the code in
ApolloFederation::EntitiesField._entities
where I did rescue fromStandardError
, and simply just returned the error instead of raising it. That way the above mentioned1.
solution applies.Inside the loop I just implemented it like:
The text was updated successfully, but these errors were encountered: