feat: Add Apollo Federation subgraph support #34
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 Feature Implementation: Apollo Federation Subgraph Support
📋 Overview
This PR implements comprehensive Apollo Federation support for nitro-graphql, enabling distributed GraphQL architectures with both GraphQL Yoga and Apollo Server frameworks.
🔧 Technical Implementation
1. Federation Configuration Types
Added
FederationConfiginterface to support federation settings:2. Virtual Module Configuration System
Replaced process.env dependencies with typed virtual module:
3. Dynamic Dependency Loading
Implemented optional
@apollo/subgraphintegration:4. Schema Builder Integration
buildSubgraphSchemawhen federation is enabledparse()makeExecutableSchemawhen federation unavailable5. GraphQL Codegen Integration
Enhanced type generation with federation support:
6. Auto-Import Functions
Added federation helper functions:
defineReference()- For__resolveReferenceresolversdefineEntity()- For federated entity typesdefineSubgraph()- For subgraph configuration🎯 Framework Support
GraphQL Yoga Implementation
buildSubgraphSchemain schema creationApollo Server Implementation
defineEventHandler🧪 Testing Infrastructure
Federation Playground
Created
/playground-federation/with:@keydirective__resolveReferenceTest Schema Example
📦 Dependency Management
@apollo/subgraphas optional peerDependency🔍 Virtual Module System
Enhanced virtual module architecture:
🔍 AST Parsing Enhancement
Extended resolver scanning to detect federation functions:
⚡ Performance Considerations
🔒 Backward Compatibility
🧩 Integration Points
Type Generation
Development Experience
📊 Code Changes Summary
✅ Verification Checklist
_service,_entities) functional__resolveReferenceworking🔗 Related Issues
Closes #33
This implementation provides a robust foundation for Apollo Federation in nitro-graphql while maintaining the library's core principles of simplicity, type safety, and developer experience. The new virtual module system eliminates runtime environment dependencies in favor of build-time configuration.