facebook / facebook/relay

MockPayloadGenerator loses fields and concrete types across repeated plural-field traversal

Open
#5,415 0 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

With relay-test-utils@20.1.1 , `MockPayloadGenerator.generate()` can lose previously generated fields or change a node’s concrete  `__typename`  when the same plural linked field is traversed multiple times.

We encountered this when attachment content and Relay resolver dependency fragments selected overlapping fields.

Reproduction scenario

Use a normalization operation containing:

1. An attachment connection with plural edges and abstract node values.
2. An initial selection of  `__typename`  and type-specific content fields.
3. Subsequent fragment-spread selections revisiting the same attachment path for additional fields.

Generate a mock payload, then normalize it using `environment.commitPayload()`.

The operation structure matters: it contains repeated selections through fragment spreads, rather than one flattened attachment selection.

Expected behavior

Each attachment retains its concrete type and previously generated fields. Later traversals merge additional fields into the corresponding list item without mixing data between items.

Actual behavior

Previously generated attachment fields can disappear, and the concrete type can change. Normalizing the resulting payload produces missing-field warnings, even though the fields are selected by the operation.

Suspected cause

In  lib/RelayMockPayloadGenerator.js :

• Scalar generation explicitly permits overwriting an existing  `__typename` .
• Repeated plural-field traversal passes the previous field’s entire array as prior data, rather than the previous item at the current index.

A local patch preserving an existing  `__typename`  and passing the corresponding previous array item addresses our reproduction. Regression cases cover multiple concrete types, retained content fields, null entries, empty lists, and null connections.

Versions

•  relay-test-utils :  20.1.1 
•  relay-runtime :  20.1.1 

We have not confirmed whether a newer release addresses this.

Contributor guide

Open the contributing guide

Research direction

Start in lib/RelayMockPayloadGenerator.js and reproduce the repeated plural-field traversal described with environment.commitPayload(). Check the existing __typename handling and prior array-item behavior against the reported scenario, then add or run regression coverage for multiple concrete types, retained fields, null entries, empty lists, and null connections. Done means repeated traversals preserve each list item’s type and previously generated fields without missing-field warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.