Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,49 @@ describe('RelayResponseNormalizer', () => {
});
});

// Regression test for facebook/relay#5056 — currently demonstrates
// buggy behavior; flip assertion when the underlying bug is fixed.
// The reported schema shape is `[[MyType!]!]!` where the inner type is
// an abstract (interface/union). The test schema does not model nested
// lists, so this test instead sends a doubly-nested payload to a plain
// plural-of-abstract field (`User.actors: [Actor]`). That exercises the
// same `_normalizePluralLink` → `_getRecordType` runtime path described
// in #5056: the inner "item" is itself an array, so `_getRecordType`
// receives an array and fails with an unhelpful Invariant Violation.
it('throws when a plural-of-abstract field receives a nested-array payload (#5056)', () => {
const Query = graphql`
query RelayResponseNormalizerTest5056Query($id: ID) {
node(id: $id) {
id
__typename
... on User {
actors {
id
__typename
}
}
}
}
`;
const malformedPayload = {
node: {
id: '1',
__typename: 'User',
actors: [[{id: '2', __typename: 'Page'}]],
},
};
const recordSource = new RelayRecordSource();
recordSource.set(ROOT_ID, RelayModernRecord.create(ROOT_ID, ROOT_TYPE));
expect(() =>
normalize(
recordSource,
createNormalizationSelector(Query.operation, ROOT_ID, {id: '1'}),
malformedPayload,
defaultOptions,
),
).toThrow(/Expected a typename for record `\[/);
});

it('warns in __DEV__ if payload data is missing an expected field', () => {
const BarQuery = graphql`
query RelayResponseNormalizerTest20Query($id: ID) {
Expand Down

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

Loading