Skip to content

Commit

Permalink
Split out method in RelayReader responsible for propogating resolver …
Browse files Browse the repository at this point in the history
…metadata

Reviewed By: josephsavona

Differential Revision: D46614515

fbshipit-source-id: 4b088dc156815d51fd9d3e702e671ec16bffcb2d
  • Loading branch information
captbaritone authored and facebook-github-bot committed Jun 13, 2023
1 parent fca7a9c commit b23fe58
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions packages/relay-runtime/store/RelayReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,23 +578,15 @@ class RelayReader {
this._variables,
key,
);
return {
resolverResult,
snapshot: snapshot,
error: resolverError,
};
return {resolverResult, snapshot, error: resolverError};
});
} else {
const [resolverResult, resolverError] = getResolverValue(
field,
this._variables,
null,
);
return {
resolverResult,
snapshot: undefined,
error: resolverError,
};
return {resolverResult, snapshot: undefined, error: resolverError};
}
};

Expand All @@ -613,6 +605,31 @@ class RelayReader {
getDataForResolverFragment,
);

this._propogateResolverMetadata(
field.path,
cachedSnapshot,
resolverError,
seenRecord,
suspenseID,
updatedDataIDs,
);

const applicationName = field.alias ?? field.name;
data[applicationName] = result;
return result;
}

// Reading a resolver field can uncover missing data, errors, suspense,
// additional seen records and updated dataIDs. All of these facts must be
// represented in the snapshot we return for this fragment.
_propogateResolverMetadata(
fieldPath: string,
cachedSnapshot: ?Snapshot,
resolverError: ?Error,
seenRecord: ?DataID,
suspenseID: ?DataID,
updatedDataIDs: ?DataIDSet,
) {
// The resolver's root fragment (if there is one) may be missing data, have
// errors, or be in a suspended state. Here we propagate those cases
// upwards to mimic the behavior of having traversed into that fragment directly.
Expand Down Expand Up @@ -645,7 +662,7 @@ class RelayReader {
// to be logged.
if (resolverError) {
this._resolverErrors.push({
field: {path: field.path, owner: this._fragmentName},
field: {path: fieldPath, owner: this._fragmentName},
error: resolverError,
});
}
Expand All @@ -665,7 +682,7 @@ class RelayReader {
if (suspenseID != null) {
this._isMissingData = true;
this._missingLiveResolverFields.push({
path: `${this._fragmentName}.${field.path}`,
path: `${this._fragmentName}.${fieldPath}`,
liveStateID: suspenseID,
});
}
Expand All @@ -674,10 +691,6 @@ class RelayReader {
this._updatedDataIDs.add(recordID);
}
}

const applicationName = field.alias ?? field.name;
data[applicationName] = result;
return result;
}

_readClientEdge(
Expand Down

0 comments on commit b23fe58

Please sign in to comment.