PHP code example of veysiyildiz / module-graphql-performance

1. Go to this page and download the library: Download veysiyildiz/module-graphql-performance library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

veysiyildiz / module-graphql-performance example snippets


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']);
    }
}

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}";
    }
}

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
    }
}
xml
<config>
    <default>
        <graphql_performance>
            <cache>
                <warming_enabled>1</warming_enabled>
                <warming_interval>3600</warming_interval>
            </cache>
        </graphql_performance>
    </default>
</config>