PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 18, 2022

[FIXED] How can I resolve issue on Symfony ApiPlatform SearchFilter import?

 October 18, 2022     api-platform.com, php, symfony     No comments   

Issue

I made an API with Symfony / ApiPlatform. I followed the official doc of ApiPlatform concerning filters on queries but I just can't use the ApiFilter "SearchFilter".

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Annotation\ApiResource;

#[ORM\Entity(repositoryClass: PostRepository::class)]
#[
    ApiResource(
        graphql: [
            //queries
            'item_query' => [
                'normalization_context' => [
                    'groups' => ['read:Post']
                ]
            ],
            'collection_query' => [
                'normalization_context' => [
                    'groups' => ['read:Posts'],
                ],
                'denormalizationContext' => [
                    'groups' => ['write:Post']
                ]
            ],
        ]
    ),
]
#[ApiFilter(DateFilter::class, properties: ['date'])]
#[ApiFilter(SearchFilter::class, properties: ['author' => 'exact'])]
Class Post {
//...
    #[ORM\ManyToOne(inversedBy: 'posts')]
    #[ORM\JoinColumn(nullable: false)]
    #[Groups(['read:Post', 'read:Posts'])]
    private ?User $author = null;
}

Api returning 500 on fetching schemas. Error below:

ApiPlatform\Doctrine\Orm\Filter\SearchFilter::__construct(): Argument #2 ($iriConverter) must be of type ApiPlatform\Api\IriConverterInterface, ApiPlatform\Core\Bridge\Symfony\Routing\IriConverter given, called in ...myway/var/cache/dev/ContainerE6FeJyy/getAnnotatedAppEntityPostApiPlatformDoctrineOrmFilterSearchFilterService.php on line 29 Doc ApiPlatform: https://api-platform.com/docs/core/filters/

I don't understand the issue concerning "SearchFilter". Also the "DateFilter" works fine. (This is not problem with gql support because with basic REST support, the error is identical on localhost/api) Any help is welcome! Thanks you so much!


Solution

So, there were conflicts between my current version of ApiPlatform (the deprecated v2.6) and the new serializer annotations that appeared with v2.7/v3. So I started the migration to v2.7 of apiPlatform and corrected the import breaking changes, and that's it.

(Also, $ php bin/console api:upgrade-resource -f helped me to update my entity files.)

Everything works well. Thanks @HarveyDent, you were right it was concerning my version of api-platform.



Answered By - anonyMouse
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing