-
Notifications
You must be signed in to change notification settings - Fork 660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Error handling -- @catch & partial data #5337
Comments
I like To be discussed: for apps that never want partial results, we could think of a global setting where Tangential remark: if we feel |
This is the default. If you never want partial results, fields without
Is it time to introduce |
A few additional comments:
With the (still subject to change but as of today) implementation, apps that opt-in "error aware parsing" by importing I've been thinking about changing the type of
As of today (still subject to change), I feel we won't be able to remove the v2/v3 mode where |
Description
For previous episodes on error handling, visit #4711
Goal
Simplify the error handling which is currently based on 3 different properties of
ApolloResponse
:response.data
for GraphQL dataresponse.errors
for GraphQL errorsresponse.exception
for network exceptionsThis is confusing and ideally, we want
ApolloResponse
to be a result-like class with eitherdata
or anexception
. There is a lot of brain muscle around result-like classes. Kotlin stdlib hasResult
, Arrow hasEither
, Rust hasResult
, etc... So it feels like a natural fit here.Proposal:
@catch
client directiveInspired by Relay error handling, introduce a
@catch
client directive that allows user to opt-in error handling on a given field.If this field or any sub-field contains an entry in the
errors
array then this error is exposed to the user and no data is shown for that field.Advantages:
data
contains everything needed to display the UI. There's no need to go back to theerrors
array because the error is now inline at the position where it happens. We could keep theerrors
arrays for advanced use cases but in the very large majority of use cases, it shouldn't be needed. We can rely ondata
orexception
again.A
@catch
field is modeled in generated models as a sealed interface and matching result types:Schema:
Query:
Kotlin codegen:
Examples
Product error
Query:
Error Response:
Kotlin test:
price error
If a nested fails, the error is exposed on the closest enclosing
@catch
field:Kotlin test:
The text was updated successfully, but these errors were encountered: