Add regression test for RelayResponseNormalizer @skip + multi-fragment warning (#5119)#5269
Open
markselby9 wants to merge 2 commits into
Open
Add regression test for RelayResponseNormalizer @skip + multi-fragment warning (#5119)#5269markselby9 wants to merge 2 commits into
markselby9 wants to merge 2 commits into
Conversation
…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.
9a8e188 to
dc90477
Compare
This was referenced May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a regression test in
RelayResponseNormalizer-test.jsfor 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 warningPayload 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
__typenameas the painful case ("especially difficult to debug"). The test usesfirstNameinstead — a__typenamevariant doesn't trigger the warning here because the parent selector... on Userrequiresnode.__typenameto be present in the payload, which short-circuits the warning path before it reaches the User fragments. The in-test comment explains whyfirstNameis 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_fixmebecause the compiler now requires aliases on duplicate selections; this matches the convention used elsewhere in the same file (e.g. the_pvFragmenttest).Refs #5119.
Notes for reviewer
__generated__/*.graphql.jsfiles. They were produced withrelay-compiler@0.0.0-main-38ad9e13(the published@20.1.1rejects fields the current OSS test config uses). The structure follows the standard codegen format; if the maintainer's internal compiler regenerates with trivial differences (SignedSourcehash, formatting), please regenerate as part of the import — happy to follow up if it causes any review friction.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.it()in the existingdescribe('RelayResponseNormalizer', ...)block, immediately after the existing'warns in __DEV__ if payload data is missing an expected field'test (sibling concept).Commits
const SkipFragment/const NoSkipFragmentassignments to satisfyeslint --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 passedRelayResponseNormalizer-test.jssuite still passes (61 total, was 60)yarn run lint packages/relay-runtime/store/__tests__/RelayResponseNormalizer-test.js— clean (0 warnings)