apollo-kotlin icon indicating copy to clipboard operation
apollo-kotlin copied to clipboard

@nonull could have surprising effects in error cases

Open BoD opened this issue 3 years ago • 1 comments

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

BoD avatar Dec 15 '21 16:12 BoD

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.

martinbonnin avatar Dec 16 '21 10:12 martinbonnin

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

martinbonnin avatar Nov 28 '23 15:11 martinbonnin