Skip to content

feat: support variable arguments in @requires field sets#3448

Open
jeffutter wants to merge 1 commit into
apollographql:mainfrom
jeffutter:requires-field-argument-variables
Open

feat: support variable arguments in @requires field sets#3448
jeffutter wants to merge 1 commit into
apollographql:mainfrom
jeffutter:requires-field-argument-variables

Conversation

@jeffutter

@jeffutter jeffutter commented Jun 9, 2026

Copy link
Copy Markdown

@requires(fields: "...") previously only accepted static literal argument values for required fields that take arguments — there was no way to pass a per-request value (e.g. an end user's currency) through to the subgraph that owns the required field. This adds support for referencing the annotated field's own arguments as bare $arg variables, e.g.:

price(currency: Currency!) @external
localizedPrice(currency: Currency!): Money @requires(fields: "price(currency: $currency)")

A @requires field set may now reference one of the annotated field's own arguments as a variable. At query planning time, the value the operation supplies for that argument is threaded into the subgraph that owns the required field: an operation variable is forwarded, a literal is inlined, and an omitted argument resolves to its schema default or null.

Variables are kept symbolic through parsing, composition, and query-graph building, and are only bound to concrete values during query planning. Composition rejects unbound variables, type-incompatible bindings, and any variable used in a @provides field set.

Fixes: apollographql/router#9583
Mirrors: apollographql/router#9604
Relates to:

Note:

👋 Hi folks. I've done my best here to make sure these changes are accurate and reasonable. I'm obviously not an expert in this codebase - I've tried to adopt the style of surrounding code and consider maintainability in my implementation. That said I'm sure folks closer to the codebase will have opinions here. I'm glad to make any updates you see fit, even if it's heading back to the drawing board to approach this from a different angle.

@jeffutter
jeffutter requested a review from a team as a code owner June 9, 2026 21:31
@apollo-librarian

apollo-librarian Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ AI Style Review — 7 Issues Found

Summary

The pull request updates the documentation to align with several style guide sections. In 'structural-elements', punctuation was removed from list fragments. Under 'voice' and 'verb-tense-and-voice', the tone was updated to be more authoritative and prescriptive using the present tense. 'Word-and-symbol-usage' now includes standard contractions and consistent naming conventions for 'the Router'. Language and framing improvements were made to ensure proper article usage and a professional, reader-focused perspective. Finally, 'text-formatting' and 'products-and-features' updates ensure 'Router' is correctly styled as code when referring to components and treated as a standalone product name.

Duration: 4839ms
Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 02481f1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@apollo/federation-internals Minor
@apollo/composition Minor
@apollo/query-planner Minor
@apollo/gateway Minor
@apollo/query-graphs Minor
@apollo/subgraph Minor
apollo-federation-integration-testsuite Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jeffutter
jeffutter force-pushed the requires-field-argument-variables branch 2 times, most recently from 0402698 to 9afb650 Compare June 9, 2026 21:55
`@requires(fields: "...")` previously only accepted static literal argument
values for required fields that take arguments — there was no way to pass a
per-request value (e.g. an end user's currency) through to the subgraph that
owns the required field. This adds support for referencing the annotated
field's own arguments as bare `$arg` variables, e.g.:

```
localizedPrice(currency: Currency!): Money
  @requires(fields: "price(currency: $currency)")
```

A @requires field set may now reference one of the annotated field's own
arguments as a variable. At query planning time, the value the operation
supplies for that argument is threaded into the subgraph that owns the
required field: an operation variable is forwarded, a literal is inlined,
and an omitted argument resolves to its schema default or null.

Variables are kept symbolic through parsing, composition, and query-graph
building, and are only bound to concrete values during query planning.
Composition rejects unbound variables, type-incompatible bindings, and any
variable used in a @provides field set.
@jeffutter
jeffutter force-pushed the requires-field-argument-variables branch from 9afb650 to 02481f1 Compare June 9, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support variables in @requires directives

1 participant