facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.38k stars 1.82k forks source link

Integrate missing required fields into errorResponseFields #4807

Open captbaritone opened 3 hours ago

captbaritone commented 3 hours ago

This represents the last major step in consolidating how field errors are modeled on Snapshot. Here we move missing required fields into the existing errorResponseFields (which should probably get renamed at some point) and are now directly stored in their event shape, rather than needing an intermediate shape.

This comes with a few small changes:

  1. The decision of if we should throw or not is now guided by the actual event rather than just the presence of @throwOnFieldError on the fragment being read. This is important because we may inherit events from resolvers that we read.
  2. We now throw individual errors based on the first field error we encounter rather than throwing a composite error with lots of metadata attached. In practice I think this is probably better. Many errors are likely uncommon, and having an informative error message is likely to result in a more actionable error report (error reporting infra won't easily pick up the metadata). Advanced users are free to use the FieldLogger to build more advanced errors if they wish
  3. We dropped the feature where cascading missing required field errors were not logged. We now log all required field errors (even if some are the result of previous errors) but only the first error will throw.
facebook-github-bot commented 2 hours ago

@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.