MockPayloadGenerator loses fields and concrete types across repeated plural-field traversal
With [email protected] , 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:
- An attachment connection with plural edges and abstract node values.
- An initial selection of
__typenameand type-specific content fields. - 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.
Source: facebook/relay