api-platform / api-platform/core

[GraphQL, SearchFilter] Filter a nested collection doesn't work on iterable property

Open
#8,038 1 comment 0 reactions 0 assignees View on GitHub
doctrine filters GraphQL
Dominant language
PHP
Stars
2.6k
Forks
980
Avg merge
2d 2h
Merged PRs (30d)
51

Description

**API Platform version(s) affected**: 2.6.8

**Description**

Filter nested collection (OneToMany) doesn't work as excerpted, i also tried `children.views`

Note that it works with ORM `string` property, but not with ORM `array` type.

**How to reproduce**

* Entity

```php
// App/Entity/Route
...
#[ApiFilter(SearchFilter::class, strategy: 'partial', properties: ['views'=>'partial'])]
class Route
{
...
#[ORM\Column(type: 'array')]
private array $views = [];

#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
private ?self $parent;

#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $children;
}
```

* Query
```graphql
query {
routes(views: [MENU]) {
edges {
node {
id
title
children(views: [MENU]) {
edges {
node {
id
title
}
}
}
}
}
}
}
```

* Result
```json
{
"data": {
"routes": {
"edges": [
{
"node": {
"id": "/api/routes/1468",
"title": "Work Orders",
"views": [
"MENU"
],
"children": {
"edges": [
{
"node": {
"id": "/api/routes/1469",
"title": "Work Order List",
"views": [
"MENU"
]
}
},
{
"node": {
"id": "/api/routes/1470",
"title": "New Work Order",
"views": [
"PAGE_ACTION"
]
}
},
{
"node": {
"id": "/api/routes/1471",
"title": "Edit Work Order",
"views": [
"ENTITY_ACTION"
]
}
},
{
"node": {
"id": "/api/routes/1472",
"title": "Delete Work Order",
"views": [
"ENTITY_ACTION"
]
}
}
]
}
}
},
...
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.