Skip to content

Commit

Permalink
4/n - Add logging on seeing relayFieldErrors
Browse files Browse the repository at this point in the history
Reviewed By: tyao1

Differential Revision: D51944687

fbshipit-source-id: 8c1db06d9cabf0d4174d15327035dd7f0fb1784f
  • Loading branch information
itamark authored and facebook-github-bot committed Jan 16, 2024
1 parent dde8048 commit 12d169f
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/react-relay/relay-hooks/FragmentResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,15 @@ class FragmentResourceImpl {
this._environment,
s.missingRequiredFields,
s.relayResolverErrors,
s.errorResponseFields,
);
});
} else {
handlePotentialSnapshotErrors(
this._environment,
snapshot.missingRequiredFields,
snapshot.relayResolverErrors,
snapshot.errorResponseFields,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ function handlePotentialSnapshotErrorsForState(
environment,
state.snapshot.missingRequiredFields,
state.snapshot.relayResolverErrors,
state.snapshot.errorResponseFields,
);
} else if (state.kind === 'plural') {
for (const snapshot of state.snapshots) {
handlePotentialSnapshotErrors(
environment,
snapshot.missingRequiredFields,
snapshot.relayResolverErrors,
snapshot.errorResponseFields,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ function handlePotentialSnapshotErrorsForState(
environment,
state.snapshot.missingRequiredFields,
state.snapshot.relayResolverErrors,
state.snapshot.errorResponseFields,
);
} else if (state.kind === 'plural') {
for (const snapshot of state.snapshots) {
handlePotentialSnapshotErrors(
environment,
snapshot.missingRequiredFields,
snapshot.relayResolverErrors,
snapshot.errorResponseFields,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/relay-runtime/query/fetchQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function fetchQuery<TVariables: Variables, TData, TRawResponse>(
environment,
snapshot.missingRequiredFields,
snapshot.relayResolverErrors,
snapshot.errorResponseFields,
);
/* $FlowFixMe[incompatible-return] we assume readData returns the right
* data just having written it from network or checked availability. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class SelectorResolver {
this._environment,
this._missingRequiredFields,
this._relayResolverErrors,
this._errorResponseFields,
);
return this._data;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/relay-runtime/store/RelayStoreTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,12 @@ export type RelayFieldLoggerEvent =
+owner: string,
+fieldPath: string,
+error: Error,
}
| {
+kind: 'relay_field_payload.error',
+owner: string,
+fieldPath: string,
+error: TRelayFieldError,
};

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/relay-runtime/util/RelayFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export type FeatureFlags = {
ENABLE_FIELD_ERROR_HANDLING: boolean,

ENABLE_STRICT_EQUAL_SELECTORS: boolean,
ENABLE_FIELD_ERROR_HANDLING_THROW_BY_DEFAULT: boolean,
ENABLE_FIELD_ERROR_HANDLING_CATCH_DIRECTIVE: boolean,
};

const RelayFeatureFlags: FeatureFlags = {
Expand All @@ -66,6 +68,8 @@ const RelayFeatureFlags: FeatureFlags = {
ENABLE_OPERATION_TRACKER_OPTIMISTIC_UPDATES: false,
ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE: false,
ENABLE_FIELD_ERROR_HANDLING: false,
ENABLE_FIELD_ERROR_HANDLING_THROW_BY_DEFAULT: false,
ENABLE_FIELD_ERROR_HANDLING_CATCH_DIRECTIVE: false,
ENABLE_SHALLOW_FREEZE_RESOLVER_VALUES: true,
ENABLE_STRICT_EQUAL_SELECTORS: false,
};
Expand Down
19 changes: 19 additions & 0 deletions packages/relay-runtime/util/handlePotentialSnapshotErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
'use strict';

import type {
ErrorResponseFields,
IEnvironment,
MissingRequiredFields,
RelayResolverErrors,
} from '../store/RelayStoreTypes';

import RelayFeatureFlags from './RelayFeatureFlags';

function handlePotentialSnapshotErrors(
environment: IEnvironment,
missingRequiredFields: ?MissingRequiredFields,
relayResolverErrors: RelayResolverErrors,
errorResponseFields: ?ErrorResponseFields,
) {
for (const resolverError of relayResolverErrors) {
environment.relayFieldLogger({
Expand All @@ -30,6 +34,21 @@ function handlePotentialSnapshotErrors(
error: resolverError.error,
});
}
if (RelayFeatureFlags.ENABLE_FIELD_ERROR_HANDLING) {
if (errorResponseFields != null) {
for (const fieldError of errorResponseFields) {
const {path, owner, error} = fieldError;

environment.relayFieldLogger({
kind: 'relay_field_payload.error',
owner: owner,
fieldPath: path,
error,
});
}
}
}

if (missingRequiredFields != null) {
switch (missingRequiredFields.action) {
case 'THROW': {
Expand Down

0 comments on commit 12d169f

Please sign in to comment.