Skip to content

Implement all missing Apollo Federation directives - #2774

Open
eriksulymosi wants to merge 12 commits into
nuwave:masterfrom
magyarjeti:apollo-authorization-directives
Open

eriksulymosi wants to merge 12 commits into
nuwave:masterfrom
magyarjeti:apollo-authorization-directives

Conversation

@eriksulymosi

@eriksulymosi eriksulymosi commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #

  • Added or updated tests
  • Documented user facing changes

Changes

This PR introduces support for Apollo-style declarative authorization directives within Lighthouse. This allows schemas to better align with Apollo Router / Federation standards for authorization handled at the gateway or subgraph level.

Key additions:

  • Introduced Apollo Authorization Directives (e.g., @authenticated, @requiresScopes, @policy) to control field and type accessibility.
  • Integrated the directive definitions into the schema generation and validation pipeline.
  • Added corresponding tests to ensure schema syntax and directive handling work seamlessly with standard Apollo federation setups.

Breaking changes

None. This is a purely additive feature and does not affect existing @can, @auth or @guard directives implemented natively by Lighthouse.

@eriksulymosi

Copy link
Copy Markdown
Contributor Author

Hi @spawnia,

Just wanted to gently ping this PR to see if anyone has a moment to check it out.

It introduces support for a few essential Apollo Router directives directly into Lighthouse. This will make it much easier for developers using Lighthouse in a federated architecture or alongside Apollo Router to leverage these directives out of the box.

The implementation is non-breaking, well-scoped, and all tests are passing.

Let me know if you have any feedback or if you'd like me to tweak anything! Thanks for your time and for this great package. 🙏

@eriksulymosi

Copy link
Copy Markdown
Contributor Author

Hi! Just wanted to gently bump this PR since it's been quiet for a while. Whenever you have some bandwidth, I'd greatly appreciate it if you could take a look. Let me know if any adjustments are needed! Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Valid interface, scalar, and enum authorization directives are omitted from generated federation SDL.

1 open finding
What changed in this PR

Adds Apollo Federation authorization directives and preserves them in generated subgraph SDL.

Changes:

  • Adds @authenticated, @requiresScopes, and @policy.
  • Registers directives with federation schema printing.
  • Adds documentation and integration coverage.
File Description
src/​Federation/​Directives/​AuthenticatedDirective.php Defines @authenticated.
src/​Federation/​Directives/​RequiresScopesDirective.php Defines scope-based authorization.
src/​Federation/​Directives/​PolicyDirective.php Defines policy-based authorization.
src/​Federation/​FederationPrinter.php Preserves authorization directives in SDL.
tests/​Integration/​Federation/​FederationSchemaTest.php Tests object and field directives.
docs/​6/​federation/​getting-started.md Documents directive imports.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Federation/FederationPrinter.php Resolved
@eriksulymosi
eriksulymosi marked this pull request as draft October 14, 2026 10:42
@eriksulymosi
eriksulymosi marked this pull request as ready for review October 15, 2026 11:09
@eriksulymosi

Copy link
Copy Markdown
Contributor Author

I originally opened this PR to implement the authorization-related Apollo Federation directives. However, I've since expanded its scope and implemented all the other missing Federation directives as well.

With these changes, I've completed the implementation of all previously missing Apollo Federation directives in Lighthouse.

@eriksulymosi eriksulymosi changed the title Apollo authorization directives Implement all missing Apollo Federation directives Oct 15, 2026
@spawnia
spawnia requested a balanced review from Copilot October 25, 2026 16:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Generated IDE definitions reference an undeclared scalar, and enum printing introduces quadratic AST scanning.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment on lines +202 to +211
foreach ($definitions as $value) {
if ($value->astNode === null) {
foreach ($type->astNode->values ?? [] as $valueNode) {
if ($valueNode->name->value === $value->name) {
$value = clone $value;
$value->astNode = $valueNode;
break;
}
}
}
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