api-platform / api-platform/core
[GraphQL] NumericFilter and RangeFilter can not be defined on the same property
- 主要言語
- PHP
- スター
- 2.6k
- フォーク
- 980
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 49
説明
**API Platform version(s) affected**: 2.5.4
**Description**
In my context, i need to enable both RangeFilter and NumericFilter on the same property to have the following filtering option : less than, equals, between and greater than
In such case, the graphql schema will convert both filters in the same way using the property name to identify the filter.
In the following example
```
/**
* @ApiResource()
* @ApiFilter(RangeFilter::class, properties={"age"})
* @ApiFilter(NumericFilter::class, properties={"age"})
*/
class Dummy
{
/** @var int $age */
private $age;
// ...
}
```
The REST collection endpoint enables both filters with the syntax `/dummies?age=18` and `/dummies?age[gt]=18`
But the GraphQL endpoint enables only the `NumericFilter` with the syntax `dummies(age: "18") { ... }`
(as the `RangeFilter` uses the syntax `dummies(age: {gt: "18"})`)
**How to reproduce**
Here a valid entity declaration
```php
id;
}
public function setId($id): void
{
$this->id = $id;
}
/**
* @var integer
* @ApiProperty
* @ORM\Column(type="integer")
*/
private $age;
public function getAge()
{
return $this->age;
}
public function setAge($age): void
{
$this->age = $age;
}
}
```
**Case 1. Both RangeFilter and NumericFilter**
In the entity definition, enabling both the `RangeFilter` and the `NumericFilter` the following graphql query is available
```
{
dummies(age: 18) {
edges {
node {
id age
}
}
}
}
```
And the following syntax:
```
{
dummies(age: {gt:"18"}) {
edges {
node {
id age
}
}
}
}
```
raises the error:
```
{
"errors": [
{
"message": "Field \"dummies\" argument \"age\" requires type Int, found {gt: \"18\"}.",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 2,
"column": 16
}
]
}
]
}
```
**Case 2. Only RangeFilter**
In the entity definition, enabling only the `RangeFilter` (delete the `NumericFilter` filter declaration) the following graphql query is available
```
{
dummies(age: {gt:"18"}) {
edges {
node {
id age
}
}
}
}
```
And the following syntax:
```
{
dummies(age: 18) {
edges {
node {
id age
}
}
}
}
```
raises the error:
```
{
"errors": [
{
"message": "Field \"dummies\" argument \"age\" requires type DummyFilter_age, found 18.",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 2,
"column": 16
}
]
}
]
}
```
**Possible Solution**
The RangeFilter should supports an `eq` (and `neq`) syntax allowing to use, with one filter, all the cases : less than, between, greater than and equal to
**Additional Context**
Note that using the `NumericFilter` a numerical value should be defined but using the `RangeFilter`, a string should be used to define the value.
Should I open another issue ?
コントリビューションガイド
評価
この issue はまだ評価されていません。