Skip to content

fix(OverlappingFieldsCanMergeRule): require same variable definitions - #4839

Merged
yaacovCR merged 1 commit into
graphql:17.x.xfrom
yaacovCR:fix/overlapping-fields-can-be-merged
Jul 20, 2026
Merged

yaacovCR merged 1 commit into
graphql:17.x.xfrom
yaacovCR:fix/overlapping-fields-can-be-merged

Conversation

@yaacovCR

Copy link
Copy Markdown
Contributor

The initial v17 release included validation of fragment arguments using an earlier, rejected version of the field selection merging rules. This PR updates fragment arguments validation to the current spec proposal.

The current spec proposal intentionally requires variables in otherwise identical arguments to refer to the same variable definition. Following argument values through fragment spreads could allow more documents, but it makes the logic for determining whether arguments are the same significantly more complex. The current fragment arguments proposal takes the conservative approach of rejecting these cases.

For example, these fields appear to use the same operation variable:

query Example($size: Int!) {
  user {
    image(size: $size)
    ...Image(size: $size)
  }
}

fragment Image($size: Int!) on User {
  image(size: $size)
}

The first field uses the operation variable, while the field in Image uses the fragment variable. Treating them as equal requires resolving the spread argument before comparing the fields.

A literal may also match a fragment variable default:

query Example {
  user {
    image(size: 10)
    ...Image
  }
}

fragment Image($size: Int = 10) on User {
  image(size: $size)
}

Treating these fields as equal requires applying the omitted fragment argument default during field selection merging.

Bindings may also pass through several fragments:

query Example($size: Int!) {
  user {
    image(size: $size)
    ...Outer(size: $size)
  }
}

fragment Outer($size: Int!) on User {
  ...Image(size: $size)
}

fragment Image($size: Int!) on User {
  image(size: $size)
}

Treating these fields as equal requires following the operation variable through both fragment variable definitions.

Allowing these cases means a fragment cannot be checked on its own. The validator must carry variable bindings into each spread, apply defaults, follow bindings through nested fragments, cache the same fragment separately for different bindings, and handle cycles while doing so. Whether two arguments are the same then depends on the full path to the fragment.

Requiring the same variable definition keeps the check local. Variables are compared by their definition rather than by tracing the values passed to them. The stricter rule can also be relaxed later without invalidating documents that are already valid, but v17 incorrectly released the more lenient rule despite the currently stricter stance within the specification.

References:

The initial v17 release included validation of fragment arguments using an earlier, rejected version of the field selection merging rules. This PR updates fragment arguments validation to the current spec proposal.

The current spec proposal intentionally requires variables in otherwise identical arguments to refer to the same variable definition. Following argument values through fragment spreads could allow more documents, but it makes the logic for determining whether arguments are the same significantly more complex. The current fragment arguments proposal takes the conservative approach of rejecting these cases.

For example, these fields appear to use the same operation variable:

```graphql
query Example($size: Int!) {
  user {
    image(size: $size)
    ...Image(size: $size)
  }
}

fragment Image($size: Int!) on User {
  image(size: $size)
}
```

The first field uses the operation variable, while the field in `Image` uses the fragment variable. Treating them as equal requires resolving the spread argument before comparing the fields.

A literal may also match a fragment variable default:

```graphql
query Example {
  user {
    image(size: 10)
    ...Image
  }
}

fragment Image($size: Int = 10) on User {
  image(size: $size)
}
```

Treating these fields as equal requires applying the omitted fragment argument default during field selection merging.

Bindings may also pass through several fragments:

```graphql
query Example($size: Int!) {
  user {
    image(size: $size)
    ...Outer(size: $size)
  }
}

fragment Outer($size: Int!) on User {
  ...Image(size: $size)
}

fragment Image($size: Int!) on User {
  image(size: $size)
}
```

Treating these fields as equal requires following the operation variable through both fragment variable definitions.

Allowing these cases means a fragment cannot be checked on its own. The validator must carry variable bindings into each spread, apply defaults, follow bindings through nested fragments, cache the same fragment separately for different bindings, and handle cycles while doing so. Whether two arguments are the same then depends on the full path to the fragment.

Requiring the same variable definition keeps the check local. Variables are compared by their definition rather than by tracing the values passed to them. The stricter rule can also be relaxed later without invalidating documents that are already valid, but v17 incorrectly released the more lenient rule despite the currently stricter stance within the specification.

