Repository navigation
Conversation
The normalizer strips `path` from server errors when it attaches them to a
record, so the reader's `(error.path ?? []).join('.')` was always '' in
practice. Build the path the same way as for missing data / @required
errors: start from the field name and prepend parents via
_prependPreviousErrors.
Fixes facebook#4970
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4970.
Problem
relay_field_payload.errorevents always hadfieldPath: ''in real apps, sorelayFieldLoggerand the@throwOnFieldErrormessage ("Received a field error in the server response for field ''") never said which field failed.RelayReader._maybeAddFieldErrorsbuilt the path fromerror.path. ButRelayErrorTriedropspathwhen the normalizer attaches an error to a record (see the__errorsexpectations inRelayResponseNormalizer-test), so in practice the join was always empty. The reader tests passed only because they wrote records by hand with an absolutepathon the stored error.Fix
Build the path the same way the reader already does for
missing_expected_data/missing_required_field: start from the field's name (alias or name), and let_prependPreviousErrorsadd the parent fields as the reader unwinds. The path is therefore relative to the fragment/operation that owns the event, like the other kinds.Tests
RelayReader-RelayErrorHandling-testcase: normalizes a real response with a server error at['me', 'lastName']throughRelayResponseNormalizer, then reads it. It fails before (fieldPath: '') and passes after ('me.lastName').observeQuery/observeFragment:field ''→field 'me.name'/'name'.''→node.friends.edges/node.emailAddresses.name,lastName,nodes.0.lastName).@catch) cases now include the alias (me.myAlias.lastName), same as missing-data events.yarn jest packages: 246 suites, 3824 passed. ESLint and Prettier are clean on the changed files. I couldn't runflow checkmeaningfully on my partial checkout.I used an AI assistant to help with this change. I traced the bug, reproduced it with the normalizer and reviewed the fix and test updates myself.