Skip to content

Commit 12d169f

Browse files
itamarkfacebook-github-bot
authored andcommitted
4/n - Add logging on seeing relayFieldErrors
Reviewed By: tyao1 Differential Revision: D51944687 fbshipit-source-id: 8c1db06d9cabf0d4174d15327035dd7f0fb1784f
1 parent dde8048 commit 12d169f

File tree

8 files changed

+37
-0
lines changed

8 files changed

+37
-0
lines changed

packages/react-relay/relay-hooks/FragmentResource.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,15 @@ class FragmentResourceImpl {
566566
this._environment,
567567
s.missingRequiredFields,
568568
s.relayResolverErrors,
569+
s.errorResponseFields,
569570
);
570571
});
571572
} else {
572573
handlePotentialSnapshotErrors(
573574
this._environment,
574575
snapshot.missingRequiredFields,
575576
snapshot.relayResolverErrors,
577+
snapshot.errorResponseFields,
576578
);
577579
}
578580
}

packages/react-relay/relay-hooks/experimental/readFragmentInternal_EXPERIMENTAL.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ function handlePotentialSnapshotErrorsForState(
8787
environment,
8888
state.snapshot.missingRequiredFields,
8989
state.snapshot.relayResolverErrors,
90+
state.snapshot.errorResponseFields,
9091
);
9192
} else if (state.kind === 'plural') {
9293
for (const snapshot of state.snapshots) {
9394
handlePotentialSnapshotErrors(
9495
environment,
9596
snapshot.missingRequiredFields,
9697
snapshot.relayResolverErrors,
98+
snapshot.errorResponseFields,
9799
);
98100
}
99101
}

packages/react-relay/relay-hooks/experimental/useFragmentInternal_EXPERIMENTAL.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,15 @@ function handlePotentialSnapshotErrorsForState(
117117
environment,
118118
state.snapshot.missingRequiredFields,
119119
state.snapshot.relayResolverErrors,
120+
state.snapshot.errorResponseFields,
120121
);
121122
} else if (state.kind === 'plural') {
122123
for (const snapshot of state.snapshots) {
123124
handlePotentialSnapshotErrors(
124125
environment,
125126
snapshot.missingRequiredFields,
126127
snapshot.relayResolverErrors,
128+
snapshot.errorResponseFields,
127129
);
128130
}
129131
}

packages/relay-runtime/query/fetchQuery.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ function fetchQuery<TVariables: Variables, TData, TRawResponse>(
140140
environment,
141141
snapshot.missingRequiredFields,
142142
snapshot.relayResolverErrors,
143+
snapshot.errorResponseFields,
143144
);
144145
/* $FlowFixMe[incompatible-return] we assume readData returns the right
145146
* data just having written it from network or checked availability. */

packages/relay-runtime/store/RelayModernFragmentSpecResolver.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ class SelectorResolver {
333333
this._environment,
334334
this._missingRequiredFields,
335335
this._relayResolverErrors,
336+
this._errorResponseFields,
336337
);
337338
return this._data;
338339
}

packages/relay-runtime/store/RelayStoreTypes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,12 @@ export type RelayFieldLoggerEvent =
12071207
+owner: string,
12081208
+fieldPath: string,
12091209
+error: Error,
1210+
}
1211+
| {
1212+
+kind: 'relay_field_payload.error',
1213+
+owner: string,
1214+
+fieldPath: string,
1215+
+error: TRelayFieldError,
12101216
};
12111217

12121218
/**

packages/relay-runtime/util/RelayFeatureFlags.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export type FeatureFlags = {
4646
ENABLE_FIELD_ERROR_HANDLING: boolean,
4747

4848
ENABLE_STRICT_EQUAL_SELECTORS: boolean,
49+
ENABLE_FIELD_ERROR_HANDLING_THROW_BY_DEFAULT: boolean,
50+
ENABLE_FIELD_ERROR_HANDLING_CATCH_DIRECTIVE: boolean,
4951
};
5052

5153
const RelayFeatureFlags: FeatureFlags = {
@@ -66,6 +68,8 @@ const RelayFeatureFlags: FeatureFlags = {
6668
ENABLE_OPERATION_TRACKER_OPTIMISTIC_UPDATES: false,
6769
ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE: false,
6870
ENABLE_FIELD_ERROR_HANDLING: false,
71+
ENABLE_FIELD_ERROR_HANDLING_THROW_BY_DEFAULT: false,
72+
ENABLE_FIELD_ERROR_HANDLING_CATCH_DIRECTIVE: false,
6973
ENABLE_SHALLOW_FREEZE_RESOLVER_VALUES: true,
7074
ENABLE_STRICT_EQUAL_SELECTORS: false,
7175
};

packages/relay-runtime/util/handlePotentialSnapshotErrors.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
'use strict';
1313

1414
import type {
15+
ErrorResponseFields,
1516
IEnvironment,
1617
MissingRequiredFields,
1718
RelayResolverErrors,
1819
} from '../store/RelayStoreTypes';
1920

21+
import RelayFeatureFlags from './RelayFeatureFlags';
22+
2023
function handlePotentialSnapshotErrors(
2124
environment: IEnvironment,
2225
missingRequiredFields: ?MissingRequiredFields,
2326
relayResolverErrors: RelayResolverErrors,
27+
errorResponseFields: ?ErrorResponseFields,
2428
) {
2529
for (const resolverError of relayResolverErrors) {
2630
environment.relayFieldLogger({
@@ -30,6 +34,21 @@ function handlePotentialSnapshotErrors(
3034
error: resolverError.error,
3135
});
3236
}
37+
if (RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING) {
38+
if (errorResponseFields != null) {
39+
for (const fieldError of errorResponseFields) {
40+
const {path, owner, error} = fieldError;
41+
42+
environment.relayFieldLogger({
43+
kind: 'relay_field_payload.error',
44+
owner: owner,
45+
fieldPath: path,
46+
error,
47+
});
48+
}
49+
}
50+
}
51+
3352
if (missingRequiredFields != null) {
3453
switch (missingRequiredFields.action) {
3554
case 'THROW': {

0 commit comments

Comments
 (0)