feat(graphql-armor): add context injection plugin for enhanced validation #770
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.
Enhanced Validation Context Handling for Apollo Server
Overview
This PR introduces improved validation context handling in GraphQL Armor, specifically for Apollo Server integration. The changes enable better access to request context during validation rules execution, which is crucial for implementing more sophisticated security checks.
Key Changes
1. New Context Helper Module
context-helper.ts
with utilities for injecting request context into validation rulesinjectRequestContextRule
helper function to wrap validation rules with request contextcontextInjectionPlugin
for Apollo Server to handle context injection2. Enhanced Types
@escape.tech/graphql-armor-types
:EnhancedValidationContext
interface for extended validation contextUser
interface for authentication-related features3. Updated Protection Rules
Modified all protection rules to use the new context injection system:
4. Testing Updates
Technical Details
The changes introduce a more robust way to access request context during validation by:
Benefits
Testing
Breaking Changes
None. This is a backward-compatible enhancement that adds functionality without breaking existing behavior.
Dependencies
No new dependencies were added. The changes utilize existing Apollo Server and GraphQL types.