@catch implementation for Apollo Kotlin
#32
Closed
martinbonnin
started this conversation in
General
Replies: 1 comment
-
|
Closing this as it is implemented in Apollo Kotlin 4+. Spec is at https://specs.apollo.dev/nullability/v0.4/ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Opening this discussion to explore how
@catchcould work on Apollo Kotlin.Overall, field errors would make the whole response fail unless caught by
@catch. In that case, codegen would expose error information inline.We're hoping to start iterating on this soon-ish and hopefully we can give more feasibility details. We'll update that discussion as we go.
Formal definition
@catchfields as Kotlin sealed interfaces.In Kotlin, a
@catchfield can be modeled as a sealed interface and matching result types:Schema:
Query:
{ product @catch { name price } }Kotlin codegen:
Examples
Product error
Query:
{ product @catch { name price } }Error Response:
{ "errors": [ { "message": "Cannot resolve product", "path": ["product"] } ], "data": { "product": null } }Kotlin test:
price error
If a nested fails, the error is exposed on the closest enclosing
@catchfield:{ "errors": [ { "message": "Cannot resolve product price", "path": ["product", "price"] } ], "data": { "product": { "name": "Champagne", "price": null } } }Kotlin test:
Questions
the list case
How to represent errors in lists?
{ "errors": [ { "message": "Cannot resolve champagne price", "path": ["product", 0, "price"] } ], "data": { "products": [ { "name": "Champagne", "price": null }, { "name": "Grenadine", "price": 3.49 } ] } }We could have
@catchapply to all items recursively, making it a bit more verbose to check each level.Alternatively, we could specify the dimensions to check using an argument:
{ # catch the field (dimension 0) and the items (dimension 1) products @catch(listDimensions: [0, 1]) # only catch the field (default) products @catch(listDimensions: [0]) # only catch the items products @catch(listDimensions: [1]) }Or
{ # catch the field and the items products @catch(on: "[.].") # only catch the field (default) products @catch(on: ".") # only catch the items products @catch(on: "[.]") }Should
@catchbe allowed on fragments?Given that fragments are used as a unit of data bound to a component, would it be useful to allow
@catchon fragments?Additional
@catchbehaviour?Relay allows different behaviours using a
toparameter. Would it make sense to allow such things on Apollo Kotlin?Beta Was this translation helpful? Give feedback.
All reactions