Why is data provider class in for api platform ignored?

62 Views Asked by At

I did all as is described here https://api-platform.com/docs/v2.6/core/data-providers/ but when i call my endpoint, data provider class is ignorder

My Class

namespace App\DataProvider;

use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use App\Entity\Review;

final class ReviewItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface 
{

    public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
    {
        return Review::class === $resourceClass; // Add your custom conditions here
    }

 
    public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?Review
    {
        return null;
    }
}

My service configuration

parameters:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'

I call endpoint /api/reviews/26 and i expected that it will return null, but i returns default api platfrom respone

{
    "@context": "/api/contexts/Review",
    "@id": "/api/reviews/26",
    "@type": "Review",
    "id": 26,
    "createdAt": "2023-11-01T20:44:45+00:00",
    "resource": "/api/review_resources/7",
    "reviewResponses": [
        "/api/review_responses/121",
        "/api/review_responses/122",
        "/api/review_responses/123"
    ]
}
0

There are 0 best solutions below