Skip to content

feat: add experimental support for parsing fragment arguments - #4015

Merged
JoviDeCroock merged 5 commits into
graphql:mainfrom
JoviDeCroock:fragment-args-syntax-2024
Sep 6, 2024
Merged

feat: add experimental support for parsing fragment arguments#4015
JoviDeCroock merged 5 commits into
graphql:mainfrom
JoviDeCroock:fragment-args-syntax-2024

Conversation

@JoviDeCroock

@JoviDeCroock JoviDeCroock commented Jan 26, 2024

Copy link
Copy Markdown
Contributor

This is a rebase of #3847

This implements execution of Fragment Arguments, and more specifically visiting, parsing and printing of fragment-spreads with arguments and fragment definitions with variables, as described by the spec changes in graphql/graphql-spec#1081. There are a few amendments in terms of execution and keying the fragment-spreads, these are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts, the stacked PR's will contain mentions of open feedback that was present at the time.

CC @mjmahone the original author

@netlify

netlify Bot commented Jan 26, 2024

Copy link
Copy Markdown

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit 5a16135
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/66d888218ec45f00089701e1
😎 Deploy Preview https://deploy-preview-4015--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mjmahone mjmahone left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for rebasing the syntax changes! This looks correct to me.

I'm not sure whether we need the full stack of changes up before merging any of the changes: I'd be surprised if the syntax changes need to be modified due to the validation or execution changes.

This update is probably worth bringing to the graphql-wg this week: https://github.com/graphql/graphql-wg/blob/main/agendas/2024/02-Feb/01-wg-primary.md

@github-actions

Copy link
Copy Markdown

Hi @JoviDeCroock, I'm @github-actions bot happy to help you with this PR 👋

Supported commands

Please post this commands in separate comments and only one per comment:

  • @github-actions run-benchmark - Run benchmark comparing base and merge commits for this PR
  • @github-actions publish-pr-on-npm - Build package from this PR and publish it on NPM

@JoviDeCroock

Copy link
Copy Markdown
Contributor Author

@mjmahone worth bringing up that the PR is up, or should that be for the graphql-js wg? Not entirely sure 😅

@JoviDeCroock

Copy link
Copy Markdown
Contributor Author

CC @graphql/graphql-js-reviewers

@kitten

kitten commented Jan 30, 2024

Copy link
Copy Markdown

The implementation in this branch passes tests but uses UNSET. However, there's an alternative here: JoviDeCroock@1ee3f42, which has some updated tests.

Basically, the spec proposal uses CoerceArgumentValues (which itself is used in CoerceFieldArgumentValues, which isn't reflected in graphql-js since the spec conflates two different data structures), which is in turn used in ArgumentsFromSpread.

The spec then uses versions of spreadArgumentValues / argumentValues, i.e. a version of “variables” only for the fragment variable definitions, and keeps the variableValues separate. Since CoerceArgumentValues is reused, we should raise an error in CollectFields (via the former) for invalid values (e.g. undefined on non-defaulting non-null fields), which is reflected in the linked commit.

@mjmahone

Copy link
Copy Markdown
Contributor

worth bringing up that the PR is up, or should that be for the graphql-js wg?

I think it's worth adding a 5-10 minute dicussion item to the WG meeting this thursday https://github.com/graphql/graphql-wg/blob/main/agendas/2024/02-Feb/01-wg-primary.md

@mjmahone

Copy link
Copy Markdown
Contributor

The implementation in this branch passes tests but uses UNSET. However, there's an alternative here: JoviDeCroock@1ee3f42, which has some updated tests.

I don't think that is true anymore? I think @JoviDeCroock removed all the UNSET hacks from this PR (they might still exist in the executor changes). It also looks like graphql-js #4015 no longer uses the UNSET hack.

We should definitely ship the graphql-js changes that most closely match the changes to the spec itself, and the UNSET hack does not match the spec changes from Spec #1081 , but this looks like the parser changes are in a reasonably good state right now to my eyes!

@JoviDeCroock

JoviDeCroock commented Feb 27, 2024

Copy link
Copy Markdown
Contributor Author

@mjmahone yeah it doesn't use it it's just the parser. The execution PR also uses the new spec text

@JoviDeCroock

Copy link
Copy Markdown
Contributor Author

@graphql/graphql-js-reviewers is there anything missing to move this and the linked PR's forward?

@nandorojo

Copy link
Copy Markdown

So excited for this! Let me know if you want any help testing it in a real app.

@JoviDeCroock

JoviDeCroock commented Jul 21, 2024

Copy link
Copy Markdown
Contributor Author

Would this PR be better served being aimed at the 16.x.x branch? Not sure how the release schedule of this would work. If so how do we handle the existing option this._options.allowLegacyFragmentVariables

Comment thread src/language/parser.ts Outdated
Comment thread src/language/printer.ts
@yaacovCR yaacovCR added the PR: feature 🚀 requires increase of "minor" version number label Aug 19, 2024
@JoviDeCroock
JoviDeCroock force-pushed the fragment-args-syntax-2024 branch 3 times, most recently from 839284d to 3918bb5 Compare August 20, 2024 14:44
Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
@yaacovCR

Copy link
Copy Markdown
Contributor

Submitted some suggestions to the TypeInfo/Validation portion over at JoviDeCroock#12 => While working through that and thinking about the linked original review comments (https://github.com/graphql/graphql-js/pull/3835/files#r1101008869), I am tending to think we should make Fragment Arguments a separate Kind.

Basically, with my suggestions as the starting off point, anyone who has a Kind.ARGUMENT visitor in place could be visiting a field/directive argument or a fragment spread argument. You can distinguish by calling context.getArgument() which will return the argument definition for field/directive arguments, otherwise undefined, or context.getFragmentSignature() which will return the fragment signature if in a fragment spread argument, otherwise undefined.

Code within custom rules that do not know about fragment arguments will interpret the undefined result from context.getArgument() as a missing argument definition.

In the original version, we monkey-patch a schema argument definition from the fragment spread argument, so the argument will not appear missing, but then the visitor doesn't really know what it's visiting, and may actually do the wrong thing.

There does not yet appear to me to be a great backwards compatible fix for this, and so I suggest a separate Kind.FRAGMENT_ARGUMENT.

@yaacovCR

Copy link
Copy Markdown
Contributor

Motivation is only to preserve backwards compatibility for those not wishing to upgrade their visitors while fragment arguments are experimental. So another alternative is something in between, introduce a new Node now, maybe something like Kind.EXPERIMENTAL_FRAGMENT_ARGUMENT and then when fragment arguments are released, we would remove the EXPERIMENTAL and force everyone to upgrade their existing stuff (and force early adopters to integrate any custom visitors for both types of arguments).

yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Dec 17, 2025
…aphql#4180)

fixes up just merged graphql#4015

this was actually intended to be in graphql#4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Dec 17, 2025
…l#4015)

This is a rebase of graphql#3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Dec 17, 2025
…aphql#4180)

fixes up just merged graphql#4015

this was actually intended to be in graphql#4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Dec 19, 2025
…l#4015)

This is a rebase of graphql#3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Dec 19, 2025
…aphql#4180)

fixes up just merged graphql#4015

this was actually intended to be in graphql#4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Dec 22, 2025
…l#4015)

This is a rebase of graphql#3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Dec 22, 2025
…aphql#4180)

fixes up just merged graphql#4015

this was actually intended to be in graphql#4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit that referenced this pull request Dec 22, 2025
This is a rebase of #3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit that referenced this pull request Dec 22, 2025
)

