Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fieldPath to missing data field error logs #4835

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 55 additions & 12 deletions packages/relay-runtime/store/RelayReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class RelayReader {
}
}

_markDataAsMissing(): void {
_markDataAsMissing(fieldName: string): void {
if (this._isWithinUnmatchedTypeRefinement) {
return;
}
Expand All @@ -226,18 +226,17 @@ class RelayReader {
}

// we will add the path later
const fieldPath = '';
const owner = this._fragmentName;

this._errorResponseFields.push(
this._selector.node.metadata?.throwOnFieldError ?? false
? {
kind: 'missing_expected_data.throw',
owner,
fieldPath,
fieldPath: fieldName,
handled: false,
}
: {kind: 'missing_expected_data.log', owner, fieldPath},
: {kind: 'missing_expected_data.log', owner, fieldPath: fieldName},
);

this._isMissingData = true;
Expand Down Expand Up @@ -266,7 +265,7 @@ class RelayReader {
this._seenRecords.add(dataID);
if (record == null) {
if (record === undefined) {
this._markDataAsMissing();
this._markDataAsMissing('<record>');
}
return record;
}
Expand Down Expand Up @@ -489,12 +488,15 @@ class RelayReader {
this._createFragmentPointer(selection, record, data);
break;
case 'AliasedInlineFragmentSpread': {
const prevErrors = this._errorResponseFields;
this._errorResponseFields = null;
let fieldValue = this._readInlineFragment(
selection.fragment,
record,
{},
true,
);
this._prependPreviousErrors(prevErrors, selection.name);
if (fieldValue === false) {
fieldValue = null;
}
Expand Down Expand Up @@ -601,9 +603,12 @@ class RelayReader {
data: SelectorData,
): mixed {
const parentRecordID = RelayModernRecord.getDataID(record);
const prevErrors = this._errorResponseFields;
this._errorResponseFields = null;
const result = this._readResolverFieldImpl(field, parentRecordID);

const fieldName = field.alias ?? field.name;
this._prependPreviousErrors(prevErrors, fieldName);
data[fieldName] = result;
return result;
}
Expand Down Expand Up @@ -982,12 +987,15 @@ class RelayReader {
RelayModernRecord.getDataID(record),
prevData,
);
const prevErrors = this._errorResponseFields;
this._errorResponseFields = null;
const edgeValue = this._traverse(
field.linkedField,
storeID,
// $FlowFixMe[incompatible-variance]
prevData,
);
this._prependPreviousErrors(prevErrors, fieldName);
this._clientEdgeTraversalPath.pop();
data[fieldName] = edgeValue;
return edgeValue;
Expand All @@ -1005,7 +1013,7 @@ class RelayReader {
if (value === null) {
this._maybeAddErrorResponseFields(record, storageKey);
} else if (value === undefined) {
this._markDataAsMissing();
this._markDataAsMissing(fieldName);
}
data[fieldName] = value;
return value;
Expand All @@ -1024,7 +1032,7 @@ class RelayReader {
if (linkedID === null) {
this._maybeAddErrorResponseFields(record, storageKey);
} else if (linkedID === undefined) {
this._markDataAsMissing();
this._markDataAsMissing(fieldName);
}
return linkedID;
}
Expand All @@ -1039,12 +1047,41 @@ class RelayReader {
RelayModernRecord.getDataID(record),
prevData,
);
const prevErrors = this._errorResponseFields;
this._errorResponseFields = null;
// $FlowFixMe[incompatible-variance]
const value = this._traverse(field, linkedID, prevData);

this._prependPreviousErrors(prevErrors, fieldName);
data[fieldName] = value;
return value;
}

_prependPreviousErrors(
prevErrors: ?Array<ErrorResponseField>,
fieldNameOrIndex: string | number,
): void {
if (this._errorResponseFields != null) {
for (let i = 0; i < this._errorResponseFields.length; i++) {
const event = this._errorResponseFields[i];
if (
event.owner === this._fragmentName &&
(event.kind === 'missing_expected_data.throw' ||
event.kind === 'missing_expected_data.log')
) {
event.fieldPath = `${fieldNameOrIndex}.${event.fieldPath}`;
}
}
if (prevErrors != null) {
for (let i = prevErrors.length - 1; i >= 0; i--) {
this._errorResponseFields.unshift(prevErrors[i]);
}
}
} else {
this._errorResponseFields = prevErrors;
}
}

_readActorChange(
field: ReaderActorChange,
record: Record,
Expand All @@ -1060,7 +1097,7 @@ class RelayReader {
if (externalRef == null) {
data[fieldName] = externalRef;
if (externalRef === undefined) {
this._markDataAsMissing();
this._markDataAsMissing(fieldName);
} else if (externalRef === null) {
this._maybeAddErrorResponseFields(record, storageKey);
}
Expand Down Expand Up @@ -1107,7 +1144,7 @@ class RelayReader {
if (linkedIDs == null) {
data[fieldName] = linkedIDs;
if (linkedIDs === undefined) {
this._markDataAsMissing();
this._markDataAsMissing(fieldName);
}
return linkedIDs;
}
Expand All @@ -1121,11 +1158,13 @@ class RelayReader {
RelayModernRecord.getDataID(record),
prevData,
);
const prevErrors = this._errorResponseFields;
this._errorResponseFields = null;
const linkedArray = prevData || [];
linkedIDs.forEach((linkedID, nextIndex) => {
if (linkedID == null) {
if (linkedID === undefined) {
this._markDataAsMissing();
this._markDataAsMissing(String(nextIndex));
}
// $FlowFixMe[cannot-write]
linkedArray[nextIndex] = linkedID;
Expand All @@ -1140,10 +1179,14 @@ class RelayReader {
RelayModernRecord.getDataID(record),
prevItem,
);
const prevErrors = this._errorResponseFields;
this._errorResponseFields = null;
// $FlowFixMe[cannot-write]
// $FlowFixMe[incompatible-variance]
linkedArray[nextIndex] = this._traverse(field, linkedID, prevItem);
this._prependPreviousErrors(prevErrors, nextIndex);
});
this._prependPreviousErrors(prevErrors, fieldName);
data[fieldName] = linkedArray;
return linkedArray;
}
Expand All @@ -1166,7 +1209,7 @@ class RelayReader {
RelayModernRecord.getValue(record, componentKey);
if (component == null) {
if (component === undefined) {
this._markDataAsMissing();
this._markDataAsMissing('<module-import>');
}
return;
}
Expand Down Expand Up @@ -1398,7 +1441,7 @@ class RelayReader {
// fetched the `__is[AbstractType]` flag for this concrete type. In this
// case we need to report that we are missing data, in case that field is
// still in flight.
this._markDataAsMissing();
this._markDataAsMissing('<abstract-type-hint>');
}
// $FlowFixMe Casting record value
return implementsInterface;
Expand Down
4 changes: 2 additions & 2 deletions packages/relay-runtime/store/RelayStoreTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ export type MissingFieldHandler =
export type MissingExpectedDataLogEvent = {
+kind: 'missing_expected_data.log',
+owner: string,
+fieldPath: string,
fieldPath: string,
};

/**
Expand All @@ -1300,7 +1300,7 @@ export type MissingExpectedDataLogEvent = {
export type MissingExpectedDataThrowEvent = {
+kind: 'missing_expected_data.throw',
+owner: string,
+fieldPath: string,
fieldPath: string,
+handled: boolean,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ function cloneEventWithSets(event: LogEvent) {
isMissingData: true,
errorResponseFields: [
{
fieldPath: '',
fieldPath: 'profilePicture',
kind: 'missing_expected_data.log',
owner: 'RelayModernStoreSubscriptionsTest1Fragment',
},
{
fieldPath: '',
fieldPath: 'emailAddresses',
kind: 'missing_expected_data.log',
owner: 'RelayModernStoreSubscriptionsTest1Fragment',
},
Expand Down Expand Up @@ -466,12 +466,12 @@ function cloneEventWithSets(event: LogEvent) {
},
errorResponseFields: [
{
fieldPath: '',
fieldPath: 'profilePicture',
kind: 'missing_expected_data.log',
owner: 'RelayModernStoreSubscriptionsTest1Fragment',
},
{
fieldPath: '',
fieldPath: 'emailAddresses',
kind: 'missing_expected_data.log',
owner: 'RelayModernStoreSubscriptionsTest1Fragment',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,12 @@ function cloneEventWithSets(event: LogEvent) {
{
owner: 'RelayModernStoreTest5Fragment',
kind: 'missing_expected_data.log',
fieldPath: '',
fieldPath: 'profilePicture',
},
{
owner: 'RelayModernStoreTest5Fragment',
kind: 'missing_expected_data.log',
fieldPath: '',
fieldPath: 'emailAddresses',
},
],
missingLiveResolverFields: [],
Expand Down Expand Up @@ -782,12 +782,12 @@ function cloneEventWithSets(event: LogEvent) {
{
owner: 'RelayModernStoreTest5Fragment',
kind: 'missing_expected_data.log',
fieldPath: '',
fieldPath: 'profilePicture',
},
{
owner: 'RelayModernStoreTest5Fragment',
kind: 'missing_expected_data.log',
fieldPath: '',
fieldPath: 'emailAddresses',
},
],
seenRecords: new Set(['842472']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ describe('Inline Fragments', () => {
);
expect(errorResponseFields).toEqual([
{
fieldPath: '',
fieldPath: 'node.aliased_fragment.name',
kind: 'missing_expected_data.log',
owner:
'RelayReaderAliasedFragmentsTestRequiredBubblesOnAbstractTypeQuery',
Expand Down Expand Up @@ -1101,7 +1101,7 @@ describe('Inline Fragments', () => {
);
expect(errorResponseFields).toEqual([
{
fieldPath: '',
fieldPath: 'node.aliased_fragment.<abstract-type-hint>',
kind: 'missing_expected_data.log',
owner:
'RelayReaderAliasedFragmentsTestRequiredBubblesOnAbstractWithMissingTypeInfoQuery',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('RelayReader @catch', () => {

expect(errorResponseFields).toEqual([
{
fieldPath: '',
fieldPath: 'me.firstName',
kind: 'missing_expected_data.log',
owner: 'RelayReaderCatchFieldsTestCatchMissingToNullErrorQuery',
},
Expand Down
Loading
Loading