Hello!
Looks like I found a bug. If I add filter to the entity this way:
/**
* @ApiResource()
* @ApiFilter(SearchFilter::class, properties={"id": "exact"})
*/
class Entity
Then I receive the following schema:
Entity(first: Int, after: String, id: Int, id_list: [Int])
When I apply filter by id, it's ignoring and returns me the full collection.
Also I believe that the id must string like /entities/1 instead of integer.
Or I'm doing something wrong?
Hi!
I thing I have the same bug here
For context:
Added api-platform to existing project, trying to replace existing custom graphql implementation with api-platform implementation.
When adding a filter to an entity, it works on the REST API but doesn't on the graphql api.
Information recollected:
# config/services.yaml
services:
entity.search_filter:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [{entityID: 'exact', anotherEntityID: 'exact'}]
tags: [{ name: 'api_platform.filter', id: 'entity.search_filter'}]
#tags: [ 'api_platform.filter' ]
autowire: false
autoconfigure: false
public: false
namespace App\Entity;
* @ApiResource(
* attributes={
* "filters"={"entity.search_filter"}
* },
* graphql={
* "query"={
* "filters"={"entity.search_filter"}
* },
* "delete",
* "update",
* "create"
* }
* )
*/
class Entity {
* @ApiFilter(SearchFilter::class, properties={"entityID": "exact"})
it gives me error:
(1/1) InvalidArgumentException
The filter class "SearchFilter" does not implement "ApiPlatform\Core\Api\FilterInterface".
in ApiFilter.php line 61
I thing is unrelated
Do you need more info? There's a way to make a temporary fix?
Lots of thanks, I thinks it's an amazing project
Hello,
This behavior is quite strange but it's caused by the normalizeValues function of the SearchFilter.
With REST operations the values passed to the filter aren't typed and are all strings so there is no problem if you pass to this filter values that are in fact numerical string values.
But with graphQl the values are typed.
For me you have two solutions that depend on your needs :
id_list argument. (I'm working on it)normalizeValues function in order to not discard values that aren't strings.Please do not use the NumericFilter for ids
I think this type conversion should be handled at the GraphQL layer. ~As far as the filters are concerned, all values are strings.~ (Not really true since https://github.com/api-platform/core/pull/1633)
I think the way to fix this is to introduce the IriFilter and deprecate using the SearchFilter for IRIs / ids.
LMK if the issue remains after #2277
LMK if the issue remains after #2277
Possible need of backport on branch 2.2 : https://github.com/api-platform/core/issues/2308
Most helpful comment
Hello,
This behavior is quite strange but it's caused by the normalizeValues function of the SearchFilter.
With REST operations the values passed to the filter aren't typed and are all strings so there is no problem if you pass to this filter values that are in fact numerical string values.
But with graphQl the values are typed.
For me you have two solutions that depend on your needs :
id_listargument. (I'm working on it)normalizeValuesfunction in order to not discard values that aren't strings.