From 9c87ff68b85a15f88dc1caf7f0c4c56d98b96ae6 Mon Sep 17 00:00:00 2001 From: Itamar Kestenbaum Date: Wed, 8 Jan 2025 11:42:04 -0800 Subject: [PATCH] rename errorResponseFields to fieldErrors Reviewed By: evanyeung Differential Revision: D67923811 fbshipit-source-id: c6ebaec0b39cd9e35e4b62baef3e4e3ce3b861d2 --- .../__tests__/LiveResolvers-test.js | 8 +- ...entContainer-WithFragmentOwnership-test.js | 6 +- .../ReactRelayFragmentContainer-test.js | 6 +- .../ReactRelayPaginationContainer-test.js | 8 +- .../ReactRelayRefetchContainer-test.js | 8 +- ...layResolverNullableModelClientEdge-test.js | 6 +- .../relay-hooks/legacy/FragmentResource.js | 9 +- .../relay-hooks/readFragmentInternal.js | 7 +- .../useFragmentInternal_CURRENT.js | 11 +- .../useFragmentInternal_EXPERIMENTAL.js | 11 +- packages/relay-runtime/query/fetchQuery.js | 2 +- .../store/RelayModernFragmentSpecResolver.js | 12 +- packages/relay-runtime/store/RelayReader.js | 152 +++++++++--------- .../store/RelayStoreSubscriptions.js | 4 +- .../relay-runtime/store/RelayStoreTypes.js | 6 +- packages/relay-runtime/store/ResolverCache.js | 4 +- .../relay-runtime/store/ResolverFragments.js | 8 +- ...nEnvironment-ConnectionAndRequired-test.js | 2 +- ...nment-ExecuteWithStreamAndRequired-test.js | 2 +- .../RelayModernStore-Subscriptions-test.js | 6 +- .../store/__tests__/RelayModernStore-test.js | 12 +- .../RelayReader-AliasedFragments-test.js | 18 +-- .../__tests__/RelayReader-CatchFields-test.js | 79 ++++----- .../RelayReader-RelayErrorHandling-test.js | 83 +++++----- .../RelayReader-RequiredFields-test.js | 26 ++- .../__tests__/RelayReader-Resolver-test.js | 50 +++--- .../__tests__/resolvers/LiveResolvers-test.js | 8 +- .../__tests__/resolvers/Resolver-test.js | 4 +- .../__tests__/resolvers/ResolverGC-test.js | 4 +- .../store/observeFragmentExperimental.js | 2 +- .../util/handlePotentialSnapshotErrors.js | 18 +-- 31 files changed, 259 insertions(+), 323 deletions(-) diff --git a/packages/react-relay/__tests__/LiveResolvers-test.js b/packages/react-relay/__tests__/LiveResolvers-test.js index 577a0f2065d53..81878adf1a8ac 100644 --- a/packages/react-relay/__tests__/LiveResolvers-test.js +++ b/packages/react-relay/__tests__/LiveResolvers-test.js @@ -1701,7 +1701,7 @@ test('Errors when reading a @live resolver that does not return a LiveState obje }); const data = environment.lookup(operation.fragment); - expect(data.errorResponseFields).toEqual([ + expect(data.fieldErrors).toEqual([ { kind: 'relay_resolver.error', owner: 'LiveResolversTest18Query', @@ -1757,7 +1757,7 @@ test('provided variables and resolvers', () => { }); const snapshot = environment.lookup(operation.fragment); - expect(snapshot.errorResponseFields).toEqual(null); + expect(snapshot.fieldErrors).toEqual(null); expect(snapshot.data).toEqual({ hello_world_with_provided_variable: 'Hello, Hello, World!!', }); @@ -1782,7 +1782,7 @@ test('allows dependencies to be provided through the store', () => { }); const snapshot = environment.lookup(operation.fragment); - expect(snapshot.errorResponseFields).toEqual(null); + expect(snapshot.fieldErrors).toEqual(null); expect(snapshot.data).toEqual({ hello_world_with_context: 'Hello Hello Allemaal!!', }); @@ -1809,7 +1809,7 @@ test('allows objects to be provided to be provided through the store', () => { }); const snapshot = environment.lookup(operation.fragment); - expect(snapshot.errorResponseFields).toEqual(null); + expect(snapshot.fieldErrors).toEqual(null); expect(snapshot.data).toEqual({ hello_world_with_context_object: 'Hello Hello Allemaal!!', }); diff --git a/packages/react-relay/__tests__/ReactRelayFragmentContainer-WithFragmentOwnership-test.js b/packages/react-relay/__tests__/ReactRelayFragmentContainer-WithFragmentOwnership-test.js index cb30b57d7e101..df9e717555c95 100644 --- a/packages/react-relay/__tests__/ReactRelayFragmentContainer-WithFragmentOwnership-test.js +++ b/packages/react-relay/__tests__/ReactRelayFragmentContainer-WithFragmentOwnership-test.js @@ -206,7 +206,7 @@ describe('ReactRelayFragmentContainer with fragment ownership', () => { }, __fragmentOwner: ownerUser1.request, }, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, isMissingData: false, @@ -333,7 +333,7 @@ describe('ReactRelayFragmentContainer with fragment ownership', () => { }, __fragmentOwner: ownerUser2.request, }, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, isMissingData: false, @@ -403,7 +403,7 @@ describe('ReactRelayFragmentContainer with fragment ownership', () => { }, __fragmentOwner: ownerUser1WithCondVar.request, }, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, isMissingData: false, diff --git a/packages/react-relay/__tests__/ReactRelayFragmentContainer-test.js b/packages/react-relay/__tests__/ReactRelayFragmentContainer-test.js index 40d9f3d73c6ca..2b6ff092b536a 100644 --- a/packages/react-relay/__tests__/ReactRelayFragmentContainer-test.js +++ b/packages/react-relay/__tests__/ReactRelayFragmentContainer-test.js @@ -270,7 +270,7 @@ describe('ReactRelayFragmentContainer', () => { id: '4', name: 'Zuck', }, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, isMissingData: false, @@ -371,7 +371,7 @@ describe('ReactRelayFragmentContainer', () => { name: 'Joe', }, isMissingData: false, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, seenRecords: expect.any(Object), @@ -429,7 +429,7 @@ describe('ReactRelayFragmentContainer', () => { // Name is excluded since value of cond is now false }, isMissingData: false, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, seenRecords: expect.any(Object), diff --git a/packages/react-relay/__tests__/ReactRelayPaginationContainer-test.js b/packages/react-relay/__tests__/ReactRelayPaginationContainer-test.js index 19f60ef692c7d..e9b9a660f8666 100644 --- a/packages/react-relay/__tests__/ReactRelayPaginationContainer-test.js +++ b/packages/react-relay/__tests__/ReactRelayPaginationContainer-test.js @@ -343,7 +343,7 @@ describe('ReactRelayPaginationContainer', () => { expect(environment.subscribe.mock.calls[0][0]).toEqual({ data: expect.any(Object), isMissingData: false, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, seenRecords: expect.any(Object), @@ -456,7 +456,7 @@ describe('ReactRelayPaginationContainer', () => { expect(environment.subscribe.mock.calls[0][0]).toEqual({ data: expect.any(Object), isMissingData: false, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, seenRecords: expect.any(Object), @@ -525,7 +525,7 @@ describe('ReactRelayPaginationContainer', () => { expect(environment.subscribe.mock.calls[0][0]).toEqual({ data: expect.any(Object), isMissingData: false, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, seenRecords: expect.any(Object), @@ -629,7 +629,7 @@ describe('ReactRelayPaginationContainer', () => { expect(environment.subscribe.mock.calls[0][0]).toEqual({ data: expect.any(Object), isMissingData: false, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, seenRecords: expect.any(Object), diff --git a/packages/react-relay/__tests__/ReactRelayRefetchContainer-test.js b/packages/react-relay/__tests__/ReactRelayRefetchContainer-test.js index 56b2ceb8a3a13..190e18a5cf420 100644 --- a/packages/react-relay/__tests__/ReactRelayRefetchContainer-test.js +++ b/packages/react-relay/__tests__/ReactRelayRefetchContainer-test.js @@ -279,7 +279,7 @@ describe('ReactRelayRefetchContainer', () => { name: 'Zuck', }, isMissingData: false, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, seenRecords: expect.any(Object), @@ -379,7 +379,7 @@ describe('ReactRelayRefetchContainer', () => { name: 'Joe', }, isMissingData: false, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, seenRecords: expect.any(Object), @@ -438,7 +438,7 @@ describe('ReactRelayRefetchContainer', () => { // Name is excluded since value of cond is now false }, isMissingData: false, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, seenRecords: expect.any(Object), @@ -524,7 +524,7 @@ describe('ReactRelayRefetchContainer', () => { id: '4', // Name is excluded since value of cond is now false }, - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, isMissingData: false, diff --git a/packages/react-relay/__tests__/RelayResolverNullableModelClientEdge-test.js b/packages/react-relay/__tests__/RelayResolverNullableModelClientEdge-test.js index 294e3e96c534a..5fc665c05750c 100644 --- a/packages/react-relay/__tests__/RelayResolverNullableModelClientEdge-test.js +++ b/packages/react-relay/__tests__/RelayResolverNullableModelClientEdge-test.js @@ -493,7 +493,7 @@ test('Errors thrown when reading the model a client edge points to are caught as {}, ); const snapshot = environment.lookup(operation.fragment); - expect(snapshot.errorResponseFields).toEqual([ + expect(snapshot.fieldErrors).toEqual([ { error: Error(ERROR_MESSAGE), owner: 'RelayResolverNullableModelClientEdgeTest_ErrorModel_Query', @@ -519,7 +519,7 @@ test('Errors thrown when reading plural client edge are caught as resolver error {}, ); const snapshot = environment.lookup(operation.fragment); - expect(snapshot.errorResponseFields).toEqual([ + expect(snapshot.fieldErrors).toEqual([ { error: Error(ERROR_MESSAGE), owner: 'RelayResolverNullableModelClientEdgeTest_PluralErrorModel_Query', @@ -553,7 +553,7 @@ test('Errors thrown when reading plural client edge are caught as resolver error {}, ); const snapshot = environment.lookup(operation.fragment); - expect(snapshot.errorResponseFields).toEqual([ + expect(snapshot.fieldErrors).toEqual([ { error: Error(ERROR_MESSAGE), owner: diff --git a/packages/react-relay/relay-hooks/legacy/FragmentResource.js b/packages/react-relay/relay-hooks/legacy/FragmentResource.js index 4f4289db7cadf..00041c6331b68 100644 --- a/packages/react-relay/relay-hooks/legacy/FragmentResource.js +++ b/packages/react-relay/relay-hooks/legacy/FragmentResource.js @@ -558,13 +558,10 @@ class FragmentResourceImpl { _throwOrLogErrorsInSnapshot(snapshot: SingularOrPluralSnapshot) { if (Array.isArray(snapshot)) { snapshot.forEach(s => { - handlePotentialSnapshotErrors(this._environment, s.errorResponseFields); + handlePotentialSnapshotErrors(this._environment, s.fieldErrors); }); } else { - handlePotentialSnapshotErrors( - this._environment, - snapshot.errorResponseFields, - ); + handlePotentialSnapshotErrors(this._environment, snapshot.fieldErrors); } } @@ -763,7 +760,7 @@ class FragmentResourceImpl { missingLiveResolverFields: currentSnapshot.missingLiveResolverFields, seenRecords: currentSnapshot.seenRecords, selector: currentSnapshot.selector, - errorResponseFields: currentSnapshot.errorResponseFields, + fieldErrors: currentSnapshot.fieldErrors, }; if (updatedData !== renderData) { const result = getFragmentResult( diff --git a/packages/react-relay/relay-hooks/readFragmentInternal.js b/packages/react-relay/relay-hooks/readFragmentInternal.js index 4bde1922432ae..8c28ddf1ca0bf 100644 --- a/packages/react-relay/relay-hooks/readFragmentInternal.js +++ b/packages/react-relay/relay-hooks/readFragmentInternal.js @@ -83,13 +83,10 @@ function handlePotentialSnapshotErrorsForState( state: FragmentState, ): void { if (state.kind === 'singular') { - handlePotentialSnapshotErrors( - environment, - state.snapshot.errorResponseFields, - ); + handlePotentialSnapshotErrors(environment, state.snapshot.fieldErrors); } else if (state.kind === 'plural') { for (const snapshot of state.snapshots) { - handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields); + handlePotentialSnapshotErrors(environment, snapshot.fieldErrors); } } } diff --git a/packages/react-relay/relay-hooks/useFragmentInternal_CURRENT.js b/packages/react-relay/relay-hooks/useFragmentInternal_CURRENT.js index 5b8252dec4bef..4e7da2fb89fff 100644 --- a/packages/react-relay/relay-hooks/useFragmentInternal_CURRENT.js +++ b/packages/react-relay/relay-hooks/useFragmentInternal_CURRENT.js @@ -111,13 +111,10 @@ function handlePotentialSnapshotErrorsForState( state: FragmentState, ): void { if (state.kind === 'singular') { - handlePotentialSnapshotErrors( - environment, - state.snapshot.errorResponseFields, - ); + handlePotentialSnapshotErrors(environment, state.snapshot.fieldErrors); } else if (state.kind === 'plural') { for (const snapshot of state.snapshots) { - handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields); + handlePotentialSnapshotErrors(environment, snapshot.fieldErrors); } } } @@ -153,7 +150,7 @@ function handleMissedUpdates( missingLiveResolverFields: currentSnapshot.missingLiveResolverFields, seenRecords: currentSnapshot.seenRecords, selector: currentSnapshot.selector, - errorResponseFields: currentSnapshot.errorResponseFields, + fieldErrors: currentSnapshot.fieldErrors, }; return [ updatedData !== state.snapshot.data, @@ -177,7 +174,7 @@ function handleMissedUpdates( missingLiveResolverFields: currentSnapshot.missingLiveResolverFields, seenRecords: currentSnapshot.seenRecords, selector: currentSnapshot.selector, - errorResponseFields: currentSnapshot.errorResponseFields, + fieldErrors: currentSnapshot.fieldErrors, }; if (updatedData !== snapshot.data) { didMissUpdates = true; diff --git a/packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js b/packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js index 0a29b45f63e7a..2c5ad84db79aa 100644 --- a/packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +++ b/packages/react-relay/relay-hooks/useFragmentInternal_EXPERIMENTAL.js @@ -131,13 +131,10 @@ function handlePotentialSnapshotErrorsForState( state: FragmentState, ): void { if (state.kind === 'singular') { - handlePotentialSnapshotErrors( - environment, - state.snapshot.errorResponseFields, - ); + handlePotentialSnapshotErrors(environment, state.snapshot.fieldErrors); } else if (state.kind === 'plural') { for (const snapshot of state.snapshots) { - handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields); + handlePotentialSnapshotErrors(environment, snapshot.fieldErrors); } } } @@ -173,7 +170,7 @@ function handleMissedUpdates( missingLiveResolverFields: currentSnapshot.missingLiveResolverFields, seenRecords: currentSnapshot.seenRecords, selector: currentSnapshot.selector, - errorResponseFields: currentSnapshot.errorResponseFields, + fieldErrors: currentSnapshot.fieldErrors, }; return [ updatedData !== state.snapshot.data, @@ -199,7 +196,7 @@ function handleMissedUpdates( missingLiveResolverFields: currentSnapshot.missingLiveResolverFields, seenRecords: currentSnapshot.seenRecords, selector: currentSnapshot.selector, - errorResponseFields: currentSnapshot.errorResponseFields, + fieldErrors: currentSnapshot.fieldErrors, }; if (updatedData !== snapshot.data) { didMissUpdates = true; diff --git a/packages/relay-runtime/query/fetchQuery.js b/packages/relay-runtime/query/fetchQuery.js index ae2df100f9e19..c9b81917fd97f 100644 --- a/packages/relay-runtime/query/fetchQuery.js +++ b/packages/relay-runtime/query/fetchQuery.js @@ -138,7 +138,7 @@ function fetchQuery( const fetchPolicy = options?.fetchPolicy ?? 'network-only'; function readData(snapshot: Snapshot): TData { - handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields); + handlePotentialSnapshotErrors(environment, snapshot.fieldErrors); /* $FlowFixMe[incompatible-return] we assume readData returns the right * data just having written it from network or checked availability. */ return snapshot.data; diff --git a/packages/relay-runtime/store/RelayModernFragmentSpecResolver.js b/packages/relay-runtime/store/RelayModernFragmentSpecResolver.js index b2acf3590d314..5354a2cfcb004 100644 --- a/packages/relay-runtime/store/RelayModernFragmentSpecResolver.js +++ b/packages/relay-runtime/store/RelayModernFragmentSpecResolver.js @@ -14,7 +14,7 @@ import type {ConcreteRequest} from '../util/RelayConcreteNode'; import type {Disposable, Variables} from '../util/RelayRuntimeTypes'; import type { - ErrorResponseFields, + FieldErrors, FragmentMap, FragmentSpecResolver, FragmentSpecResults, @@ -228,7 +228,7 @@ class SelectorResolver { _data: ?SelectorData; _environment: IEnvironment; _isMissingData: boolean; - _errorResponseFields: ?ErrorResponseFields; + _fieldErrors: ?FieldErrors; _rootIsQueryRenderer: boolean; _selector: SingularReaderSelector; _subscription: ?Disposable; @@ -244,7 +244,7 @@ class SelectorResolver { this._callback = callback; this._data = snapshot.data; this._isMissingData = snapshot.isMissingData; - this._errorResponseFields = snapshot.errorResponseFields; + this._fieldErrors = snapshot.fieldErrors; this._environment = environment; this._rootIsQueryRenderer = rootIsQueryRenderer; this._selector = selector; @@ -325,7 +325,7 @@ class SelectorResolver { } } } - handlePotentialSnapshotErrors(this._environment, this._errorResponseFields); + handlePotentialSnapshotErrors(this._environment, this._fieldErrors); return this._data; } @@ -340,7 +340,7 @@ class SelectorResolver { const snapshot = this._environment.lookup(selector); this._data = recycleNodesInto(this._data, snapshot.data); this._isMissingData = snapshot.isMissingData; - this._errorResponseFields = snapshot.errorResponseFields; + this._fieldErrors = snapshot.fieldErrors; this._selector = selector; this._subscription = this._environment.subscribe(snapshot, this._onChange); } @@ -376,7 +376,7 @@ class SelectorResolver { _onChange = (snapshot: Snapshot): void => { this._data = snapshot.data; this._isMissingData = snapshot.isMissingData; - this._errorResponseFields = snapshot.errorResponseFields; + this._fieldErrors = snapshot.fieldErrors; this._callback(); }; } diff --git a/packages/relay-runtime/store/RelayReader.js b/packages/relay-runtime/store/RelayReader.js index b2b42d351d698..5a0f03732824a 100644 --- a/packages/relay-runtime/store/RelayReader.js +++ b/packages/relay-runtime/store/RelayReader.js @@ -35,8 +35,8 @@ import type {DataID, Variables} from '../util/RelayRuntimeTypes'; import type { ClientEdgeTraversalInfo, DataIDSet, - ErrorResponseField, - ErrorResponseFields, + FieldError, + FieldErrors, MissingClientEdgeRequestInfo, Record, RecordSource, @@ -99,7 +99,7 @@ class RelayReader { _missingClientEdges: Array; _missingLiveResolverFields: Array; _isWithinUnmatchedTypeRefinement: boolean; - _errorResponseFields: ?ErrorResponseFields; + _fieldErrors: ?FieldErrors; _owner: RequestDescriptor; // Exec time resolvers are run before reaching the Relay store so the store already contains // the normalized data; the same as if the data were sent from the server. However, since a @@ -129,7 +129,7 @@ class RelayReader { this._missingLiveResolverFields = []; this._isMissingData = false; this._isWithinUnmatchedTypeRefinement = false; - this._errorResponseFields = null; + this._fieldErrors = null; this._owner = selector.owner; this._useExecTimeResolvers = this._owner.node.operation.use_exec_time_resolvers ?? false; @@ -206,11 +206,11 @@ class RelayReader { missingLiveResolverFields: this._missingLiveResolverFields, seenRecords: this._seenRecords, selector: this._selector, - errorResponseFields: this._errorResponseFields, + fieldErrors: this._fieldErrors, }; } - _maybeAddErrorResponseFields(record: Record, storageKey: string): void { + _maybeAddFieldErrors(record: Record, storageKey: string): void { const errors = RelayModernRecord.getErrors(record, storageKey); if (errors == null) { @@ -218,11 +218,11 @@ class RelayReader { } const owner = this._fragmentName; - if (this._errorResponseFields == null) { - this._errorResponseFields = []; + if (this._fieldErrors == null) { + this._fieldErrors = []; } for (const error of errors) { - this._errorResponseFields.push({ + this._fieldErrors.push({ kind: 'relay_field_payload.error', owner, fieldPath: (error.path ?? []).join('.'), @@ -237,14 +237,14 @@ class RelayReader { if (this._isWithinUnmatchedTypeRefinement) { return; } - if (this._errorResponseFields == null) { - this._errorResponseFields = []; + if (this._fieldErrors == null) { + this._fieldErrors = []; } // we will add the path later const owner = this._fragmentName; - this._errorResponseFields.push( + this._fieldErrors.push( this._selector.node.metadata?.throwOnFieldError ?? false ? { kind: 'missing_expected_data.throw', @@ -309,8 +309,8 @@ class RelayReader { } const owner = this._fragmentName; - if (this._errorResponseFields == null) { - this._errorResponseFields = []; + if (this._fieldErrors == null) { + this._fieldErrors = []; } let fieldName: string; @@ -323,7 +323,7 @@ class RelayReader { switch (selection.action) { case 'THROW': - this._errorResponseFields.push({ + this._fieldErrors.push({ kind: 'missing_required_field.throw', fieldPath: fieldName, owner, @@ -331,7 +331,7 @@ class RelayReader { }); return; case 'LOG': - this._errorResponseFields.push({ + this._fieldErrors.push({ kind: 'missing_required_field.log', fieldPath: fieldName, owner, @@ -362,7 +362,7 @@ class RelayReader { * any fields within them. * * 1. Before traversing into the selection(s) marked as `@catch`, the caller - * stores the previous field errors (`this._errorResponseFields`) in a + * stores the previous field errors (`this._fieldErrors`) in a * variable. * 2. After traversing into the selection(s) marked as `@catch`, the caller * calls this method with the resulting value, the `to` value from the @@ -377,7 +377,7 @@ class RelayReader { _catchErrors( _value: T, to: CatchFieldTo, - previousResponseFields: ?ErrorResponseFields, + previousResponseFields: ?FieldErrors, ): ?T | Result { let value: T | null | Result = _value; switch (to) { @@ -385,10 +385,7 @@ class RelayReader { value = this._asResult(_value); break; case 'NULL': - if ( - this._errorResponseFields != null && - this._errorResponseFields.length > 0 - ) { + if (this._fieldErrors != null && this._fieldErrors.length > 0) { value = null; } break; @@ -396,22 +393,22 @@ class RelayReader { (to: empty); } - const childrenErrorResponseFields = this._errorResponseFields; + const childrenFieldErrors = this._fieldErrors; - this._errorResponseFields = previousResponseFields; + this._fieldErrors = previousResponseFields; // Merge any errors encountered within the @catch with the previous field // errors, but mark them as "handled" first. - if (childrenErrorResponseFields != null) { - if (this._errorResponseFields == null) { - this._errorResponseFields = []; + if (childrenFieldErrors != null) { + if (this._fieldErrors == null) { + this._fieldErrors = []; } - for (let i = 0; i < childrenErrorResponseFields.length; i++) { + for (let i = 0; i < childrenFieldErrors.length; i++) { // We mark any errors encountered within the @catch as "handled" // to ensure that they don't cause the reader to throw, but can // still be logged. - this._errorResponseFields.push( - markFieldErrorHasHandled(childrenErrorResponseFields[i]), + this._fieldErrors.push( + markFieldErrorHasHandled(childrenFieldErrors[i]), ); } } @@ -420,21 +417,18 @@ class RelayReader { /** * Convert a value into a Result object based on the presence of errors in the - * `this._errorResponseFields` array. + * `this._fieldErrors` array. * * **Note**: This method does _not_ mark errors as handled. It is the caller's * responsibility to ensure that errors are marked as handled. */ _asResult(value: T): Result { - if ( - this._errorResponseFields == null || - this._errorResponseFields.length === 0 - ) { + if (this._fieldErrors == null || this._fieldErrors.length === 0) { return {ok: true, value}; } // TODO: Should we be hiding log level events here? - const errors = this._errorResponseFields + const errors = this._fieldErrors .map(error => { switch (error.kind) { case 'relay_field_payload.error': @@ -462,7 +456,7 @@ class RelayReader { (error.kind: empty); invariant( false, - 'Unexpected error errorResponseField kind: %s', + 'Unexpected error fieldError kind: %s', error.kind, ); } @@ -492,9 +486,9 @@ class RelayReader { } break; case 'CatchField': { - const previousResponseFields = this._errorResponseFields; + const previousResponseFields = this._fieldErrors; - this._errorResponseFields = null; + this._fieldErrors = null; const catchFieldValue = this._readClientSideDirectiveField( selection, @@ -688,8 +682,8 @@ class RelayReader { data: SelectorData, ): mixed { const parentRecordID = RelayModernRecord.getDataID(record); - const prevErrors = this._errorResponseFields; - this._errorResponseFields = null; + const prevErrors = this._fieldErrors; + this._fieldErrors = null; const result = this._readResolverFieldImpl(field, parentRecordID); const fieldName = field.alias ?? field.name; @@ -727,7 +721,7 @@ class RelayReader { return { data: snapshot.data, isMissingData: snapshot.isMissingData, - errorResponseFields: snapshot.errorResponseFields, + fieldErrors: snapshot.fieldErrors, }; } @@ -740,7 +734,7 @@ class RelayReader { return { data: snapshot.data, isMissingData: snapshot.isMissingData, - errorResponseFields: snapshot.errorResponseFields, + fieldErrors: snapshot.fieldErrors, }; }; @@ -838,23 +832,23 @@ class RelayReader { this._missingLiveResolverFields.push(missingResolverField); } } - if (cachedSnapshot.errorResponseFields != null) { - if (this._errorResponseFields == null) { - this._errorResponseFields = []; + if (cachedSnapshot.fieldErrors != null) { + if (this._fieldErrors == null) { + this._fieldErrors = []; } - for (const error of cachedSnapshot.errorResponseFields) { + for (const error of cachedSnapshot.fieldErrors) { if (this._selector.node.metadata?.throwOnFieldError === true) { // If this fragment is @throwOnFieldError, any destructive error // encountered inside a resolver's fragment is equivilent to the // resolver field having a field error, and we want that to cause this // fragment to throw. So, we propagate all errors as is. - this._errorResponseFields.push(error); + this._fieldErrors.push(error); } else { // If this fragment is _not_ @throwOnFieldError, we will simply // accept that any destructive errors encountered in the resolver's // root fragment will cause the resolver to return null, and well // pass the errors along to the logger marked as "handled". - this._errorResponseFields.push(markFieldErrorHasHandled(error)); + this._fieldErrors.push(markFieldErrorHasHandled(error)); } } } @@ -873,10 +867,10 @@ class RelayReader { shouldThrow: this._selector.node.metadata?.throwOnFieldError ?? false, handled: false, }; - if (this._errorResponseFields == null) { - this._errorResponseFields = [errorEvent]; + if (this._fieldErrors == null) { + this._fieldErrors = [errorEvent]; } else { - this._errorResponseFields.push(errorEvent); + this._fieldErrors.push(errorEvent); } } @@ -1069,8 +1063,8 @@ class RelayReader { RelayModernRecord.getDataID(record), prevData, ); - const prevErrors = this._errorResponseFields; - this._errorResponseFields = null; + const prevErrors = this._fieldErrors; + this._fieldErrors = null; const edgeValue = this._traverse( field.linkedField, storeID, @@ -1098,7 +1092,7 @@ class RelayReader { Array.isArray(value) && value.length === 0) ) { - this._maybeAddErrorResponseFields(record, storageKey); + this._maybeAddFieldErrors(record, storageKey); } else if (value === undefined) { this._markDataAsMissing(fieldName); } @@ -1117,7 +1111,7 @@ class RelayReader { if (linkedID == null) { data[fieldName] = linkedID; if (linkedID === null) { - this._maybeAddErrorResponseFields(record, storageKey); + this._maybeAddFieldErrors(record, storageKey); } else if (linkedID === undefined) { this._markDataAsMissing(fieldName); } @@ -1134,8 +1128,8 @@ class RelayReader { RelayModernRecord.getDataID(record), prevData, ); - const prevErrors = this._errorResponseFields; - this._errorResponseFields = null; + const prevErrors = this._fieldErrors; + this._fieldErrors = null; // $FlowFixMe[incompatible-variance] const value = this._traverse(field, linkedID, prevData); @@ -1145,7 +1139,7 @@ class RelayReader { } /** - * Adds a set of field errors to `this._errorResponseFields`, ensuring the + * Adds a set of field errors to `this._fieldErrors`, ensuring the * `fieldPath` property of existing field errors are prefixed with the given * `fieldNameOrIndex`. * @@ -1164,8 +1158,8 @@ class RelayReader { * To achieve this, named field readers must do the following to correctly * track error filePaths: * - * 1. Stash the value of `this._errorResponseFields` in a local variable - * 2. Set `this._errorResponseFields` to `null` + * 1. Stash the value of `this._fieldErrors` in a local variable + * 2. Set `this._fieldErrors` to `null` * 3. Traverse into the field * 4. Call this method with the stashed errors and the field's name * @@ -1177,12 +1171,12 @@ class RelayReader { * field error paths. */ _prependPreviousErrors( - prevErrors: ?Array, + prevErrors: ?Array, fieldNameOrIndex: string | number, ): void { - if (this._errorResponseFields != null) { - for (let i = 0; i < this._errorResponseFields.length; i++) { - const event = this._errorResponseFields[i]; + if (this._fieldErrors != null) { + for (let i = 0; i < this._fieldErrors.length; i++) { + const event = this._fieldErrors[i]; if ( event.owner === this._fragmentName && (event.kind === 'missing_expected_data.throw' || @@ -1194,13 +1188,13 @@ class RelayReader { } } if (prevErrors != null) { - for (let i = this._errorResponseFields.length - 1; i >= 0; i--) { - prevErrors.push(this._errorResponseFields[i]); + for (let i = this._fieldErrors.length - 1; i >= 0; i--) { + prevErrors.push(this._fieldErrors[i]); } - this._errorResponseFields = prevErrors; + this._fieldErrors = prevErrors; } } else { - this._errorResponseFields = prevErrors; + this._fieldErrors = prevErrors; } } @@ -1221,7 +1215,7 @@ class RelayReader { if (externalRef === undefined) { this._markDataAsMissing(fieldName); } else if (externalRef === null) { - this._maybeAddErrorResponseFields(record, storageKey); + this._maybeAddFieldErrors(record, storageKey); } return data[fieldName]; } @@ -1255,7 +1249,7 @@ class RelayReader { Array.isArray(linkedIDs) && linkedIDs.length === 0) ) { - this._maybeAddErrorResponseFields(record, storageKey); + this._maybeAddFieldErrors(record, storageKey); } return this._readLinkedIds(field, linkedIDs, record, data); } @@ -1285,8 +1279,8 @@ class RelayReader { RelayModernRecord.getDataID(record), prevData, ); - const prevErrors = this._errorResponseFields; - this._errorResponseFields = null; + const prevErrors = this._fieldErrors; + this._fieldErrors = null; const linkedArray = prevData || []; linkedIDs.forEach((linkedID, nextIndex) => { if (linkedID == null) { @@ -1306,8 +1300,8 @@ class RelayReader { RelayModernRecord.getDataID(record), prevItem, ); - const prevErrors = this._errorResponseFields; - this._errorResponseFields = null; + const prevErrors = this._fieldErrors; + this._fieldErrors = null; // $FlowFixMe[cannot-write] // $FlowFixMe[incompatible-variance] linkedArray[nextIndex] = this._traverse(field, linkedID, prevItem); @@ -1377,8 +1371,8 @@ class RelayReader { record: Record, data: SelectorData, ) { - const prevErrors = this._errorResponseFields; - this._errorResponseFields = null; + const prevErrors = this._fieldErrors; + this._fieldErrors = null; let fieldValue = this._readInlineFragment( aliasedInlineFragment.fragment, record, @@ -1608,9 +1602,7 @@ class RelayReader { } } -function markFieldErrorHasHandled( - event: ErrorResponseField, -): ErrorResponseField { +function markFieldErrorHasHandled(event: FieldError): FieldError { switch (event.kind) { case 'missing_expected_data.throw': case 'missing_required_field.throw': diff --git a/packages/relay-runtime/store/RelayStoreSubscriptions.js b/packages/relay-runtime/store/RelayStoreSubscriptions.js index bfdd489656bb3..7957787c68cb9 100644 --- a/packages/relay-runtime/store/RelayStoreSubscriptions.js +++ b/packages/relay-runtime/store/RelayStoreSubscriptions.js @@ -115,7 +115,7 @@ class RelayStoreSubscriptions implements StoreSubscriptions { missingLiveResolverFields: backup.missingLiveResolverFields, seenRecords: backup.seenRecords, selector: backup.selector, - errorResponseFields: backup.errorResponseFields, + fieldErrors: backup.fieldErrors, }; } else { // This subscription was created during the optimisitic state. We should @@ -185,7 +185,7 @@ class RelayStoreSubscriptions implements StoreSubscriptions { missingLiveResolverFields: nextSnapshot.missingLiveResolverFields, seenRecords: nextSnapshot.seenRecords, selector: nextSnapshot.selector, - errorResponseFields: nextSnapshot.errorResponseFields, + fieldErrors: nextSnapshot.fieldErrors, }: Snapshot); if (__DEV__) { deepFreeze(nextSnapshot); diff --git a/packages/relay-runtime/store/RelayStoreTypes.js b/packages/relay-runtime/store/RelayStoreTypes.js index b0f500d05da9e..bb0f0497862fd 100644 --- a/packages/relay-runtime/store/RelayStoreTypes.js +++ b/packages/relay-runtime/store/RelayStoreTypes.js @@ -116,7 +116,7 @@ export type NormalizationSelector = { +variables: Variables, }; -export type ErrorResponseField = +export type FieldError = | RelayFieldPayloadErrorEvent | MissingExpectedDataLogEvent | MissingExpectedDataThrowEvent @@ -124,7 +124,7 @@ export type ErrorResponseField = | MissingRequiredFieldLogEvent | MissingRequiredFieldThrowEvent; -export type ErrorResponseFields = Array; +export type FieldErrors = Array; export type ClientEdgeTraversalInfo = { +readerClientEdge: ReaderClientEdgeToServerObject, @@ -149,7 +149,7 @@ export type Snapshot = { +missingClientEdges: null | $ReadOnlyArray, +seenRecords: DataIDSet, +selector: SingularReaderSelector, - +errorResponseFields: ?ErrorResponseFields, + +fieldErrors: ?FieldErrors, }; /** diff --git a/packages/relay-runtime/store/ResolverCache.js b/packages/relay-runtime/store/ResolverCache.js index 91b2b1101adc0..1d2f00243a957 100644 --- a/packages/relay-runtime/store/ResolverCache.js +++ b/packages/relay-runtime/store/ResolverCache.js @@ -18,7 +18,7 @@ import type { import type {DataID, Variables} from '../util/RelayRuntimeTypes'; import type { DataIDSet, - ErrorResponseFields, + FieldErrors, SingularReaderSelector, Snapshot, } from './RelayStoreTypes'; @@ -35,7 +35,7 @@ export type EvaluationResult = { export type ResolverFragmentResult = { data: mixed, isMissingData: boolean, - errorResponseFields: ?ErrorResponseFields, + fieldErrors: ?FieldErrors, }; export type GetDataForResolverFragmentFn = diff --git a/packages/relay-runtime/store/ResolverFragments.js b/packages/relay-runtime/store/ResolverFragments.js index 9e1256533f12b..a55c224314884 100644 --- a/packages/relay-runtime/store/ResolverFragments.js +++ b/packages/relay-runtime/store/ResolverFragments.js @@ -112,12 +112,14 @@ function readFragment( fragmentSelector.kind === 'SingularReaderSelector', `Expected a singular reader selector for the fragment of the resolver ${fragmentNode.name}, but it was plural.`, ); - const {data, isMissingData, errorResponseFields} = - context.getDataForResolverFragment(fragmentSelector, fragmentKey); + const {data, isMissingData, fieldErrors} = context.getDataForResolverFragment( + fragmentSelector, + fragmentKey, + ); if ( isMissingData || - (errorResponseFields != null && errorResponseFields.some(eventShouldThrow)) + (fieldErrors != null && fieldErrors.some(eventShouldThrow)) ) { throw RESOLVER_FRAGMENT_ERRORED_SENTINEL; } diff --git a/packages/relay-runtime/store/__tests__/RelayModernEnvironment-ConnectionAndRequired-test.js b/packages/relay-runtime/store/__tests__/RelayModernEnvironment-ConnectionAndRequired-test.js index d1a8a0664ed64..e31c2c872d64a 100644 --- a/packages/relay-runtime/store/__tests__/RelayModernEnvironment-ConnectionAndRequired-test.js +++ b/packages/relay-runtime/store/__tests__/RelayModernEnvironment-ConnectionAndRequired-test.js @@ -130,7 +130,7 @@ describe.each(['RelayModernEnvironment', 'MultiActorEnvironment'])( getSingularSelector(fragment, nextOperationSnapshot.data?.node), ); const snapshot = environment.lookup(selector); - expect(snapshot.errorResponseFields).toEqual([ + expect(snapshot.fieldErrors).toEqual([ { kind: 'missing_required_field.log', owner: diff --git a/packages/relay-runtime/store/__tests__/RelayModernEnvironment-ExecuteWithStreamAndRequired-test.js b/packages/relay-runtime/store/__tests__/RelayModernEnvironment-ExecuteWithStreamAndRequired-test.js index 52b81726d03d9..6e2ce966fdb5f 100644 --- a/packages/relay-runtime/store/__tests__/RelayModernEnvironment-ExecuteWithStreamAndRequired-test.js +++ b/packages/relay-runtime/store/__tests__/RelayModernEnvironment-ExecuteWithStreamAndRequired-test.js @@ -111,7 +111,7 @@ describe('execute() a query with @stream and @required', () => { jest.runAllTimers(); const snapshot = callback.mock.calls[0][0]; - expect(snapshot.errorResponseFields).toEqual([ + expect(snapshot.fieldErrors).toEqual([ { kind: 'missing_required_field.log', owner: diff --git a/packages/relay-runtime/store/__tests__/RelayModernStore-Subscriptions-test.js b/packages/relay-runtime/store/__tests__/RelayModernStore-Subscriptions-test.js index 67f27036848b8..ee54a39cbc2db 100644 --- a/packages/relay-runtime/store/__tests__/RelayModernStore-Subscriptions-test.js +++ b/packages/relay-runtime/store/__tests__/RelayModernStore-Subscriptions-test.js @@ -371,7 +371,7 @@ function cloneEventWithSets(event: LogEvent) { ...snapshot, missingLiveResolverFields: [], isMissingData: false, - errorResponseFields: null, + fieldErrors: null, data: { name: 'Zuck', profilePicture: { @@ -415,7 +415,7 @@ function cloneEventWithSets(event: LogEvent) { }, missingLiveResolverFields: [], isMissingData: true, - errorResponseFields: [ + fieldErrors: [ { fieldPath: 'profilePicture', kind: 'missing_expected_data.log', @@ -464,7 +464,7 @@ function cloneEventWithSets(event: LogEvent) { name: 'Joe', profilePicture: undefined, }, - errorResponseFields: [ + fieldErrors: [ { fieldPath: 'profilePicture', kind: 'missing_expected_data.log', diff --git a/packages/relay-runtime/store/__tests__/RelayModernStore-test.js b/packages/relay-runtime/store/__tests__/RelayModernStore-test.js index c7987874d397c..22ca3916de72d 100644 --- a/packages/relay-runtime/store/__tests__/RelayModernStore-test.js +++ b/packages/relay-runtime/store/__tests__/RelayModernStore-test.js @@ -295,7 +295,7 @@ function cloneEventWithSets(event: LogEvent) { }, }, seenRecords: new Set(Object.keys(data)), - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, isMissingData: false, @@ -348,7 +348,7 @@ function cloneEventWithSets(event: LogEvent) { __fragmentOwner: owner.request, }, seenRecords: new Set(Object.keys(data)), - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, isMissingData: false, @@ -405,7 +405,7 @@ function cloneEventWithSets(event: LogEvent) { }, }, seenRecords: new Set(['client:2', '4']), - errorResponseFields: null, + fieldErrors: null, missingLiveResolverFields: [], missingClientEdges: null, isMissingData: false, @@ -693,7 +693,7 @@ function cloneEventWithSets(event: LogEvent) { ...snapshot, missingClientEdges: null, isMissingData: false, - errorResponseFields: null, + fieldErrors: null, data: { name: 'Zuck', profilePicture: { @@ -735,7 +735,7 @@ function cloneEventWithSets(event: LogEvent) { name: 'Joe', profilePicture: undefined, }, - errorResponseFields: [ + fieldErrors: [ { owner: 'RelayModernStoreTest5Fragment', kind: 'missing_expected_data.log', @@ -789,7 +789,7 @@ function cloneEventWithSets(event: LogEvent) { }, missingClientEdges: null, isMissingData: true, - errorResponseFields: [ + fieldErrors: [ { owner: 'RelayModernStoreTest5Fragment', kind: 'missing_expected_data.log', diff --git a/packages/relay-runtime/store/__tests__/RelayReader-AliasedFragments-test.js b/packages/relay-runtime/store/__tests__/RelayReader-AliasedFragments-test.js index 6395068654d58..a8deb79f329e0 100644 --- a/packages/relay-runtime/store/__tests__/RelayReader-AliasedFragments-test.js +++ b/packages/relay-runtime/store/__tests__/RelayReader-AliasedFragments-test.js @@ -906,8 +906,8 @@ describe('Inline Fragments', () => { `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); const snapshot = read(source, operation.fragment); - const {data, isMissingData, errorResponseFields} = snapshot; - expect(errorResponseFields).toBe(null); + const {data, isMissingData, fieldErrors} = snapshot; + expect(fieldErrors).toBe(null); expect(isMissingData).toBe(false); expect(data).toEqual({ node: { @@ -1035,11 +1035,8 @@ describe('Inline Fragments', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, isMissingData, errorResponseFields} = read( - source, - operation.fragment, - ); - expect(errorResponseFields).toEqual([ + const {data, isMissingData, fieldErrors} = read(source, operation.fragment); + expect(fieldErrors).toEqual([ { fieldPath: 'node.aliased_fragment.name', kind: 'missing_expected_data.log', @@ -1095,11 +1092,8 @@ describe('Inline Fragments', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, isMissingData, errorResponseFields} = read( - source, - operation.fragment, - ); - expect(errorResponseFields).toEqual([ + const {data, isMissingData, fieldErrors} = read(source, operation.fragment); + expect(fieldErrors).toEqual([ { fieldPath: 'node.aliased_fragment.', kind: 'missing_expected_data.log', diff --git a/packages/relay-runtime/store/__tests__/RelayReader-CatchFields-test.js b/packages/relay-runtime/store/__tests__/RelayReader-CatchFields-test.js index 2ec131d0ccde0..1e01dbc783e26 100644 --- a/packages/relay-runtime/store/__tests__/RelayReader-CatchFields-test.js +++ b/packages/relay-runtime/store/__tests__/RelayReader-CatchFields-test.js @@ -41,8 +41,8 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); - expect(errorResponseFields).toEqual(null); + const {data, fieldErrors} = read(source, operation.fragment); + expect(fieldErrors).toEqual(null); expect(data).toEqual({me: {lastName: null}}); }); @@ -77,7 +77,7 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual({ me: { lastName: { @@ -91,7 +91,7 @@ describe('RelayReader @catch', () => { }, }); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { error: {message: 'There was an error!', path: ['me', 'lastName']}, fieldPath: 'me.lastName', @@ -136,7 +136,7 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual({ me: { lastName: null, @@ -147,7 +147,7 @@ describe('RelayReader @catch', () => { }, }); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.lastName', error: { @@ -191,7 +191,7 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual({ alsoMe: null, me: { @@ -205,7 +205,7 @@ describe('RelayReader @catch', () => { }, }); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { kind: 'missing_required_field.log', fieldPath: 'alsoMe.lastName', @@ -243,12 +243,12 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual({ me: null, }); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.firstName', handled: true, @@ -281,17 +281,14 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields, isMissingData} = read( - source, - operation.fragment, - ); + const {data, fieldErrors, isMissingData} = read(source, operation.fragment); expect(data).toEqual({me: null}); // We still need to ensure that we will suspend if there is a request in flight. expect(isMissingData).toEqual(true); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.firstName', kind: 'missing_expected_data.log', @@ -324,17 +321,14 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {data, errorResponseFields, isMissingData} = read( - source, - operation.fragment, - ); + const {data, fieldErrors, isMissingData} = read(source, operation.fragment); expect(data).toEqual(null); // We still need to ensure that we will suspend if there is a request in flight. expect(isMissingData).toEqual(true); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.firstName', kind: 'missing_expected_data.log', @@ -367,17 +361,14 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {data, errorResponseFields, isMissingData} = read( - source, - operation.fragment, - ); + const {data, fieldErrors, isMissingData} = read(source, operation.fragment); expect(data).toEqual({errors: [{path: ['me', 'firstName']}], ok: false}); // We still need to ensure that we will suspend if there is a request in flight. expect(isMissingData).toEqual(true); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.firstName', kind: 'missing_expected_data.log', @@ -417,7 +408,7 @@ describe('RelayReader @catch', () => { `; const owner = createOperationDescriptor(FooQuery, {}); - const {data, errorResponseFields, isMissingData} = read( + const {data, fieldErrors, isMissingData} = read( source, createReaderSelector(FooFragment, 'client:root', {}, owner.request), ); @@ -427,7 +418,7 @@ describe('RelayReader @catch', () => { // We still need to ensure that we will suspend if there is a request in flight. expect(isMissingData).toEqual(true); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.firstName', kind: 'missing_expected_data.log', @@ -465,7 +456,7 @@ describe('RelayReader @catch', () => { `; const owner = createOperationDescriptor(FooQuery, {}); - const {data, errorResponseFields, isMissingData} = read( + const {data, fieldErrors, isMissingData} = read( source, createReaderSelector(FooFragment, 'client:root', {}, owner.request), ); @@ -475,7 +466,7 @@ describe('RelayReader @catch', () => { // We still need to ensure that we will suspend if there is a request in flight. expect(isMissingData).toEqual(true); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.firstName', kind: 'missing_expected_data.log', @@ -509,17 +500,14 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {data, errorResponseFields, isMissingData} = read( - source, - operation.fragment, - ); + const {data, fieldErrors, isMissingData} = read(source, operation.fragment); expect(data).toEqual({me: {myAlias: null}}); // We still need to ensure that we will suspend if there is a request in flight. expect(isMissingData).toEqual(true); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.myAlias.firstName', kind: 'missing_expected_data.log', @@ -554,10 +542,7 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {data, errorResponseFields, isMissingData} = read( - source, - operation.fragment, - ); + const {data, fieldErrors, isMissingData} = read(source, operation.fragment); expect(data).toEqual({ me: {myAlias: {ok: false, errors: [{path: ['myAlias', 'firstName']}]}}, @@ -566,7 +551,7 @@ describe('RelayReader @catch', () => { // We still need to ensure that we will suspend if there is a request in flight. expect(isMissingData).toEqual(true); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.myAlias.firstName', kind: 'missing_expected_data.log', @@ -599,7 +584,7 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual({ me: { lastName: { @@ -609,7 +594,7 @@ describe('RelayReader @catch', () => { }, }); - expect(errorResponseFields).toBeNull(); + expect(fieldErrors).toBeNull(); }); it('if linked has catch to RESULT - but no error, response should reflect', () => { @@ -635,7 +620,7 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual({ me: { ok: true, @@ -645,7 +630,7 @@ describe('RelayReader @catch', () => { }, }); - expect(errorResponseFields).toBeNull(); + expect(fieldErrors).toBeNull(); }); it('if linked has catch to RESULT - with error, response should reflect', () => { @@ -679,7 +664,7 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual({ me: { ok: false, @@ -691,7 +676,7 @@ describe('RelayReader @catch', () => { }, }); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { error: {message: 'There was an error!', path: ['me', 'lastName']}, fieldPath: 'me.lastName', @@ -726,7 +711,7 @@ describe('RelayReader @catch', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual({ me: { errors: [ @@ -739,7 +724,7 @@ describe('RelayReader @catch', () => { }, }); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.lastName', handled: true, diff --git a/packages/relay-runtime/store/__tests__/RelayReader-RelayErrorHandling-test.js b/packages/relay-runtime/store/__tests__/RelayReader-RelayErrorHandling-test.js index f4caaf94b801f..49ce8682c544c 100644 --- a/packages/relay-runtime/store/__tests__/RelayReader-RelayErrorHandling-test.js +++ b/packages/relay-runtime/store/__tests__/RelayReader-RelayErrorHandling-test.js @@ -20,7 +20,7 @@ const {read} = require('../RelayReader'); const RelayRecordSource = require('../RelayRecordSource'); describe('RelayReader error fields', () => { - it('adds the errors to errorResponseFields', () => { + it('adds the errors to fieldErrors', () => { const source = RelayRecordSource.create({ 'client:root': { __id: 'client:root', @@ -51,9 +51,9 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual({me: {lastName: null}}); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { owner: 'RelayReaderRelayErrorHandlingTest1Query', fieldPath: 'me.lastName', @@ -68,7 +68,7 @@ describe('RelayReader error fields', () => { ]); }); - it('adds the errors to errorResponseFields including missingData - without @catch', () => { + it('adds the errors to fieldErrors including missingData - without @catch', () => { const source = RelayRecordSource.create({ 'client:root': { __id: 'client:root', @@ -103,9 +103,9 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {size: 42}); - const {errorResponseFields} = read(source, operation.fragment); + const {fieldErrors} = read(source, operation.fragment); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { owner: 'RelayReaderRelayErrorHandlingTest4Query', fieldPath: 'me.lastName', @@ -126,7 +126,7 @@ describe('RelayReader error fields', () => { ]); }); - it('adds the errors to errorResponseFields including missingData within plural fields - without @catch', () => { + it('adds the errors to fieldErrors including missingData within plural fields - without @catch', () => { const source = RelayRecordSource.create({ 'client:root': { __id: 'client:root', @@ -161,9 +161,9 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {size: 42}); - const {errorResponseFields} = read(source, operation.fragment); + const {fieldErrors} = read(source, operation.fragment); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { owner: 'RelayReaderRelayErrorHandlingTestMissingPluralQuery', fieldPath: 'me.lastName', @@ -184,7 +184,7 @@ describe('RelayReader error fields', () => { ]); }); - it('adds the errors to errorResponseFields including missingData - with @catch', () => { + it('adds the errors to fieldErrors including missingData - with @catch', () => { const source = RelayRecordSource.create({ 'client:root': { __id: 'client:root', @@ -218,7 +218,7 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {size: 42}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); // we have a task out for adding path to missingData. Meantime that array is empty. expect(data).toEqual({ @@ -235,7 +235,7 @@ describe('RelayReader error fields', () => { }, }); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { error: {message: 'There was an error!', path: ['me', 'lastName']}, fieldPath: 'me.lastName', @@ -283,7 +283,7 @@ describe('RelayReader error fields', () => { `; const operation = createOperationDescriptor(FooQuery, {size: 42}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual({ me: { @@ -291,7 +291,7 @@ describe('RelayReader error fields', () => { }, }); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { error: {message: 'There was an error!', path: ['me', 'lastName']}, fieldPath: 'me.lastName', @@ -337,9 +337,9 @@ describe('RelayReader error fields', () => { `; const operation = createOperationDescriptor(FooQuery, {size: 42}); - const {errorResponseFields} = read(source, operation.fragment); + const {fieldErrors} = read(source, operation.fragment); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { error: {message: 'There was an error!', path: ['me', 'lastName']}, fieldPath: 'me.lastName', @@ -386,9 +386,9 @@ describe('RelayReader error fields', () => { `; const operation = createOperationDescriptor(FooQuery, {size: 42}); - const {errorResponseFields} = read(source, operation.fragment); + const {fieldErrors} = read(source, operation.fragment); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.client_edge.firstName', kind: 'missing_expected_data.throw', @@ -436,9 +436,9 @@ describe('RelayReader error fields', () => { `; const operation = createOperationDescriptor(FooQuery, {}); - const {errorResponseFields} = store.lookup(operation.fragment); + const {fieldErrors} = store.lookup(operation.fragment); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.astrological_sign.notes', kind: 'missing_expected_data.throw', @@ -473,9 +473,9 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {errorResponseFields} = store.lookup(operation.fragment); - for (let i = 0; i < errorResponseFields.length; i++) { - expect(errorResponseFields[i]).toEqual({ + const {fieldErrors} = store.lookup(operation.fragment); + for (let i = 0; i < fieldErrors.length; i++) { + expect(fieldErrors[i]).toEqual({ fieldPath: `all_astrological_signs.${i}.notes`, kind: 'missing_expected_data.throw', handled: true, @@ -515,13 +515,10 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {errorResponseFields, isMissingData} = read( - source, - operation.fragment, - ); + const {fieldErrors, isMissingData} = read(source, operation.fragment); expect(isMissingData).toBe(false); - expect(errorResponseFields).toEqual(null); + expect(fieldErrors).toEqual(null); }); it('does report missing data within an inline fragment that does match', () => { @@ -555,13 +552,10 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {errorResponseFields, isMissingData} = read( - source, - operation.fragment, - ); + const {fieldErrors, isMissingData} = read(source, operation.fragment); expect(isMissingData).toBe(true); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ // We are missing the metadata bout the interface { fieldPath: 'node.', @@ -611,13 +605,10 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {errorResponseFields, isMissingData} = read( - source, - operation.fragment, - ); + const {fieldErrors, isMissingData} = read(source, operation.fragment); expect(isMissingData).toBe(true); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'also_me.name', handled: false, @@ -705,9 +696,9 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {errorResponseFields} = read(source, operation.fragment); + const {fieldErrors} = read(source, operation.fragment); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: '', handled: false, @@ -755,9 +746,9 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {errorResponseFields} = read(source, operation.fragment); + const {fieldErrors} = read(source, operation.fragment); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: '', handled: false, @@ -819,10 +810,10 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data.node.friends.edges).toEqual([]); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: '', handled: false, @@ -869,9 +860,9 @@ describe('RelayReader error fields', () => { } `; const operation = createOperationDescriptor(FooQuery, {}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data.node.emailAddresses).toEqual([]); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: '', handled: false, diff --git a/packages/relay-runtime/store/__tests__/RelayReader-RequiredFields-test.js b/packages/relay-runtime/store/__tests__/RelayReader-RequiredFields-test.js index ecb1329695037..afce9652b2877 100644 --- a/packages/relay-runtime/store/__tests__/RelayReader-RequiredFields-test.js +++ b/packages/relay-runtime/store/__tests__/RelayReader-RequiredFields-test.js @@ -146,9 +146,9 @@ describe('RelayReader @required', () => { } `; const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read(source, operation.fragment); + const {data, fieldErrors} = read(source, operation.fragment); expect(data).toEqual(null); - expect(errorResponseFields[0].fieldPath).toBe('me.lastName'); + expect(fieldErrors[0].fieldPath).toBe('me.lastName'); }); it('bubbles @required(action: LOG) scalars up to LinkedField even if subsequent fields are not unexpectedly null', () => { @@ -896,7 +896,7 @@ describe('RelayReader @required', () => { const store = new RelayModernStore(source); const operation = createOperationDescriptor(FooQuery, {}); const resolverCache = new LiveResolverCache(() => source, store); - const {data, errorResponseFields} = read( + const {data, fieldErrors} = read( source, operation.fragment, resolverCache, @@ -913,7 +913,7 @@ describe('RelayReader @required', () => { }, }); // these are "handled" because the field with the required error was caught - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { fieldPath: 'me.client_object', handled: true, @@ -949,12 +949,8 @@ describe('RelayReader @required', () => { const store = new RelayModernStore(source); const operation = createOperationDescriptor(FooQuery, {}); const resolverCache = new LiveResolverCache(() => source, store); - const {errorResponseFields} = read( - source, - operation.fragment, - resolverCache, - ); - expect(errorResponseFields).toEqual([ + const {fieldErrors} = read(source, operation.fragment, resolverCache); + expect(fieldErrors).toEqual([ { fieldPath: 'me.client_object', kind: 'missing_required_field.throw', @@ -995,13 +991,13 @@ describe('RelayReader @required', () => { const store = new RelayModernStore(source); const operation = createOperationDescriptor(FooQuery, {}); const resolverCache = new LiveResolverCache(() => source, store); - const {data, errorResponseFields} = read( + const {data, fieldErrors} = read( source, operation.fragment, resolverCache, ); expect(data).toEqual({me: {astrological_sign: {name: 'Pisces'}}}); - expect(errorResponseFields).toBe(null); + expect(fieldErrors).toBe(null); }); test('does not throw when required plural field is present', () => { @@ -1028,13 +1024,13 @@ describe('RelayReader @required', () => { const store = new RelayModernStore(source); const operation = createOperationDescriptor(FooQuery, {}); const resolverCache = new LiveResolverCache(() => source, store); - const {data, errorResponseFields} = read( + const {data, fieldErrors} = read( source, operation.fragment, resolverCache, ); expect(data.all_astrological_signs.length).toBe(12); - expect(errorResponseFields).toBe(null); + expect(fieldErrors).toBe(null); }); test('does not throw when @live required field is suspended', () => { @@ -1057,7 +1053,7 @@ describe('RelayReader @required', () => { const operation = createOperationDescriptor(FooQuery, {}); const resolverCache = new LiveResolverCache(() => source, store); const snapshot = read(source, operation.fragment, resolverCache); - expect(snapshot.errorResponseFields).toEqual(null); + expect(snapshot.fieldErrors).toEqual(null); expect(snapshot.missingLiveResolverFields).toEqual([ `client:root:${RELAY_READ_TIME_RESOLVER_KEY_PREFIX}live_user_resolver_always_suspend`, ]); diff --git a/packages/relay-runtime/store/__tests__/RelayReader-Resolver-test.js b/packages/relay-runtime/store/__tests__/RelayReader-Resolver-test.js index d4bf281530d1a..d96dc698c3cc9 100644 --- a/packages/relay-runtime/store/__tests__/RelayReader-Resolver-test.js +++ b/packages/relay-runtime/store/__tests__/RelayReader-Resolver-test.js @@ -185,8 +185,8 @@ describe('Relay resolver - Field Error Handling', () => { const operation = createOperationDescriptor(FooQuery, {}); const store = new RelayStore(source, {gcReleaseBufferSize: 0}); - const {errorResponseFields} = store.lookup(operation.fragment); - expect(errorResponseFields).toEqual([ + const {fieldErrors} = store.lookup(operation.fragment); + expect(fieldErrors).toEqual([ { fieldPath: 'me.lastName', kind: 'relay_field_payload.error', @@ -223,8 +223,8 @@ it('propagates @required errors from the resolver up to the reader', () => { const operation = createOperationDescriptor(FooQuery, {}); const store = new RelayStore(source, {gcReleaseBufferSize: 0}); - const {errorResponseFields} = store.lookup(operation.fragment); - expect(errorResponseFields).toEqual([ + const {fieldErrors} = store.lookup(operation.fragment); + expect(fieldErrors).toEqual([ { kind: 'missing_required_field.log', owner: 'UserRequiredNameResolver', @@ -242,7 +242,7 @@ it('propagates @required errors from the resolver up to the reader', () => { // Lookup a second time to ensure that we still report the missing fields when // reading from the cache. - const {errorResponseFields: missingRequiredFieldsTakeTwo} = store.lookup( + const {fieldErrors: missingRequiredFieldsTakeTwo} = store.lookup( operation.fragment, ); @@ -322,8 +322,8 @@ it('merges @required logs from resolver field with parent', () => { const operation = createOperationDescriptor(FooQuery, {}); const store = new RelayStore(source, {gcReleaseBufferSize: 0}); - const {errorResponseFields} = store.lookup(operation.fragment); - expect(errorResponseFields).toEqual([ + const {fieldErrors} = store.lookup(operation.fragment); + expect(fieldErrors).toEqual([ { kind: 'missing_required_field.log', owner: 'UserRequiredNameResolver', @@ -346,7 +346,7 @@ it('merges @required logs from resolver field with parent', () => { // Lookup a second time to ensure that we still report the missing fields when // reading from the cache. - const {errorResponseFields: missingRequiredFieldsTakeTwo} = store.lookup( + const {fieldErrors: missingRequiredFieldsTakeTwo} = store.lookup( operation.fragment, ); @@ -398,10 +398,10 @@ it('propagates @required(action: THROW) errors from the resolver up to the reade const store = new RelayStore(source, {gcReleaseBufferSize: 0}); const beforeCallCount = requiredThrowNameCalls.count; - const {errorResponseFields, data} = store.lookup(operation.fragment); + const {fieldErrors, data} = store.lookup(operation.fragment); expect(data).toEqual({me: {required_throw_name: null}}); expect(requiredThrowNameCalls.count).toBe(beforeCallCount); - expect(errorResponseFields).toEqual([ + expect(fieldErrors).toEqual([ { kind: 'missing_required_field.throw', owner: 'UserRequiredThrowNameResolver', @@ -412,7 +412,7 @@ it('propagates @required(action: THROW) errors from the resolver up to the reade // Lookup a second time to ensure that we still report the missing fields when // reading from the cache. - const {errorResponseFields: missingRequiredFieldsTakeTwo, data: dataTakeTwo} = + const {fieldErrors: missingRequiredFieldsTakeTwo, data: dataTakeTwo} = store.lookup(operation.fragment); expect(dataTakeTwo).toEqual({me: {required_throw_name: null}}); @@ -1040,14 +1040,10 @@ it('Returns null and includes errors when the resolver throws', () => { const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read( - source, - operation.fragment, - resolverCache, - ); + const {data, fieldErrors} = read(source, operation.fragment, resolverCache); expect(data).toEqual({me: {always_throws: null}}); // Resolver result - expect(errorResponseFields).toMatchInlineSnapshot(` + expect(fieldErrors).toMatchInlineSnapshot(` Array [ Object { "error": [Error: I always throw. What did you expect?], @@ -1061,7 +1057,7 @@ it('Returns null and includes errors when the resolver throws', () => { `); // Subsequent read should also read the same error/path - const {data: data2, errorResponseFields: relayResolverErrors2} = read( + const {data: data2, fieldErrors: relayResolverErrors2} = read( source, operation.fragment, resolverCache, @@ -1108,14 +1104,10 @@ it('Returns null and includes errors when a transitive resolver throws', () => { const operation = createOperationDescriptor(FooQuery, {id: '1'}); - const {data, errorResponseFields} = read( - source, - operation.fragment, - resolverCache, - ); + const {data, fieldErrors} = read(source, operation.fragment, resolverCache); expect(data).toEqual({me: {always_throws_transitively: null}}); // Resolver result - expect(errorResponseFields).toMatchInlineSnapshot(` + expect(fieldErrors).toMatchInlineSnapshot(` Array [ Object { "error": [Error: I always throw. What did you expect?], @@ -1129,7 +1121,7 @@ it('Returns null and includes errors when a transitive resolver throws', () => { `); // Subsequent read should also read the same error/path - const {data: data2, errorResponseFields: relayResolverErrors2} = read( + const {data: data2, fieldErrors: relayResolverErrors2} = read( source, operation.fragment, resolverCache, @@ -1170,14 +1162,10 @@ it('Catches errors thrown before calling readFragment', () => { const operation = createOperationDescriptor(FooQuery, {}); - const {data, errorResponseFields} = read( - source, - operation.fragment, - resolverCache, - ); + const {data, fieldErrors} = read(source, operation.fragment, resolverCache); expect(data).toEqual({throw_before_read: null}); // Resolver result - expect(errorResponseFields).toMatchInlineSnapshot(` + expect(fieldErrors).toMatchInlineSnapshot(` Array [ Object { "error": [Error: Purposefully throwing before reading to exercise an edge case.], diff --git a/packages/relay-runtime/store/__tests__/resolvers/LiveResolvers-test.js b/packages/relay-runtime/store/__tests__/resolvers/LiveResolvers-test.js index 3c1c610efadaa..821fbf4f0d5b0 100644 --- a/packages/relay-runtime/store/__tests__/resolvers/LiveResolvers-test.js +++ b/packages/relay-runtime/store/__tests__/resolvers/LiveResolvers-test.js @@ -256,7 +256,7 @@ test('Errors thrown during _initial_ read() are caught as resolver errors', () = }); const snapshot = environment.lookup(operation.fragment); - expect(snapshot.errorResponseFields).toEqual([ + expect(snapshot.fieldErrors).toEqual([ { kind: 'relay_resolver.error', error: Error('What?'), @@ -299,7 +299,7 @@ test('Errors thrown during read() _after update_ are caught as resolver errors', environment.subscribe(snapshot, handler); // Confirm there are no initial errors - expect(snapshot.errorResponseFields).toEqual(null); + expect(snapshot.fieldErrors).toEqual(null); const data: $FlowExpectedError = snapshot.data; expect(data.counter_throws_when_odd).toBe(0); @@ -310,7 +310,7 @@ test('Errors thrown during read() _after update_ are caught as resolver errors', const nextSnapshot = handler.mock.calls[0][0]; - expect(nextSnapshot.errorResponseFields).toEqual([ + expect(nextSnapshot.fieldErrors).toEqual([ { kind: 'relay_resolver.error', error: Error('What?'), @@ -331,7 +331,7 @@ test('Errors thrown during read() _after update_ are caught as resolver errors', const finalSnapshot = handler.mock.calls[0][0]; // Confirm there are no initial errors - expect(finalSnapshot.errorResponseFields).toEqual(null); + expect(finalSnapshot.fieldErrors).toEqual(null); const finalData: $FlowExpectedError = finalSnapshot.data; expect(finalData.counter_throws_when_odd).toBe(2); }); diff --git a/packages/relay-runtime/store/__tests__/resolvers/Resolver-test.js b/packages/relay-runtime/store/__tests__/resolvers/Resolver-test.js index 93aa49b1af3b1..dbcf654400ce1 100644 --- a/packages/relay-runtime/store/__tests__/resolvers/Resolver-test.js +++ b/packages/relay-runtime/store/__tests__/resolvers/Resolver-test.js @@ -125,8 +125,8 @@ describe('Relay Resolver', () => { environment.commitPayload(operation, {}); - const {data, errorResponseFields} = environment.lookup(operation.fragment); - expect(errorResponseFields).toBe(null); + const {data, fieldErrors} = environment.lookup(operation.fragment); + expect(fieldErrors).toBe(null); // $FlowFixMe[incompatible-use] Lookup is untyped expect(data.hello_optional_world).toEqual('Hello, Default!'); diff --git a/packages/relay-runtime/store/__tests__/resolvers/ResolverGC-test.js b/packages/relay-runtime/store/__tests__/resolvers/ResolverGC-test.js index d6cf747fc0634..5ea579b266efb 100644 --- a/packages/relay-runtime/store/__tests__/resolvers/ResolverGC-test.js +++ b/packages/relay-runtime/store/__tests__/resolvers/ResolverGC-test.js @@ -180,7 +180,7 @@ test('Regular resolver with fragment reads live resovler with fragment', async ( }, afterLookupAfterFreedGC: (snapshot, recordIdsInStore) => { expect(snapshot.data).toEqual({counter_plus_one: null}); - expect(snapshot.errorResponseFields).toEqual([ + expect(snapshot.fieldErrors).toEqual([ { fieldPath: 'me.', kind: 'missing_expected_data.log', @@ -735,7 +735,7 @@ test('Resolver reading a plural client-edge to a client type', async () => { afterLookupAfterFreedGC: (snapshot, recordIdsInStore) => { // Note that we _can't_ recreate the Resolver value because it's root fragment has been GGed. expect(snapshot.data).toEqual({all_astrological_signs: null}); - expect(snapshot.errorResponseFields).toEqual([ + expect(snapshot.fieldErrors).toEqual([ { fieldPath: 'me.', kind: 'missing_expected_data.log', diff --git a/packages/relay-runtime/store/observeFragmentExperimental.js b/packages/relay-runtime/store/observeFragmentExperimental.js index 424ef28a3254c..a35b9a29ecf6c 100644 --- a/packages/relay-runtime/store/observeFragmentExperimental.js +++ b/packages/relay-runtime/store/observeFragmentExperimental.js @@ -252,7 +252,7 @@ function snapshotToFragmentState( } try { - handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields); + handlePotentialSnapshotErrors(environment, snapshot.fieldErrors); } catch (error) { return {error, state: 'error'}; } diff --git a/packages/relay-runtime/util/handlePotentialSnapshotErrors.js b/packages/relay-runtime/util/handlePotentialSnapshotErrors.js index 8e975827feec3..4a17ead846f27 100644 --- a/packages/relay-runtime/util/handlePotentialSnapshotErrors.js +++ b/packages/relay-runtime/util/handlePotentialSnapshotErrors.js @@ -12,8 +12,8 @@ 'use strict'; import type { - ErrorResponseField, - ErrorResponseFields, + FieldError, + FieldErrors, IEnvironment, } from '../store/RelayStoreTypes'; @@ -21,16 +21,16 @@ const invariant = require('invariant'); function handleFieldErrors( environment: IEnvironment, - errorResponseFields: ErrorResponseFields, + fieldErrors: FieldErrors, ) { - for (const fieldError of errorResponseFields) { + for (const fieldError of fieldErrors) { // First we log all events. Note that the logger may opt to throw its own // error here if it wants to throw an error that is better integrated into // site's error handling infrastructure. environment.relayFieldLogger(fieldError); } - for (const fieldError of errorResponseFields) { + for (const fieldError of fieldErrors) { if (eventShouldThrow(fieldError)) { switch (fieldError.kind) { case 'relay_resolver.error': @@ -63,7 +63,7 @@ function handleFieldErrors( } } -function eventShouldThrow(event: ErrorResponseField): boolean { +function eventShouldThrow(event: FieldError): boolean { switch (event.kind) { case 'relay_resolver.error': case 'relay_field_payload.error': @@ -82,14 +82,14 @@ function eventShouldThrow(event: ErrorResponseField): boolean { function handlePotentialSnapshotErrors( environment: IEnvironment, - errorResponseFields: ?ErrorResponseFields, + fieldErrors: ?FieldErrors, ) { /** * Inside handleFieldErrors, we check for throwOnFieldError - but this fn logs the error anyway by default * which is why this still should run in any case there's errors. */ - if (errorResponseFields != null) { - handleFieldErrors(environment, errorResponseFields); + if (fieldErrors != null) { + handleFieldErrors(environment, fieldErrors); } }