api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.39k stars 847 forks source link

SearchFilter not working with GraphQL ? #2724

Closed Isengo1989 closed 3 years ago

Isengo1989 commented 5 years ago

I am using the SearchFilter Class on kw

<?php

namespace App\Entity;

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

/**
 * @ApiResource
 * @ORM\Entity
 */
class Availability
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var int
     * @ApiFilter(SearchFilter::class, strategy="exact")
     * @ORM\Column(name="kw", type="integer", nullable=false)
     */
    public $kw;

It works fine on REST but not on GraphQL, because it is returning the full list

Auswahl_427

lukasluecke commented 5 years ago

SearchFilter works fine for me on (on a string column). Maybe try using NumericFilter, since you are using an integer column?

alanpoulain commented 5 years ago

It should work with integers though.

davidgerth commented 5 years ago

SearchFilter does not work for integer columns here. If I use NumericFilter, it works.

alexfauquette commented 4 years ago

I had the same issue. The first filter work with REST and GraphQL. The second one works only with REST

@ApiFilter(NumericFilter::class, properties={"eleve.id": "exact" })

@ApiFilter(SearchFilter::class, properties={"eleve.id": "exact" })
alanpoulain commented 3 years ago

Solved by https://github.com/api-platform/core/pull/4295.