API Platform, filters & dataproviders


The new api is based on API Platform.

However, we can not use any filters (with the annotation @ApiFilter), pagination, orders, … because Sylius has implemented custom DataProvider (ex: Sylius\Bundle\ApiBundle\DataProvider\OrderCollectionDataProvider), and this dataprovider just send back (almost) all entities without applying custom filters.

To avoid this, I had to override the Sylius data provider with the official one from ApiPlatform:

# services.yml
        class: ApiPlatform\Core\Bridge\Doctrine\Orm\CollectionDataProvider
        parent: 'api_platform.doctrine.orm.collection_data_provider'
        autoconfigure: false
        # This is the important part: priority is higher than the Sylius data provider (which is 10)
        tags: [ { name: 'api_platform.collection_data_provider', priority: 100 } ] # priority ghigh number = high priority

Is there a good reason for Sylius to implement its own data providers ?


1 Like