Skip to content

Conversation

@kamilkisiela
Copy link
Contributor

Auth Directives

  • Enforce correct placement of auth directives (@authenticated, @requiresScopes, @policy) by rejecting any attempt to place them on interfaces, interface fields, or interface objects.
  • Add transitive-auth requirements checking to verify that fields using @requires specify at least the auth requirements of the fields they select
  • Propagate auth requirements through interface hierarchies so interface types and fields inherit auth requirements from implementing object types

Demand Directives

  • Disallow using @cost on interfaces - composition now fails with a clear error instead of accepting it silently
  • Add validation for @listSize sizedFields to ensure they point to list fields, not integer counters
  • Add validation for @listSize slicingArguments to ensure only arguments that exist in all subgraphs are kept

Bug Fixes

  • The EXTERNAL_MISSING_ON_BASE rule has been updated to handle @interfaceObject corner‑cases, like @external fields on object types, but provided by interface objects, were triggering false positives.

The `@cost` directive should not be applied to interface fields, field
arguments, or the interface type itself. This commit adds tests and
validation to enforce this rule. Additionally, it ensures that cost
calculations are correctly applied when an object type implements an
interface with `@cost` and `@key` directives. The behavior of
`@listSize` is also fixed as previously `sizedFields` expected Integers,
but now it expects a List
Bumped the Apollo composition package to the latest version.
@gemini-code-assist
Copy link

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 introduces significant improvements to the composition and validation logic within the federation-composition library. It tightens the rules around how authentication and demand-related directives are applied and inherited, leading to a more robust and predictable supergraph schema. Additionally, it addresses a specific bug related to external fields and interface objects, enhancing overall schema integrity.

Highlights

  • Auth Directives Validation: Stricter validation has been implemented for @authenticated, @requiresScopes, and @policy directives, preventing their incorrect placement on interfaces, interface fields, or interface objects. A new rule enforces that fields using @requires must specify at least the authentication requirements of the fields they select, and auth requirements now propagate through interface hierarchies.
  • Demand Directives Enhancements: The @cost directive can no longer be applied to interfaces, interface fields, or interface arguments, with composition now failing explicitly. Validation for @listSize has been improved to ensure sizedFields correctly point to list fields (e.g., edges instead of count) and that slicingArguments are valid across all subgraphs.
  • Bug Fix: External Missing on Base Rule: The EXTERNAL_MISSING_ON_BASE rule has been updated to correctly handle @interfaceObject corner-cases, resolving false positives where @external fields on object types provided by interface objects were incorrectly flagged.
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 changed the title Strengthen composition and validation around Stricter validation rules for auth directives, @cost, and @listSize Nov 21, 2025
@github-actions
Copy link
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.21.0-alpha-20251121132040-714a923215537c9faed246cbe44106608e4055e1 npm ↗︎ unpkg ↗︎

Copy link

@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 enhancements to composition and validation, particularly around authentication and demand-shaping directives. Key changes include stricter placement rules for auth directives, transitive authentication checks for @requires, and propagation of auth requirements through interface hierarchies. Additionally, it disallows @cost on interfaces and improves validation for @listSize. The implementation is comprehensive and includes extensive tests. I've identified a critical issue in the policy merging logic and a minor recurring typo in the test files.

Copy link
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.

legito

@kamilkisiela
Copy link
Contributor Author

legito

gracito

@kamilkisiela kamilkisiela merged commit 5edf421 into main Nov 24, 2025
4 checks passed
@kamilkisiela kamilkisiela deleted the kamil-demand-fix branch November 24, 2025 12:26
kamilkisiela pushed a commit that referenced this pull request Nov 24, 2025
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/[email protected]

### Minor Changes

-
[#215](#215)
[`5edf421`](5edf421)
Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - **Enforce
correct placement of auth directives.** A new validation rule
(`AUTH_REQUIREMENTS_APPLIED_ON_INTERFACE`) rejects any attempt to put
these directives on interfaces, interface fields or interface objects.

**Add transitive-auth requirements checking.** A new rule verifies that
any field using `@requires` specifies at least the auth requirements of
the fields it selects. If a field doesn't carry forward the
`@authenticated`, `@requiresScopes` or `@policy` requirements of its
dependencies, composition fails with a
`MISSING_TRANSITIVE_AUTH_REQUIREMENTS` error.

**Propagate auth requirements through interface hierarchies.** Interface
types and fields now inherit `@authenticated`, `@requiresScopes` and
`@policy` from the object types that implement them.

-
[#215](#215)
[`5edf421`](5edf421)
Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Disallowed
using `@cost` on interfaces - you can no longer place `@cost` on an
interface type, its fields, or field arguments. Composition now fails
with a clear error instead of accepting it silently.

The `@listSize` directive now validates that `sizedFields` point to list
fields, not integer counters (e.g., use `edges` instead of `count`).

Added validation for `slicingArguments` in `@listSize`. Only arguments
that exist in all subgraphs are kept, invalid ones trigger an error.

### Patch Changes

-
[#215](#215)
[`5edf421`](5edf421)
Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - The
`EXTERNAL_MISSING_ON_BASE` rule has been updated to handle
`@interfaceObject` corner‑cases, like `@external` fields on object
types, but provided by interface objects, were triggering false
positives.

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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