Skip to content

Commit

Permalink
Don't report missing fields within an unmatched inline fragment
Browse files Browse the repository at this point in the history
Reviewed By: RyanHoldren

Differential Revision:
D63791315

Privacy Context Container: L1125407

fbshipit-source-id: b7165b99cfdf793f08b5c457b192356f3e81dcf0
  • Loading branch information
captbaritone authored and facebook-github-bot committed Oct 3, 2024
1 parent a1370e8 commit 6c88271
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/relay-runtime/store/RelayReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ class RelayReader {
}

_markDataAsMissing(): void {
if (this._isWithinUnmatchedTypeRefinement) {
return;
}
if (this._errorResponseFields == null) {
this._errorResponseFields = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,61 @@ describe('RelayReader error fields', () => {
);

expect(isMissingData).toBe(false);
expect(errorResponseFields).toEqual(null);
});

// FIXME: This should be null
it('does report missing data within an inline fragment that does match', () => {
const source = RelayRecordSource.create({
'client:root': {
__id: 'client:root',
__typename: '__Root',
'node(id:"4")': {__ref: '4'},
},
'client:__type:User': {
__isMaybeNodeInterface: true,
},
'4': {
__id: '4',
id: '4',
__typename: 'NonNodeNoID',
// NOTE: `name` is missing
},
});

const FooQuery = graphql`
query RelayReaderRelayErrorHandlingTestInlineFragmentMatchesQuery
@throwOnFieldError {
node(id: "4") {
# GraphQL lets us spread this here as long as there is at least one
# type that overlaps
... on MaybeNodeInterface {
name
}
}
}
`;
const operation = createOperationDescriptor(FooQuery, {});
const {errorResponseFields, isMissingData} = read(
source,
operation.fragment,
);

expect(isMissingData).toBe(true);
expect(errorResponseFields).toEqual([
// We are missing the metadata bout the interface
{
fieldPath: '',
handled: false,
kind: 'missing_expected_data.throw',
owner: 'RelayReaderRelayErrorHandlingTestInlineFragmentMatchesQuery',
},
// We don't know if we should traverse into the inline fragment, but we do
// anyway and find that the field is missing
{
fieldPath: '',
handled: false,
kind: 'missing_expected_data.throw',
owner: 'RelayReaderRelayErrorHandlingTestInlineFragmentQuery',
owner: 'RelayReaderRelayErrorHandlingTestInlineFragmentMatchesQuery',
},
]);
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6c88271

Please sign in to comment.