Skip to content

Commit

Permalink
Simplify what we keep in the store for resolver errors
Browse files Browse the repository at this point in the history
Reviewed By: josephsavona

Differential Revision:
D46499963

Privacy Context Container: L1125407

fbshipit-source-id: 6d94ebd16f0e1542936543ee76568f13fe88917d
  • Loading branch information
captbaritone authored and facebook-github-bot committed Jun 12, 2023
1 parent feaba45 commit 5dfb88b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
17 changes: 6 additions & 11 deletions packages/relay-runtime/store/RelayReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ class RelayReader {
field,
this._variables,
key,
this._fragmentName,
);
return {
resolverResult,
Expand All @@ -590,7 +589,6 @@ class RelayReader {
field,
this._variables,
null,
this._fragmentName,
);
return {
resolverResult,
Expand Down Expand Up @@ -646,7 +644,10 @@ class RelayReader {
// the errors can be attached to this read's snapshot. This allows the error
// to be logged.
if (resolverError) {
this._resolverErrors.push(resolverError);
this._resolverErrors.push({
field: {path: field.path, owner: this._fragmentName},
error: resolverError,
});
}

// The resolver itself creates a record in the store. We record that we've
Expand Down Expand Up @@ -1175,8 +1176,7 @@ function getResolverValue(
field: ReaderRelayResolver | ReaderRelayLiveResolver,
variables: Variables,
fragmentKey: mixed,
ownerName: string,
) {
): [mixed, ?Error] {
// Support for languages that work (best) with ES6 modules, such as TypeScript.
const resolverFunction =
typeof field.resolverModule === 'function'
Expand All @@ -1201,12 +1201,7 @@ function getResolverValue(
if (e === RESOLVER_FRAGMENT_MISSING_DATA_SENTINEL) {
resolverResult = undefined;
} else {
// `field.path` is typed as nullable while we rollout compiler changes.
const path = field.path ?? '[UNKNOWN]';
resolverError = {
field: {path, owner: ownerName},
error: e,
};
resolverError = e;
}
}
return [resolverResult, resolverError];
Expand Down
11 changes: 5 additions & 6 deletions packages/relay-runtime/store/ResolverCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {
DataIDSet,
MutableRecordSource,
Record,
RelayResolverError,
SingularReaderSelector,
Snapshot,
} from './RelayStoreTypes';
Expand All @@ -44,7 +43,7 @@ type ResolverID = string;
export type EvaluationResult<T> = {
resolverResult: ?T,
snapshot: ?Snapshot,
error: ?RelayResolverError,
error: ?Error,
};

export type ResolverFragmentResult = {
Expand All @@ -65,7 +64,7 @@ export interface ResolverCache {
): [
?T /* Answer */,
?DataID /* Seen record */,
?RelayResolverError,
?Error,
?Snapshot,
?DataID /* ID of record containing a suspended Live field */,
?DataIDSet /** Set of updated records after read. Then need to be consumed by `processFollowupUpdates` */,
Expand All @@ -90,7 +89,7 @@ class NoopResolverCache implements ResolverCache {
): [
?T /* Answer */,
?DataID /* Seen record */,
?RelayResolverError,
?Error,
?Snapshot,
?DataID /* ID of record containing a suspended Live field */,
?DataIDSet /** Set of dirty records after read */,
Expand Down Expand Up @@ -147,7 +146,7 @@ class RecordResolverCache implements ResolverCache {
): [
?T /* Answer */,
?DataID /* Seen record */,
?RelayResolverError,
?Error,
?Snapshot,
?DataID /* ID of record containing a suspended Live field */,
?DataIDSet /** Set of dirty records after read */,
Expand Down Expand Up @@ -228,7 +227,7 @@ class RecordResolverCache implements ResolverCache {
// $FlowFixMe[incompatible-type] - casting mixed
const snapshot: ?Snapshot = linkedRecord[RELAY_RESOLVER_SNAPSHOT_KEY];
// $FlowFixMe[incompatible-type] - casting mixed
const error: ?RelayResolverError = linkedRecord[RELAY_RESOLVER_ERROR_KEY];
const error: ?Error = linkedRecord[RELAY_RESOLVER_ERROR_KEY];

return [answer, linkedID, error, snapshot, undefined, undefined];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type {
MutableRecordSource,
Record,
RecordSource,
RelayResolverError,
SingularReaderSelector,
Snapshot,
} from '../RelayStoreTypes';
Expand Down Expand Up @@ -115,7 +114,7 @@ class LiveResolverCache implements ResolverCache {
): [
?T /* Answer */,
?DataID /* Seen record */,
?RelayResolverError,
?Error,
?Snapshot,
?DataID /* ID of record containing a suspended Live field */,
?DataIDSet /** Set of dirty records after read */,
Expand Down Expand Up @@ -292,7 +291,7 @@ class LiveResolverCache implements ResolverCache {
// $FlowFixMe[incompatible-type] - casting mixed
const snapshot: ?Snapshot = linkedRecord[RELAY_RESOLVER_SNAPSHOT_KEY];
// $FlowFixMe[incompatible-type] - casting mixed
const error: ?RelayResolverError = linkedRecord[RELAY_RESOLVER_ERROR_KEY];
const error: ?Error = linkedRecord[RELAY_RESOLVER_ERROR_KEY];

let suspenseID = null;

Expand Down

0 comments on commit 5dfb88b

Please sign in to comment.