Skip to content

Commit 545a21b

Browse files
authored
docs: 4.4 release gaps (HTTP QUERY, ItemDenormalizer, legacy filters) (#2341)
1 parent c0d9d24 commit 545a21b

7 files changed

Lines changed: 196 additions & 78 deletions

File tree

‎admin/handling-relations.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,25 @@ class Review
313313
// api/src/Entity/Book.php
314314
namespace App\Entity;
315315

316-
use ApiPlatform\Metadata\ApiFilter;
316+
use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter;
317317
use ApiPlatform\Metadata\ApiResource;
318-
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
318+
use ApiPlatform\Metadata\QueryParameter;
319319
use Doctrine\Common\Collections\ArrayCollection;
320320
use Doctrine\Common\Collections\Collection;
321321
use Doctrine\ORM\Mapping as ORM;
322322

323323
#[ORM\Entity]
324-
#[ApiResource]
324+
#[ApiResource(
325+
parameters: [
326+
'title' => new QueryParameter(filter: new PartialSearchFilter()),
327+
]
328+
)]
325329
class Book
326330
{
327331
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
328332
public ?int $id = null;
329333

330334
#[ORM\Column]
331-
#[ApiFilter(SearchFilter::class, strategy: 'ipartial')]
332335
public string $title;
333336

334337
#[ORM\OneToMany(targetEntity: Review::class, mappedBy: 'book')]
@@ -341,8 +344,8 @@ class Book
341344
}
342345
```
343346

344-
Notice the "partial search" [filter](../core/filters.md) on the `title` property of the `Book`
345-
resource class.
347+
Notice the [`PartialSearchFilter`](../core/filters.md#list-of-available-filters) on the `title`
348+
property of the `Book` resource class.
346349

347350
Now, let's configure API Platform Admin to enable autocompletion for the book selector. We will
348351
leverage the [`<ReferenceInput>`](https://marmelab.com/react-admin/ReferenceInput.html) and

‎admin/performance.md‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,45 @@ To make the admin faster and greener, you can make some changes to your API.
44

55
## Retrieve All Relations in One Request
66

7-
By default, if your relations are not embedded and if you decide to display some fields belonging to
8-
relations in your resource list, the admin will fetch the relations one by one.
7+
Some of your relations are not embedded. You display some of their fields in your resource list. By
8+
default, the admin fetches these relations one by one.
99

1010
In this case, it can be improved by doing only one request for all the related resources instead.
1111

12-
To do so, you need to make sure the [search filter](../core/doctrine-filters.md#search-filter) is
12+
To do so, you need to make sure the [`ExactFilter`](../core/doctrine-filters.md#exact-filter) is
1313
enabled for the identifier of the related resource.
1414

15-
For instance, if you have a `book` resource having a relation to `author` resources and you display
16-
the author names on your book list, you can make sure the authors are retrieved in one go by
17-
writing:
15+
For instance, say you have a `book` resource with a relation to `author` resources, and you display
16+
the author names on your book list. Retrieve the authors in one go by writing:
1817

1918
```php
2019
<?php
2120
// api/src/Entity/Author.php
2221
namespace App\Entity;
2322

24-
use ApiPlatform\Metadata\ApiFilter;
25-
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
23+
use ApiPlatform\Doctrine\Orm\Filter\ExactFilter;
2624
use ApiPlatform\Metadata\ApiResource;
25+
use ApiPlatform\Metadata\QueryParameter;
2726
use Doctrine\ORM\Mapping as ORM;
2827

