Skip to content

Add regression test for MockPayloadGenerator nested-array bug with abstract InlineFragment (#5258)#5273

Closed
markselby9 wants to merge 2 commits into
facebook:mainfrom
markselby9:regression-test-5258
Closed

Add regression test for MockPayloadGenerator nested-array bug with abstract InlineFragment (#5258)#5273
markselby9 wants to merge 2 commits into
facebook:mainfrom
markselby9:regression-test-5258

Conversation

@markselby9
Copy link
Copy Markdown
Contributor

Summary

Adds a regression test for #5258: when a query selects a plural linked field on both a concrete type AND an abstract InlineFragment at the same selection level, MockPayloadGenerator.generate produces a nested-array payload ([[edge, edge, edge], [edge, edge, edge], [edge, edge, edge]]) instead of the expected flat [edge, edge, edge] shape, with __typename/cursor properties also bolted onto each Array instance.

The test asserts current (buggy) behavior so it flips when the underlying bug is fixed — same pattern as #5268 and #5269.

Notes

  • The test hand-constructs the ConcreteRequest AST rather than using a graphql template literal. The OSS test schema doesn't naturally model the concrete-vs-abstract divergent-return-type pattern that triggers this bug (every plural field returning an interface returns the same [Actor] from both interface and implementer, so the compiler dedupes the selections). I tried a schema extension adding interface AbstractConnection { edges: [AbstractEdge] } + type ConcreteConnection implements AbstractConnection { edges: [ConcreteEdge] }, but the relay compiler folds the abstract InlineFragment when the parent field's static type pins the abstract narrowing. Happy to revisit if you have a preferred path; the test header documents this attempt so future contributors don't re-tread it.
  • The test only covers the array-shape symptom; the issue's Root Cause Analysis Typo in docs #3 (__typename override on the abstract path) is a separate adjacent symptom and is explicitly out of scope here.

Test plan

  • yarn jest RelayMockPayloadGenerator — full file passes (69 tests)
  • yarn lint on the test file — clean
  • Verified the assertion locks down both the nested-array shape and the bolted-on __typename/cursor properties via deep toEqual

Refs #5258

markselby9 added 2 commits May 6, 2026 11:33
…stract InlineFragment (facebook#5258)

Adds a regression test in RelayMockPayloadGenerator-test.js demonstrating
the bug reported in facebook#5258: when a query field returns a concrete type and
the same plural linked field is selected both directly (concrete path) and
via a fragment spread on an interface the concrete type implements (abstract
path), MockPayloadGenerator produces a nested-array shape
[[e1,e2,e3], [e1,e2,e3], ...] instead of a flat [e1, e2, e3].

Root cause (per the issue): _traverseSelections processes the concrete
LinkedField and the abstract InlineFragment sequentially. On the second
pass, _mockLink reads the already-generated array out of
data[applicationName] and passes the whole array as prevData to each new
element generated by generateMockList.

The OSS test schema does not naturally model a concrete-vs-abstract
return-type divergence on the same field name (the compiler dedupes the
two selections when types match), so this test mirrors the issue's
"Standalone Reproduction Script" and hand-constructs a ConcreteRequest
matching the AST shape from the issue body. MockPayloadGenerator.generate
walks the AST and does not consult a schema, so the type names need not
exist in the test schema.

Test asserts current (buggy) behavior. The fix is left to the maintainer;
flip the assertion when the underlying bug is fixed.

Refs facebook#5258.
Address review feedback on the regression test:

- Replace weak `Array.isArray(edges[i])` checks with a strict
  structural assertion of the exact buggy payload — three copies of
  the original edges array, each Array instance also carrying the
  abstract path's `__typename`/`cursor` properties bolted on. Likely
  partial fixes (collapsed nested arrays, single-edge-wrapped
  elements, missing properties) now break the test loudly instead of
  silently passing.
- Rename test to `BUG: produces nested-array shape instead of a flat
  array (facebook#5258)` so the name reads as a bug record, matching the
  sibling `(facebook#5119)` style.
- Add a scope note acknowledging that the issue's "Root Cause
  Analysis" point facebook#3 (`mockData[TYPENAME_KEY] = selection.type`
  forcing abstract type onto already-generated concrete data) is a
  separate symptom not asserted here.
- Note in the header that a schema-extension prototype was tried —
  the OSS compiler folded the abstract InlineFragment because the
  parent field's static type pinned the narrowing — explaining why
  the hand-constructed AST is retained.
@meta-cla meta-cla Bot added the CLA Signed label May 6, 2026
@markselby9
Copy link
Copy Markdown
Contributor Author

Closing for now — I want to verify the compiler actually emits the AST shape this test asserts before adding to the review queue. Following up on #5258 to ask for a compiler-generated artifact, will revisit once that's in hand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant