Hi @midnight,
welcome to the Community!
At this point the short answer would be “no”. But nobody likes a short one, especially if it’s not positive, so I’ll try to elaborate a bit on where we are currently and what’s happening in terms of our roadmap for - what I will generally call - “UDG datasources error handling”.
You seem to be running a very simple use case - one REST API “wrapped” in GQL using UDG. That single REST datasource sometimes returns errors and what your UDG consumer is seeing is 200 OK http response with an empty data
object in the response body.
It looks easy on the surface - just override the 200 OK code with whatever 4xx or 5xx is returned by the upstream and pass the error message in error
object.
But because UDG is capable of fetching data from multiple datasources, there’s usually a more complex use case our users are or will be facing. Say only 2 out of 5 UDG datasources return errors, the rest of the data comes back without issues and can be parsed and returned in the query response. Should the 200 OK still be overridden by one of the 2 error codes? If so, which one in case they are different - like 401 and 500? Should we still return the partial response that the other 3 working datasources provided?
I could go on, because those are exactly the questions we are currently asking ourselves when discussing and designing the error handling in UDG.
If, while looking at UDG for your use case, you have any expectations that you would like to share with us, I will appreciate it greatly, it will definitely help us design this feature better.
One idea that I have as a possible workaround would be to extend your UDG schema something like this:
type Query {
myQuery: Information
}
type Information {
id: ID!
foo: String
fee: String
errors: [Error]
}
type Error {
code: Int
message: String
}
Of course type Error
would need to reflect your REST error response schema, I used code/message as an example.
But if you do it this way it will mean that consumers would need to include field errors
from type Information
with every query they send. When the REST datasource returns no error, that field will come back with null
, but when it does, then all the other requested fields would be null
and errors would have a value.
I’ll be honest, I did not try it myself yet, but I will and let you know how it worked.