fixes up just merged #4015

this was actually intended to be in #4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit that referenced this pull request Dec 22, 2025
This is a rebase of #3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit that referenced this pull request Dec 22, 2025
)

fixes up just merged #4015

this was actually intended to be in #4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Jan 27, 2026
…l#4015)

This is a rebase of graphql#3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Jan 27, 2026
…aphql#4180)

fixes up just merged graphql#4015

this was actually intended to be in graphql#4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit that referenced this pull request Feb 22, 2026
This is a rebase of #3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit that referenced this pull request Feb 22, 2026
)

fixes up just merged #4015

this was actually intended to be in #4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit that referenced this pull request Feb 23, 2026
This is a rebase of #3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit that referenced this pull request Feb 23, 2026
)

fixes up just merged #4015

this was actually intended to be in #4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit that referenced this pull request Feb 24, 2026
This is a rebase of #3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit that referenced this pull request Feb 24, 2026
)

fixes up just merged #4015

this was actually intended to be in #4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit that referenced this pull request Feb 24, 2026
This is a rebase of #3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit that referenced this pull request Feb 24, 2026
)

fixes up just merged #4015

this was actually intended to be in #4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit that referenced this pull request Feb 24, 2026
This is a rebase of #3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit that referenced this pull request Feb 24, 2026
)

fixes up just merged #4015

this was actually intended to be in #4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit that referenced this pull request Feb 24, 2026
This is a rebase of #3847

This implements execution of Fragment Arguments, and more specifically
visiting, parsing and printing of fragment-spreads with arguments and
fragment definitions with variables, as described by the spec changes in
graphql/graphql-spec#1081. There are a few
amendments in terms of execution and keying the fragment-spreads, these
are reflected in mjmahone/graphql-spec#3

The purpose is to be able to independently review all the moving parts,
the stacked PR's will contain mentions of open feedback that was present
at the time.

- [execution changes](JoviDeCroock#2)
- [TypeInfo & validation
changes](JoviDeCroock#4)
- [validation changes in
isolation](JoviDeCroock#5)

CC @mjmahone the original author

---------

Co-authored-by: mjmahone <mahoney.mattj@gmail.com>
Co-authored-by: Yaacov Rydzinski <yaacovCR@gmail.com>
yaacovCR added a commit that referenced this pull request Feb 24, 2026
)

fixes up just merged #4015

this was actually intended to be in #4015, but due to branch confusion
not originally included

now we also have a test!
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Jul 20, 2026
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 conform to the current spec proposal.

The 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 proposal takes the conservative approach of rejecting these cases.

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
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Jul 20, 2026
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
yaacovCR added a commit that referenced this pull request Jul 20, 2026
…#4839)

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:
#4015
yaacovCR added a commit to yaacovCR/graphql-js that referenced this pull request Jul 21, 2026
Bind fragment variables as compact scopes on the same selection-set graph, reject incompatible spread arguments before fieldless-root canonicalization, and share alpha-equivalent bound proofs.

Keep charging unweighted selection scans, field-set expansions, and new proofs as work. Replacing the fallback pairwise fragment comparisons with grouped bound proofs permits lowering the configurable default safety budget from 5,000 to 2,000 units while accepting substantially larger fragment-spread sets.

This builds on [the fragment arguments proposal](graphql/graphql-spec#1224) and [its GraphQL.js implementation](graphql#4015).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: feature 🚀 requires increase of "minor" version number

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants