facebook / facebook/relay

normalizer fails for simple lists that are not ordered

Open
#4,677 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Hello,

with the current `main` version, we observe an (it seems) undocumented behavior when using simple lists that are not ordered.

This happens when the same node with a list field has different orders of elements in these lists. We have some lists that are small and where pagination doesn't make sense; thus they are not a connection.

Simple example:

```json
{
"viewer": {
"id": "user",
"orgs": [
{
"id": "org1"
},
{
"id": "org2"
}
]
},
"latestComment": {
"author": {
"id": "user",
"orgs": [
{
"id": "org2"
},
{
"id": "org1"
}
]
}
}
}
```

This would result in
```
ected warning in callback: RelayResponseNormalizer: Invalid record. The record contains references to the conflicting field, node and its id values: org1 and org2. We need to make sure that the record the field points to remains consistent or one field will overwrite the other.
```

Simple test case based on existing types in the test package.

```js
it('should not warn in __DEV__ if a single response contains conflicting linked fields which are not sorted', () => {
const BarQuery = graphql`query RelayResponseNormalizerTestListQuery {
me {
neighbors {
id
neighbors {
id
}
}
parents {
neighbors {
id
}
id
}
}
}`;

//
// we -> neighbors -> Mother and Father -> neighbors -> 4 and 5
//
const payload = {
me: {
id: '1',
__typename: 'User',
parents: [
{ // Father
id: '2',
neighbors: [
{
id: '4'
},
{
id: '5'
},
{
id: '1'
}
]
},
{ // Mother
id: '3',
neighbors: [
{
id: '4'
},
{
id: '5'
},
{
id: '1'
}
]
}
],
neighbors: [
{ // Father
id: '2',
neighbors: [
{
id: '4'
},
{
id: '5'
},
{
id: '1'
}
]
},
{ // Mother
id: '3',
neighbors: [
{
id: '4'
},
{
id: '5'
},
{
id: '1'
}
]
}
]
}
};
const recordSource = new RelayRecordSource();
recordSource.set(ROOT_ID, RelayModernRecord.create(ROOT_ID, ROOT_TYPE));

normalize(
recordSource,
createNormalizationSelector(BarQuery.operation, ROOT_ID, {
}),
payload,
defaultOptions,
);
});
```


Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.