Skip to content

feat: override + requires#267

Merged
kamilkisiela merged 2 commits intomainfrom
kamil-override-requires
Feb 25, 2026
Merged

feat: override + requires#267
kamilkisiela merged 2 commits intomainfrom
kamil-override-requires

Conversation

@kamilkisiela
Copy link
Copy Markdown
Contributor

@kamilkisiela kamilkisiela commented Feb 24, 2026

Fix supergraph @join__field generation for @override + @requires combinations and add a progressive override restriction.


When a field with @requires is overridden, composition now ignores @requires usage coming only from the overridden source field when deciding whether to keep @join__field(..., external: true) or not.
This prevents stale external annotations in the supergraph, that breaks Apollo's Query Planning related logic - Apollo Gateway sees @external field that is not used by any @requires and throws.

Also, progressive override (@override(..., label: ...)) is now rejected when the overridden source field uses @requires (error code: OVERRIDE_COLLISION_WITH_ANOTHER_DIRECTIVE). Non-progressive override behavior is unchanged.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @kamilkisiela, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the GraphQL Federation composition logic to better handle the interplay between the @override and @requires directives. It resolves an issue where stale external annotations could persist in the supergraph after a field with @requires was overridden. Furthermore, it introduces a new validation to prevent progressive @override on fields that rely on @requires, ensuring more predictable and robust supergraph schema generation in complex migration scenarios.

Highlights

  • Improved Supergraph Generation for @OverRide + @requires: The composition engine now correctly ignores @requires usage coming only from an overridden source field when determining whether to keep @join__field(..., external: true), preventing stale external annotations in the supergraph.
  • Progressive Override Restriction: Progressive override (@override(..., label: ...)) is now rejected with an OVERRIDE_COLLISION_WITH_ANOTHER_DIRECTIVE error if the overridden source field uses @requires. Non-progressive override behavior remains unchanged.
  • Comprehensive Test Coverage: New test cases have been added to validate the updated composition logic for @override and @requires interactions, including deep @requires overrides and scenarios where external usage must be preserved.
Changelog
  • @theguild/federation-composition
    • Fix supergraph @join__field generation for @override + @requires migrations and add a progressive override restriction.
    • When a field with @requires is overridden, composition now ignores @requires usage coming only from the overridden source field when deciding whether to keep @join__field(..., external: true). This prevents stale external annotations in the supergraph.
    • Also, progressive override (@override(..., label: ...)) is now rejected when the overridden source field uses @requires (error code: OVERRIDE_COLLISION_WITH_ANOTHER_DIRECTIVE). Non-progressive override behavior is unchanged.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kamilkisiela kamilkisiela force-pushed the kamil-override-requires branch from 7c4d76b to e101e07 Compare February 24, 2026 15:28
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant improvements to the handling of @override and @requires directives in federation composition. The changes correctly prune stale external annotations and @join__type directives when a field with @requires is overridden. Additionally, a new validation rule is added to prevent progressive overrides on fields that have @requires in their source. The implementation is robust and well-tested.

I've identified a couple of areas where the logic could be extended to also cover interface types, ensuring complete correctness for all scenarios involving these directives. My review includes suggestions to address these points.

@kamilkisiela kamilkisiela marked this pull request as draft February 24, 2026 15:30
@kamilkisiela kamilkisiela marked this pull request as ready for review February 25, 2026 09:19
@kamilkisiela kamilkisiela requested a review from n1ru4l February 25, 2026 09:19
Copy link
Copy Markdown
Contributor

@n1ru4l n1ru4l left a comment

Choose a reason for hiding this comment

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

leggito

@kamilkisiela
Copy link
Copy Markdown
Contributor Author

mergetto, mi compadre

@kamilkisiela kamilkisiela merged commit 3e232fa into main Feb 25, 2026
3 of 4 checks passed
@kamilkisiela kamilkisiela deleted the kamil-override-requires branch February 25, 2026 11:16
kamilkisiela pushed a commit that referenced this pull request Feb 26, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @theguild/federation-composition@0.22.0

### Minor Changes

-
[#267](#267)
[`3e232fa`](3e232fa)
Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Fix
supergraph `@join__field` generation for `@override` + `@requires`
migrations and add a progressive override restriction.

When a field with `@requires` is overridden, composition now ignores
`@requires` usage coming only from the overridden source field when
deciding whether to keep `@join__field(..., external: true)`. This
prevents stale external annotations in the supergraph.

Also, progressive override (`@override(..., label: ...)`) is now
rejected when the overridden source field uses `@requires` (error code:
`OVERRIDE_COLLISION_WITH_ANOTHER_DIRECTIVE`). Non-progressive override
behavior is unchanged.

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
kamilkisiela added a commit that referenced this pull request Mar 16, 2026
…@requires` edge cases (#282)

Reproduced issues caused by #267 and added a few test cases to showcase
differences between Apollo's supergraph and ours.
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.

2 participants