Skip to content

Fix @join__field emission for Fed v1 @external and @override+ @requires edge cases#284

Merged
n1ru4l merged 2 commits intokamilkisiela-patch-1from
kamil-fix
Mar 16, 2026
Merged

Fix @join__field emission for Fed v1 @external and @override+ @requires edge cases#284
n1ru4l merged 2 commits intokamilkisiela-patch-1from
kamil-fix

Conversation

@kamilkisiela
Copy link
Copy Markdown
Contributor

@kamilkisiela kamilkisiela commented Mar 10, 2026

This PR corrects supergraph's @join__field emission in a few edge cases where emitted metadata could be incorrect or redundant.

  • Use subgraph-local key usage when deciding whether to drop Federation v1 @join__field(external:true)
  • Avoid emitting redundant @join__field(external: true) metadata when a field is only required through overridden paths
  • Tighten @join__field emission around @override and interface type fields.

This aligns emitted supergraph metadata with Apollo Gateway's requirements.
Added Apollo supergraph validation in testkit to catch compatibility regressions earlier.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 refactors and enhances the supergraph composition process, specifically addressing how @override and @provides directives are handled. The changes aim to improve the accuracy and efficiency of supergraph generation by centralizing logic for @join__field emission and introducing new validation steps. This ensures that the composed supergraph correctly reflects the intended schema, particularly for complex federation scenarios involving field overrides and external fields.

Highlights

  • Supergraph Composition Refinement: Refactored the supergraph composition logic, specifically enhancing the handling of @override and @provides directives to ensure more accurate and efficient supergraph generation.
  • Federation v1 External Field Optimization: Introduced new logic to drop unused external fields in Federation v1 supergraphs, optimizing the generated SDL by removing redundant directives.
  • Enhanced Supergraph Validation: Integrated new validation steps using @apollo/federation-internals to detect and prevent composition issues earlier in the testing process.
  • Improved Test Coverage: Expanded test coverage for @override scenarios, including specific assertions for __typename handling and the correct emission of @join__field directives in the supergraph SDL.
  • Dependency Update: Added @apollo/federation-internals as a development dependency to support the new validation capabilities.
Changelog
  • tests/override-with-label.spec.ts
    • Added new assertions to verify the generated supergraph SDL for specific @override and @join__field configurations.
  • tests/shared/testkit.ts
    • Introduced supergraph validation using @apollo/federation-internals to detect composition issues earlier in tests.
    • Added a new import for ApolloSupergraph.
  • tests/subgraph/errors/EXTERNAL_UNUSED.spec.ts
    • Removed redundant directive definitions from test type definitions.
  • tests/subgraph/key-fields.spec.ts
    • Updated test to assert specific supergraph SDL content for @provides and __typename handling.
    • Added @shareable directives to test schemas.
  • package.json
    • Added @apollo/federation-internals as a development dependency.
  • pnpm-lock.yaml
    • Updated the pnpm lockfile to reflect the new dependency.
  • src/subgraph/validation/rules/elements/provides.ts
    • Refined the @provides rule to explicitly exclude __typename when marking fields as provided.
    • Refactored imports for GraphQL types.
  • src/supergraph/composition/object-type.ts
    • Refactored the logic for emitting @join__field directives.
    • Added functions for dropping unused Federation v1 external fields, collecting override information, and building join field ASTs.
    • Refined conditions for retaining object type join types.
    • Updated provideUsedOverriddenValue to check for inGraphs instanceof Set.
    • Modified shouldKeepObjectTypeJoinTypeInGraph logic to separate hasDefinition and keys.length > 0 checks and added a condition for objectTypeInGraph.extension && !hasOnlyOverriddenRequires.
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.

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 a significant and valuable refactoring of the @override composition logic, centralizing it to improve maintainability and fix complex bugs related to interactions with @requires and interfaces. The addition of supergraph validation using @apollo/federation-internals in the testkit is an excellent enhancement for ensuring correctness. The code is much cleaner and more consistent now. I have one suggestion to further improve the new logic by reducing some code duplication.

@kamilkisiela kamilkisiela changed the title fix Fix @join__field emission for Fed v1 @external and @override+ @requires edge cases Mar 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@theguild/federation-composition 0.22.1-alpha-20260310152804-4b0d25c0c6f27415ec843256b5b7673029d46af5 npm ↗︎ unpkg ↗︎

@kamilkisiela kamilkisiela marked this pull request as ready for review March 10, 2026 15:29
@n1ru4l n1ru4l merged commit 2103359 into kamilkisiela-patch-1 Mar 16, 2026
4 checks passed
@n1ru4l n1ru4l deleted the kamil-fix branch March 16, 2026 09:36
kamilkisiela added a commit that referenced this pull request Mar 16, 2026
…@requires` edge cases (#284)

This PR corrects supergraph's `@join__field` emission in a few edge
cases where emitted metadata could be incorrect or redundant.

- Use subgraph-local key usage when deciding whether to drop Federation
v1 `@join__field(external:true)`
- Avoid emitting redundant `@join__field(external: true)` metadata when
a field is only required through overridden paths
- Tighten `@join__field` emission around `@override` and interface type
fields.

This aligns emitted supergraph metadata with Apollo Gateway's
requirements.
Added Apollo supergraph validation in testkit to catch compatibility
regressions earlier.
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