Sterk GraphQL Performance
veysiyildiz/module-graphql-performance
Optimizes Magento 2 GraphQL performance with DataLoader-based batch loading to prevent N+1 queries, multi-level caching with cache warming, and query-complexity and performance monitoring.
Build Tests
Code Quality
Tested on Magento 2.4.9
Recent Test History
Each release is tested against the latest Magento version at that time.
Top Contributors
View LeaderboardLooking for Contributors
Composer installation fails. Your contribution could help the entire Magento community!
Share This Module's Status
README
Loaded from GitHubSterk GraphQL Performance Module for Magento 2
Overview
The Sterk GraphQL Performance module is a comprehensive solution for optimizing GraphQL performance in Magento 2. It addresses common performance bottlenecks, implements efficient data loading patterns, and provides robust caching strategies.
Features
1. Data Loading Optimization
- DataLoader pattern implementation for batch loading
- Prevention of N+1 query problems
- Efficient data retrieval for:
- Products
- Categories
- Customers
- CMS Pages/Blocks
- Orders and Invoices
- Brand Categories
- Credit Memos
2. Caching Infrastructure
- Multi-level caching strategy
- Intelligent cache tag management
- Automatic cache warming
- Query-level caching
- Field-level result caching
- Cache invalidation optimization
3. Performance Monitoring
- Query execution time tracking
- Performance metrics collection
- GraphQL query complexity analysis
- Resource usage monitoring
- Performance reporting
4. Database Optimization
- Connection pooling
- Transaction management
- Batch query optimization
- Efficient resource utilization
Installation
- Install via Composer:
composer require veysiyildiz/module-graphql-performance
- Enable the module:
bin/magento module:enable Sterk_GraphQlPerformance
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:clean
Configuration
Admin Configuration
Navigate to Stores > Configuration > Sterk > GraphQL Performance to configure:
-
Cache Settings
- Cache lifetime for different entities
- Cache warming patterns
- Cache invalidation rules
-
Performance Limits
- Query complexity limits
- Query depth restrictions
- Batch size configurations
-
Monitoring Settings
- Performance logging
- Metric collection
- Report generation
Cache Warming Configuration
Configure cache warming in etc/config.xml:
<config>
<default>
<graphql_performance>
<cache>
<warming_enabled>1</warming_enabled>
<warming_interval>3600</warming_interval>
</cache>
</graphql_performance>
</default>
</config>
Usage
Basic Implementation
use Sterk\GraphQlPerformance\Model\DataLoader\ProductDataLoader;
class ProductResolver implements ResolverInterface
{
public function __construct(
private readonly ProductDataLoader $dataLoader
) {}
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
return $this->dataLoader->load($args['id']);
}
}
Advanced Features
Custom DataLoader
use Sterk\GraphQlPerformance\Model\DataLoader\BatchDataLoader;
class CustomDataLoader extends BatchDataLoader
{
protected function loadFromDatabase(array $ids): array
{
// Implement batch loading logic
}
protected function generateCacheKey(string $id): string
{
return "custom_entity_{$id}";
}
}
Cache Tag Management
use Sterk\GraphQlPerformance\Model\Cache\TagManager;
class CustomResolver
{
public function __construct(
private readonly TagManager $tagManager
) {}
public function resolve($field)
{
$tags = $this->tagManager->getEntityTags('custom_entity', $id);
// Use tags for cache operations
}
}
Performance Monitoring
Metrics Collection
The module automatically collects:
- Query execution times
- Cache hit rates
- Database query counts
- Memory usage
- Query complexity scores
Reporting
Access performance reports via:
- GraphQL API endpoint
- Admin dashboard
- Command line interface
Best Practices
1. Query Optimization
- Use field selection wisely
- Implement pagination
- Leverage query batching
- Monitor query complexity
2. Caching Strategy
- Configure appropriate cache lifetimes
- Use specific cache tags
- Implement proper invalidation
- Enable cache warming
3. Resource Management
- Configure connection pooling
- Monitor memory usage
- Implement query timeouts
- Use batch processing
Troubleshooting
Common Issues
- Cache Invalidation
Issue: Stale data after updates
Solution: Check cache tags and invalidation events
- Performance Degradation
Issue: Slow query response
Solution: Monitor query complexity and database connections
- Memory Usage
Issue: High memory consumption
Solution: Adjust batch sizes and connection pool settings
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE.md for details
Support
For support, please:
- Check documentation
- Search existing issues
- Create a new issue
- Contact veysiyildiz@gmail.com
Changelog
See CHANGELOG.md for version history
This content is fetched directly from the module's GitHub repository. We are not the authors of this content and take no responsibility for its accuracy, completeness, or any consequences arising from its use.