References:
- Current fragment arguments proposal: graphql/graphql-spec#1224
- Earlier (now-closed) fragment arguments proposal: graphql/graphql-spec#1081
- Benjie's rationale for the conservative validation rule: graphql/graphql-spec#1081 (comment)
- Benjie's follow-up PR updating the proposal: JoviDeCroock/graphql-spec#2
- Proposal commit requiring references to the same variable definition: graphql/graphql-spec@6659416
- Initial GraphQL.js fragment arguments implementation: graphql#4015
@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

@yaacovCR is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@yaacovCR yaacovCR changed the title fix fragment arguments validation fix(OverlappingFieldsCanMerge): require same variable definitions Jul 20, 2026
@yaacovCR yaacovCR added the PR: bug fix 🐞 requires increase of "patch" version number label Jul 20, 2026
@yaacovCR yaacovCR changed the title fix(OverlappingFieldsCanMerge): require same variable definitions fix(OverlappingFieldsCanMergeRule): require same variable definitions Jul 20, 2026
@yaacovCR
yaacovCR merged commit c31db12 into graphql:17.x.x Jul 20, 2026
23 of 24 checks passed
@yaacovCR
yaacovCR deleted the fix/overlapping-fields-can-be-merged branch July 20, 2026 21:03
@yaacovCR yaacovCR mentioned this pull request Nov 4, 2026
yaacovCR added a commit that referenced this pull request Nov 4, 2026
## v17.1.0 (2026-11-04)