2928
#[ORM\Entity]
30-
#[ApiResource]
29+
#[ApiResource(
30+
parameters: [
31+
'id' => new QueryParameter(filter: new ExactFilter()),
32+
]
33+
)]
3134
class Author
3235
{
3336
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
34-
#[ApiFilter(SearchFilter::class, strategy: "exact")]
3537
public ?int $id = null;
3638

3739
#[ORM\Column]
3840
public string $name;
3941
}
4042
```
4143

42-
Instead of issuing a separate request for each author, the admin will now fetch all the authors in
43-
one go, with a request similar to the following:
44+
The admin now fetches all the authors in one go, instead of issuing a separate request for each
45+
author. The request looks similar to the following:
4446

4547
```txt
4648
https://localhost/authors?

‎admin/schema.md‎

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Customizing the Schema
22

33
Both [`HydraAdmin`](./components.md#hydraadmin) and [`OpenApiAdmin`](./components.md#openapiadmin)
4-
leverage introspection of the API schema to discover its capabilities, like **filtering** and
4+
use introspection of the API schema to discover its capabilities, like **filtering** and
55
**sorting**.
66

7-
They also detect wether the API has real-time capabilities using [Mercure](./real-time-mercure.md),
8-
and automatically enable it if it does.
7+
They also detect whether the API has real-time capabilities through
8+
[Mercure](./real-time-mercure.md). When it does, Admin enables real-time updates automatically.
99

10-
Lastly, API Platform Admin has native support for the popular
11-
[Schema.org](./schema.md#about-schemaorg) vocabulary, which enables it to automatically use the
12-
field type matching your data, or display a related resource's name instead of its IRI.
10+
API Platform Admin also has native support for the popular [Schema.org](./schema.md#about-schemaorg)
11+
vocabulary. This support lets it automatically use the field type matching your data, or display a
12+
related resource's name instead of its IRI.
1313

1414
## Adding Filtering Capabilities
1515

16-
You can add the [`ApiFilter` attribute](../core/filters.md#apifilter-attribute) to an API Platform
17-
resource to configure a filter on a property.
16+
You can use the [`QueryParameter` attribute](../core/filters.md#declaring-parameters) on an API
17+
Platform resource to configure a filter on a property.
1818

1919
For instance, here is how configure filtering on the `id`, `title` and `author` properties of a
2020
`Book` resource:
@@ -24,18 +24,20 @@ For instance, here is how configure filtering on the `id`, `title` and `author`
2424
// api/src/Entity/Book.php
2525
namespace App\Entity;
2626

27-
use ApiPlatform\Metadata\ApiFilter;
27+
use ApiPlatform\Doctrine\Orm\Filter\ExactFilter;
28+
use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter;
2829
use ApiPlatform\Metadata\ApiResource;
29-
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
30+
use ApiPlatform\Metadata\QueryParameter;
3031
use Doctrine\ORM\Mapping as ORM;
3132

32-
#[ApiResource]
33+
#[ApiResource(
34+
parameters: [
35+
'id' => new QueryParameter(filter: new ExactFilter()),
36+
'title' => new QueryParameter(filter: new PartialSearchFilter()),
37+
'author' => new QueryParameter(filter: new PartialSearchFilter()),
38+
]
39+
)]
3340
#[ORM\Entity]
34-
#[ApiFilter(SearchFilter::class, properties: [
35-
'id' => 'exact',
36-
'title' => 'ipartial',
37-
'author' => 'ipartial'
38-
])]
3941
class Book
4042
{
4143
// ...
@@ -47,12 +49,12 @@ filter on the selected properties.
4749

4850
![Filtering on the title property](./images/admin-filter.png)
4951

50-
**Tip:** Learn more about the [`ApiFilter` attribute](../core/filters.md#apifilter-attribute) in the
51-
core documentation.
52+
**Tip:** Learn more about the [available filters](../core/filters.md#list-of-available-filters) in
53+
the core documentation.
5254

5355
## Adding Sorting Capabilities
5456

55-
You can also use the [`ApiFilter` attribute](../core/filters.md#apifilter-attribute) on an API
57+
You can also use the [`QueryParameter` attribute](../core/filters.md#declaring-parameters) on an API
5658
Plaform resource to configure sorting.
5759

5860
For instance, here is how to configure sorting on the `id`, `isbn`, `title`, `author` and
@@ -63,20 +65,24 @@ For instance, here is how to configure sorting on the `id`, `isbn`, `title`, `au
6365
// api/src/Entity/Book.php
6466
namespace App\Entity;
6567

66-
use ApiPlatform\Metadata\ApiFilter;
68+
use ApiPlatform\Doctrine\Orm\Filter\SortFilter;
6769
use ApiPlatform\Metadata\ApiResource;
68-
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
70+
use ApiPlatform\Metadata\QueryParameter;
6971
use Doctrine\ORM\Mapping as ORM;
7072

71-
#[ApiResource]
73+
#[ApiResource(
74+
parameters: [
75+
'order' => new QueryParameter(filter: new SortFilter(), property: 'id'),
76+
'orderIsbn' => new QueryParameter(filter: new SortFilter(), property: 'isbn'),
77+
'orderTitle' => new QueryParameter(filter: new SortFilter(), property: 'title'),
78+
'orderAuthor' => new QueryParameter(filter: new SortFilter(), property: 'author'),
79+
'orderPublicationDate' => new QueryParameter(
80+
filter: new SortFilter(),
81+
property: 'publicationDate'
82+
),
83+
]
84+
)]
7285
#[ORM\Entity]
73-
#[ApiFilter(OrderFilter::class, properties: [
74-
'id' => 'ASC',
75-
'isbn' => 'ASC',
76-
'title' => 'ASC',
77-
'author' => 'ASC',
78-
'publicationDate' => 'DESC'
79-
])]
8086
class Book
8187
{
8288
// ...
@@ -88,7 +94,7 @@ selected columns sortable.
8894

8995
![Sorting by the title property](./images/admin-sort.png)
9096

91-
**Tip:** Learn more about the [`ApiFilter` attribute](../core/filters.md#apifilter-attribute) in the
97+
**Tip:** Learn more about the [`SortFilter`](../core/filters.md#list-of-available-filters) in the
9298
core documentation.
9399

94100
## Enabling Real-Time Updates
@@ -122,19 +128,19 @@ API Platform Admin has native support for the popular [Schema.org](https://schem
122128
> Schema.org is a collaborative, community activity with a mission to create, maintain, and promote
123129
> schemas for structured data on the Internet, on web pages, in email messages, and beyond.
124130
125-
To leverage this capability, your API must use the JSON-LD format and the appropriate Schema.org
126-
types. The following examples will use [API Platform Core](../core/) to create such API, but keep in
127-
mind that this feature will work with any JSON-LD API using the Schema.org vocabulary, regardless of
128-
the used web framework or programming language.
131+
To use this capability, your API must use the JSON-LD format and the appropriate Schema.org types.
132+
The following examples use [API Platform Core](../core/) to create such an API. This feature works
133+
with any JSON-LD API that uses the Schema.org vocabulary, regardless of the web framework or
134+
programming language.
129135

130136
## Displaying Related Resource's Name Instead of its IRI
131137

132138
By default, IRIs of related objects are displayed in lists and forms. However, it is often more
133139
user-friendly to display a string representation of the resource (such as its name) instead of its
134140
ID.
135141

136-
To configure which property should be shown to represent your entity, map the property containing
137-
the name of the object with the `https://schema.org/name` type:
142+
To configure which property represents your entity, map the property that holds the name of the
143+
object with the `https://schema.org/name` type:
138144

139145
```php
140146
// api/src/Entity/Person.php

‎core/graphql.md‎

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,14 +1201,20 @@ instead of the dot (`.`) syntax, e.g.:
12011201
// api/src/Entity/Offer.php
12021202
namespace App\Entity;
12031203
1204-
use ApiPlatform\Metadata\ApiFilter;
1204+
use ApiPlatform\Doctrine\Orm\Filter\ExactFilter;
1205+
use ApiPlatform\Doctrine\Orm\Filter\SortFilter;
12051206
use ApiPlatform\Metadata\ApiResource;
1206-
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
1207-
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
1207+
use ApiPlatform\Metadata\QueryParameter;
12081208
1209-
#[ApiResource]
1210-
#[ApiFilter(OrderFilter::class, properties: ['product.releaseDate'])]
1211-
#[ApiFilter(SearchFilter::class, properties: ['product.color' => 'exact'])]
1209+
#[ApiResource(
1210+
parameters: [
1211+
'product_releaseDate' => new QueryParameter(
1212+
filter: new SortFilter(),
1213+
property: 'product.releaseDate'
1214+
),
1215+
'product_color' => new QueryParameter(filter: new ExactFilter(), property: 'product.color'),
1216+
]
1217+
)]
12121218
class Offer
12131219
{
12141220
// ...
@@ -1238,7 +1244,7 @@ Or order your results like:
12381244

12391245
```graphql
12401246
{
1241-
offers(order: [{ product_releaseDate: "DESC" }]) {
1247+
offers(product_releaseDate: "DESC") {
12421248
edges {
12431249
node {
12441250
id
@@ -2482,12 +2488,15 @@ For instance, your resource can have properties in camelCase:
24822488
// api/src/Entity/Book.php
24832489
namespace App\Entity;
24842490
2491+
use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter;
24852492
use ApiPlatform\Metadata\ApiResource;
2486-
use ApiPlatform\Metadata\ApiFilter;
2487-
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
2493+
use ApiPlatform\Metadata\QueryParameter;
24882494
2489-
#[ApiResource]
2490-
#[ApiFilter(SearchFilter::class, properties: ['publicationDate' => 'partial'])]
2495+
#[ApiResource(
2496+
parameters: [
2497+
'publicationDate' => new QueryParameter(filter: new PartialSearchFilter()),
2498+
]
2499+
)]
24912500
class Book
24922501
{
24932502
// ...
@@ -2498,7 +2507,7 @@ class Book
24982507
}
24992508
```
25002509

2501-
By default, with the search filter, the query to retrieve a collection will be:
2510+
By default, with the partial search filter, the query to retrieve a collection will be:
25022511

25032512
```graphql
25042513
{
@@ -2531,19 +2540,28 @@ But if you use the `CamelCaseToSnakeCaseNameConverter`, it will be:
25312540
If you use snake_case, you can wonder how to make the difference between an underscore and the
25322541
separator of the nested fields in the filter names, by default an underscore too.
25332542

2543+
API Platform builds the GraphQL argument name from the parameter key. It replaces the dot in that
2544+
key with the nesting separator.
2545+
25342546
For instance if you have this resource:
25352547

25362548
```php
25372549
<?php
25382550
// api/src/Entity/Book.php
25392551
namespace App\Entity;
25402552
2553+
use ApiPlatform\Doctrine\Orm\Filter\ExactFilter;
25412554
use ApiPlatform\Metadata\ApiResource;
2542-
use ApiPlatform\Metadata\ApiFilter;
2543-
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
2555+
use ApiPlatform\Metadata\QueryParameter;
25442556
2545-
#[ApiResource]
2546-
#[ApiFilter(SearchFilter::class, properties: ['relatedBooks.title' => 'exact'])]
2557+
#[ApiResource(
2558+
parameters: [
2559+
'related_books.title' => new QueryParameter(
2560+
filter: new ExactFilter(),
2561+
property: 'relatedBooks.title'
2562+
),
2563+
]
2564+
)]
25472565
class Book
25482566
{
25492567
// ...
@@ -2557,7 +2575,7 @@ class Book
25572575
}
25582576
```
25592577

2560-
You would need to use the search filter like this:
2578+
You would then query the filter like this:
25612579

25622580
```graphql
25632581
{

0 commit comments

Comments
 (0)