apollo-kotlin
apollo-kotlin copied to clipboard
@nonull could have surprising effects in error cases
When a nullable field is marked @nonnull
locally, it of course can still be returned as null
by the backend. In particular this can happen in case of partial errors.
When that happens, a JsonDataException
will be thrown at JSON reading time, in the Adapter's fromJson
method.
If we consider that this will probably happen in typical uses, this may be considered surprising to users.
- Maybe it's only a matter of adding a warning in the documentation.
- Or we could investigate a way to throw something less "low level" and more descriptive
Linking https://github.com/apollographql/apollo-kotlin/issues/2520 as it seems to be the same request.
Implementation wise, we could have a FailSafeAdapter(wrappedAdapter)
that wraps another Adapter and catches errors to propagate them up the tree to the next nullable field. From that other issue, looks like error handling will be the difficult thing but certainly sounds doable.
This is addressed with https://github.com/apollographql/apollo-kotlin/pull/5405
Using @nullOnlyOnError
is explicit that the errors may throw and must be handled with @catch
if needed