#### New Feature 🚀
* [#4852](#4852) spec change: allow empty selection sets ([@martinbonnin](https://github.com/martinbonnin))
* [#4905](#4905) feat: add maxComments parser option ([@yaacovCR](https://github.com/yaacovCR))
* [#4906](#4906) feat: add maxSourceLength parser option ([@yaacovCR](https://github.com/yaacovCR))
* [#4950](#4950) feat: configure list type nesting in the parser ([@yaacovCR](https://github.com/yaacovCR))
* [#4953](#4953) feat: configure printer indentation depth ([@yaacovCR](https://github.com/yaacovCR))

#### Bug Fix 🐞
* [#4837](#4837) fix(VariablesInAllowedPositionRule): allow fragments with variables prior to operations ([@yaacovCR](https://github.com/yaacovCR))
* [#4838](#4838) fix(DeferStreamDirectiveOnRootFieldRule): handle fragment cycles ([@yaacovCR](https://github.com/yaacovCR))
* [#4839](#4839) fix(OverlappingFieldsCanMergeRule): require same variable definitions ([@yaacovCR](https://github.com/yaacovCR))
* [#4853](#4853) fix(OverlappingFieldsCanMerge): fix var scope for fragment comparison cache ([@yaacovCR](https://github.com/yaacovCR))
* [#4841](#4841) Skip deferred fragments in collectFields only when same directive is used ([@robrichard](https://github.com/robrichard))
* [#4859](#4859) test(incremental): document bugs in shared deferred work ([@duckki](https://github.com/duckki))
* [#4868](#4868) fix(incremental): prevent lost or delayed successful shared results ([@yaacovCR](https://github.com/yaacovCR))
* [#4869](#4869) fix(incremental): prevent error completions for unannounced fragments ([@yaacovCR](https://github.com/yaacovCR))
* [#4865](#4865) fix(validation): keep argument defaults inside fragments ([@SashaMIT](https://github.com/SashaMIT))
* [#4879](#4879) fix(validation): keep collected fields separate by parent type ([@yaacovCR](https://github.com/yaacovCR))
* [#4895](#4895) fix(validation): bound conflict descriptions ([@yaacovCR](https://github.com/yaacovCR))
* [#4896](#4896) fix(validation): bound nested conflict locations ([@yaacovCR](https://github.com/yaacovCR))
* [#4898](#4898) perf(validation): prepare fragment spreads only for comparisons ([@yaacovCR](https://github.com/yaacovCR))
* [#4897](#4897) feat(validation): limit overlapping field complexity ([@yaacovCR](https://github.com/yaacovCR))
* [#4903](#4903) fix: rename maxTokens to maxLexicalTokens ([@yaacovCR](https://github.com/yaacovCR))
* [#4904](#4904) memoize pathToArray to reduce memory for multiple defers at the same path ([@robrichard](https://github.com/robrichard))
* [#4908](#4908) fix: pass parser options through buildSchema ([@yaacovCR](https://github.com/yaacovCR))
* [#4916](#4916) fix: bound shared fragment traversal in introspection validation ([@yaacovCR](https://github.com/yaacovCR))
* [#4929](#4929) fix: initialize subscription validation variables ([@yaacovCR](https://github.com/yaacovCR))
* [#4937](#4937) fix: skip disabled argument suggestions ([@yaacovCR](https://github.com/yaacovCR))
* [#4946](#4946) refactor: track fragment validation work ([@yaacovCR](https://github.com/yaacovCR))
* [#4949](#4949) refactor: account for subscription field collection ([@yaacovCR](https://github.com/yaacovCR))
* [#4951](#4951) refactor: account for field return type comparisons ([@yaacovCR](https://github.com/yaacovCR))
* [#4915](#4915) fix: align minified source location at chunk boundaries ([@fallintoplace](https://github.com/fallintoplace))
* [#4977](#4977) fix: keep minified EOF carets after the final character ([@yaacovCR](https://github.com/yaacovCR))
* [#4979](#4979) fix: reference ESM source maps from every emitted module ([@yaacovCR](https://github.com/yaacovCR))
* [#4980](#4980) fix: identify ESM modules in source map metadata ([@yaacovCR](https://github.com/yaacovCR))
* [#4983](#4983) fix: avoid inherited variable getters in nested literal values ([@yaacovCR](https://github.com/yaacovCR))

#### Docs 📝
<details>
<summary> 4 PRs were merged </summary>

* [#4986](#4986) docs: refresh the v16 and v17 API references ([@yaacovCR](https://github.com/yaacovCR))
* [#4987](#4987) docs: render constructor examples in the API reference ([@yaacovCR](https://github.com/yaacovCR))
* [#4988](#4988) docs: generate API reference during website builds ([@yaacovCR](https://github.com/yaacovCR))
* [#4989](#4989) docs: list v17 first in the API sidebar ([@yaacovCR](https://github.com/yaacovCR))
</details>

#### Polish 💅
<details>
<summary> 69 PRs were merged </summary>

* [#4836](#4836) refactor: add map keyed by set membership ([@yaacovCR](https://github.com/yaacovCR))
* [#4843](#4843) polish(OverlappingFieldsCanMerge: add tests documenting existing behavior ([@yaacovCR](https://github.com/yaacovCR))
* [#4855](#4855) refactor(validation): add overlapping fields rule context ([@yaacovCR](https://github.com/yaacovCR))
* [#4856](#4856) refactor(validation): name the variable map type ([@yaacovCR](https://github.com/yaacovCR))
* [#4857](#4857) polish(validation): skip empty field comparisons ([@yaacovCR](https://github.com/yaacovCR))
* [#4851](#4851) test: accept non-null union implementing a nullable union ([@jayphelps](https://github.com/jayphelps))
* [#4845](#4845) polish(validateInputValue): cover invalid values in iterable input ([@vrana055](https://github.com/vrana055))
* [#4844](#4844) polish(introspection): cover __Type.description on wrapping types ([@vrana055](https://github.com/vrana055))
* [#4860](#4860) docs: fix incorrect API doc examples and copy-pasted descriptions ([@Cito](https://github.com/Cito))
* [#4867](#4867) refactor(incremental): extract maybeFinishGroup ([@yaacovCR](https://github.com/yaacovCR))
* [#4871](#4871) refactor(validation): rename NodeAndDef to FieldDetails ([@yaacovCR](https://github.com/yaacovCR))
* [#4872](#4872) refactor(validation): name field detail lists ([@yaacovCR](https://github.com/yaacovCR))
* [#4873](#4873) refactor(validation): rename NodeAndDefCollection to GroupedFieldSet ([@yaacovCR](https://github.com/yaacovCR))
* [#4874](#4874) refactor(validation): align field collection names with execution ([@yaacovCR](https://github.com/yaacovCR))
* [#4875](#4875) refactor(validation): convert FieldDetails tuples to objects ([@yaacovCR](https://github.com/yaacovCR))
* [#4876](#4876) refactor(validation): convert CollectFieldsResult tuples to objects ([@yaacovCR](https://github.com/yaacovCR))
* [#4877](#4877) refactor(validation): convert conflict tuples to objects ([@yaacovCR](https://github.com/yaacovCR))
* [#4878](#4878) refactor(validation): make unordered pair lookup independent of key order ([@yaacovCR](https://github.com/yaacovCR))
* [#4880](#4880) refactor(validation): rename VariableMap to VariableScope ([@yaacovCR](https://github.com/yaacovCR))
* [#4881](#4881) perf(validation): share field collections across scopes ([@yaacovCR](https://github.com/yaacovCR))
* [#4882](#4882) refactor(validation): check stream overlap in findConflict ([@yaacovCR](https://github.com/yaacovCR))
* [#4883](#4883) perf(validation): prepare field comparison data together ([@yaacovCR](https://github.com/yaacovCR))
* [#4885](#4885) perf(validation): reuse scope maps across equivalent fragment spreads ([@yaacovCR](https://github.com/yaacovCR))
* [#4886](#4886) refactor(validation): compare value structure directly ([@yaacovCR](https://github.com/yaacovCR))
* [#4888](#4888) refactor(validation): compare variable scope identities ([@yaacovCR](https://github.com/yaacovCR))
* [#4889](#4889) perf(validation): cache field-pair source comparisons ([@yaacovCR](https://github.com/yaacovCR))
* [#4890](#4890) perf(validation): cache source value preparation ([@yaacovCR](https://github.com/yaacovCR))
* [#4891](#4891) perf(validation): cache value scope dependencies ([@yaacovCR](https://github.com/yaacovCR))
* [#4892](#4892) perf(validation): cache source fragment spread preparation ([@yaacovCR](https://github.com/yaacovCR))
* [#4893](#4893) perf(validation): reuse matching response groups across scopes ([@yaacovCR](https://github.com/yaacovCR))
* [#4894](#4894) perf(validation): skip redundant inline selection-set checks ([@yaacovCR](https://github.com/yaacovCR))
* [#4902](#4902) perf: avoid repeated SetMap key construction ([@yaacovCR](https://github.com/yaacovCR))
* [#4920](#4920) perf: reuse fragment dependencies across operations ([@yaacovCR](https://github.com/yaacovCR))
* [#4921](#4921) perf: reuse fragment variable usages ([@yaacovCR](https://github.com/yaacovCR))
* [#4925](#4925) perf: share fragment collection across operations ([@yaacovCR](https://github.com/yaacovCR))
* [#4926](#4926) refactor: use context fragment lookups in directive validation ([@yaacovCR](https://github.com/yaacovCR))
* [#4927](#4927) perf: share subscription fragment lookups ([@yaacovCR](https://github.com/yaacovCR))
* [#4931](#4931) perf: reuse subscription directive paths ([@yaacovCR](https://github.com/yaacovCR))
* [#4932](#4932) perf: reuse introspection fragment checks ([@yaacovCR](https://github.com/yaacovCR))
* [#4933](#4933) perf: share completed directive checks ([@yaacovCR](https://github.com/yaacovCR))
* [#4935](#4935) test: cover source location lookups ([@yaacovCR](https://github.com/yaacovCR))
* [#4936](#4936) perf: share source location lookups ([@yaacovCR](https://github.com/yaacovCR))
* [#4938](#4938) perf: reuse required fragment arguments ([@yaacovCR](https://github.com/yaacovCR))
* [#4939](#4939) perf: remove an extra list item type check ([@yaacovCR](https://github.com/yaacovCR))
* [#4940](#4940) perf: reuse identical field return types ([@yaacovCR](https://github.com/yaacovCR))
* [#4941](#4941) perf: reuse field return type names ([@yaacovCR](https://github.com/yaacovCR))
* [#4942](#4942) perf: index directive argument names ([@yaacovCR](https://github.com/yaacovCR))
* [#4943](#4943) perf: index directive locations ([@yaacovCR](https://github.com/yaacovCR))
* [#4944](#4944) perf: reuse field return type descriptions ([@yaacovCR](https://github.com/yaacovCR))
* [#4945](#4945) perf: reuse supported AST kinds ([@yaacovCR](https://github.com/yaacovCR))
* [#4947](#4947) refactor: extract visitSelectionSets ([@yaacovCR](https://github.com/yaacovCR))
* [#4948](#4948) refactor: simplify referenced fragment collection ([@yaacovCR](https://github.com/yaacovCR))
* [#4952](#4952) refactor: stream printer output ([@yaacovCR](https://github.com/yaacovCR))
* [#4956](#4956) perf: skip unused argument lookup preparation ([@yaacovCR](https://github.com/yaacovCR))
* [#4957](#4957) perf: skip required argument preparation for argument-free fields ([@yaacovCR](https://github.com/yaacovCR))
* [#4958](#4958) perf: scan single source locations directly ([@yaacovCR](https://github.com/yaacovCR))
* [#4959](#4959) perf: store visitor edits in a flat array ([@yaacovCR](https://github.com/yaacovCR))
* [#4960](#4960) perf: skip selection sets with no fields to compare ([@yaacovCR](https://github.com/yaacovCR))
* [#4961](#4961) perf: allocate visitor edits only when needed ([@yaacovCR](https://github.com/yaacovCR))
* [#4963](#4963) perf: reuse the visitor array check ([@yaacovCR](https://github.com/yaacovCR))
* [#4964](#4964) perf: skip pair metadata for compatible leaf fields ([@yaacovCR](https://github.com/yaacovCR))
* [#4965](#4965) perf: prepare type name lookups only when needed ([@yaacovCR](https://github.com/yaacovCR))
* [#4972](#4972) perf: flatten input-value printing ([@yaacovCR](https://github.com/yaacovCR))
* [#4973](#4973) perf: avoid arrays for single-line printer text ([@yaacovCR](https://github.com/yaacovCR))
* [#4974](#4974) perf: assemble printer output as a string ([@yaacovCR](https://github.com/yaacovCR))
* [#4975](#4975) perf: skip empty printer work ([@yaacovCR](https://github.com/yaacovCR))
* [#4976](#4976) perf: add a minimal AST reducer for printing ([@yaacovCR](https://github.com/yaacovCR))
* [#4971](#4971) perf: reuse fragment checks from fields exceeding the introspection depth ([@Cito](https://github.com/Cito))
* [#4982](#4982) revert: remove maxListDepth from #4950 for now ([@yaacovCR](https://github.com/yaacovCR))
</details>

#### Internal 🏠
<details>
<summary> 13 PRs were merged </summary>

* [#4884](#4884) ci: use a stable language-based CodeQL category ([@yaacovCR](https://github.com/yaacovCR))
* [#4887](#4887) ci: run CodeQL in a dedicated workflow ([@yaacovCR](https://github.com/yaacovCR))
* [#4907](#4907) test: execute JSDoc API examples with Node ([@yaacovCR](https://github.com/yaacovCR))
* [#4912](#4912) internal: robustify examples test runner ([@yaacovCR](https://github.com/yaacovCR))
* [#4928](#4928) ci: shard integration tests across eight jobs ([@yaacovCR](https://github.com/yaacovCR))
* [#4954](#4954) ci: retire Node.js 25 ([@yaacovCR](https://github.com/yaacovCR))
* [#4955](#4955) ci: test Node.js 27 prereleases ([@yaacovCR](https://github.com/yaacovCR))
* [#4967](#4967) fix: accept zero-byte benchmark memory samples ([@yaacovCR](https://github.com/yaacovCR))
* [#4968](#4968) fix: collect warmup garbage before benchmark memory samples ([@yaacovCR](https://github.com/yaacovCR))
* [#4970](#4970) benchmark: cover schema document printing ([@yaacovCR](https://github.com/yaacovCR))
* [#4969](#4969) fix: use cumulative allocation counters in memory benchmarks ([@yaacovCR](https://github.com/yaacovCR))
* [#4978](#4978) build: remove the obsolete development entry point ([@yaacovCR](https://github.com/yaacovCR))
* [#4981](#4981) internal: further improve example test runner ([@yaacovCR](https://github.com/yaacovCR))
</details>

#### Committers: 9
* Christoph Zwerschke([@Cito](https://github.com/Cito))
* Duckki Oe([@duckki](https://github.com/duckki))
* Jay Phelps([@jayphelps](https://github.com/jayphelps))
* Martin Bonnin([@martinbonnin](https://github.com/martinbonnin))
* Minh Vu([@fallintoplace](https://github.com/fallintoplace))
* Rob Richard([@robrichard](https://github.com/robrichard))
* Sash([@SashaMIT](https://github.com/SashaMIT))
* Vibhanshu Rana([@vrana055](https://github.com/vrana055))
* Yaacov Rydzinski ([@yaacovCR](https://github.com/yaacovCR))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: bug fix 🐞 requires increase of "patch" version number

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant