Skip to content

Add regression test for RelayResponseNormalizer @skip + multi-fragment warning (#5119)#5269

Open
markselby9 wants to merge 2 commits into
facebook:mainfrom
markselby9:regression-test-5119
Open

Add regression test for RelayResponseNormalizer @skip + multi-fragment warning (#5119)#5269
markselby9 wants to merge 2 commits into
facebook:mainfrom
markselby9:regression-test-5119

Conversation

@markselby9
Copy link
Copy Markdown
Contributor

@markselby9 markselby9 commented May 1, 2026

Summary

Adds a regression test in RelayResponseNormalizer-test.js for the bug reported in #5119: when two fragments in the same query select the same field but only one of them gates the selection with @skip(if: $skip), the normalizer emits the warning Payload did not contain a value for field ... without identifying the originating query.

This is test-only — no production code changes, no improvement to the warning message format. The test asserts current (buggy) behavior; whoever fixes the underlying bug or improves the warning to include source-query attribution should flip the assertion.

The reporter called out __typename as the painful case ("especially difficult to debug"). The test uses firstName instead — a __typename variant doesn't trigger the warning here because the parent selector ... on User requires node.__typename to be present in the payload, which short-circuits the warning path before it reaches the User fragments. The in-test comment explains why firstName is path-equivalent: both traverse _normalizeField's scalar warning path with no abstract-type discrimination involved when the parent (User) is a concrete type.

The test reuses the existing convention from the file (expectToWarn, RelayRecordSource, createNormalizationSelector, disallowWarnings() in scope at the top). Both fragment spreads carry @dangerously_unaliased_fixme because the compiler now requires aliases on duplicate selections; this matches the convention used elsewhere in the same file (e.g. the _pvFragment test).

Refs #5119.

Notes for reviewer

  • Generated artifacts: the test introduces a new query and two new fragments, requiring 3 new __generated__/*.graphql.js files. They were produced with relay-compiler@0.0.0-main-38ad9e13 (the published @20.1.1 rejects fields the current OSS test config uses). The structure follows the standard codegen format; if the maintainer's internal compiler regenerates with trivial differences (SignedSource hash, formatting), please regenerate as part of the import — happy to follow up if it causes any review friction.
  • Test name is intentionally bug-leading ("warns without identifying source query…") rather than trigger-leading, so the regression intent is clear at a glance.
  • Assertion text is generic. The expectToWarn(...) matcher is the same generic missing-field warning the existing L2640 test exercises with a trivial single-fragment query. The regression value of this test is in the query/fragment shape (sibling fragments, one @skip-gated), not in the assertion text. When the underlying bug is fixed (either better source attribution OR no-warn-on-this-pattern), the assertion needs to be updated — please cross-reference this comment if doing so.
  • Scope discipline: single new it() in the existing describe('RelayResponseNormalizer', ...) block, immediately after the existing 'warns in __DEV__ if payload data is missing an expected field' test (sibling concept).

Commits

  • Commit 1: regression test + 3 generated artifacts
  • Commit 2: dropped unused const SkipFragment/const NoSkipFragment assignments to satisfy eslint --max-warnings 0 (the fragments are picked up by the compiler from the tagged template literal regardless of whether the value is assigned)

Test plan

  • yarn jest packages/relay-runtime/store/__tests__/RelayResponseNormalizer-test.js -t '5119' — 1 passed
  • full RelayResponseNormalizer-test.js suite still passes (61 total, was 60)
  • yarn run lint packages/relay-runtime/store/__tests__/RelayResponseNormalizer-test.js — clean (0 warnings)

@meta-cla meta-cla Bot added the CLA Signed label May 1, 2026
markselby9 added 2 commits May 2, 2026 11:03
…t Warning (facebook#5119)

Adds a regression test demonstrating the bug in facebook#5119: when two fragments
in the same query select the same field but only one of them gates the
selection with @Skip, the normalizer emits an unhelpful Warning
("Payload did not contain a value for field ..."). The Warning does
not identify the originating query, which makes this hard to debug
in real applications.

Test asserts current (buggy) behavior via expectToWarn. The fix
(or warning-message improvement) is left to the maintainer; flip
the assertion when the underlying bug is addressed.
CI feedback: the SkipFragment / NoSkipFragment const declarations
trip eslint's no-unused-vars rule (the relay-compiler picks up the
fragments via the tagged template literal regardless of whether
the value is assigned, and the fragments are referenced in the
query body via `...FragmentName`, not via the JS const).

Drop both `const X = ` prefixes — the graphql`...` calls now run
purely for their side effect of registering the fragment with the
compiler. Test continues to pass.
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