Skip to content

Fragment arguments - needs champion - #1224

Open
benjie wants to merge 54 commits into
mainfrom
fragment-arguments
Open

Fragment arguments - needs champion#1224
benjie wants to merge 54 commits into
mainfrom
fragment-arguments

Conversation

@benjie

@benjie benjie commented Apr 15, 2026

Copy link
Copy Markdown
Member

See #1081 for more details

@benjie benjie added 👻 Needs Champion RFC Needs a champion to progress (See CONTRIBUTING.md) 📄 Draft (RFC 2) RFC Stage 2 (See CONTRIBUTING.md) labels Apr 15, 2026
@netlify

netlify Bot commented Apr 15, 2026

Copy link
Copy Markdown

Deploy Preview for graphql-spec-draft ready!

Name Link
🔨 Latest commit ef8aaa3
🔍 Latest deploy log https://app.netlify.com/projects/graphql-spec-draft/deploys/69dfb771811a960008680c66
😎 Deploy Preview https://deploy-preview-1224--graphql-spec-draft.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 project configuration.

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 to graphql/graphql-js 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

📄 Draft (RFC 2) RFC Stage 2 (See CONTRIBUTING.md) 👻 Needs Champion RFC Needs a champion to progress (See CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants