Skip to content

fix: 2.7 and 3.0 metadata system #1519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 29, 2022
Merged

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented Mar 15, 2022

TODO:

  • state providers
  • state processors

#[ApiResource]
#[Query]
#[Mutation(name: 'create')]
#[ApiResource(graphQlOperations: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using graphQlOperations?

core/dto.md Outdated

However, it's sometimes useful to use a specific class to represent the input or output data structure related to an operation.

## Specifying an Input or an Output Data Representation
## Implementing a write operation with an input different from the resource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Implementing a write operation with an input different from the resource
## Implementing a Write Operation With an Input Different From the Resource

core/dto.md Outdated

```php
<?php
// api/src/Model/UserResetPasswordDto.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// api/src/Model/UserResetPasswordDto.php
// api/src/Model/User.php

core/dto.md Outdated
throw new NotFoundHttpException();
}

public function resumable(?string $operationName = null, array $context = []): bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function resumable(?string $operationName = null, array $context = []): bool {
public function resumable(?string $operationName = null, array $context = []): bool
{

core/dto.md Outdated
}
```

## Implementing a read operation with an output different from the resource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Implementing a read operation with an output different from the resource
## Implementing a Read Operation With an Output Different From the Resource

core/dto.md Outdated

final class BookRepresentationProvider implements ProviderInterface
{
public function provide(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function provide(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []) {
public function provide(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = [])
{

return $resourceClass === Person::class;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

Comment on lines 81 to 82
public function supports(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []): bool
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function supports(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []): bool
{
public function supports(string $resourceClass, array $identifiers = [], ?string $operationName = null, array $context = []): bool
{

}
```

To cover this use case, we need to `denormalize` the identifier to an instance of our `App\Uuid` class. This case is covered by an identifier denormalizer:
To cover this use case, we need to `convert` the identifier to an instance of our `App\Uuid` class. This case is covered by an uri variable transformer:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To cover this use case, we need to `convert` the identifier to an instance of our `App\Uuid` class. This case is covered by an uri variable transformer:
To cover this use case, we need to `transform` the identifier to an instance of our `App\Uuid` class. This case is covered by an uri variable transformer:


/**
* {@inheritdoc}
* Checks whether the given class is supported for denormalization by this normalizer.
Copy link
Member

@alanpoulain alanpoulain Mar 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Checks whether the given class is supported for denormalization by this normalizer.
* Checks whether the given uri variable is supported for transformation by this transformer.

{
/**
* {@inheritdoc}
* Denormalizes data back into an object of the given class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Denormalizes data back into an object of the given class.
* Transforms a uri variable value.

core/security.md Outdated
@@ -343,4 +347,4 @@ section.

## Changing Serialization Groups Depending of the Current User

See [how to dynamically change](serialization.md#changing-the-serialization-context-dynamically) the current Serializer context according to the current logged in user.
See [how
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

The starting point of a subresource must be a relation on an existing resource.
For example, let's create two entities (Question, Answer) and set up a subresource so that `/question/42/answer` gives us
the answer to the question 42:
## URI variables configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## URI variables configuration
## URI Variables Configuration

In the previous examples, the `method` attribute is mandatory, because the operation name doesn't match a supported HTTP
method.
In this example, we instructed API Platform that the `Answer` we retrieve comes **from** the **class** `Question`
**from** the **propety** `answer` of that class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**from** the **propety** `answer` of that class.
**from** the **property** `answer` of that class.

```

### Access Control of Subresources
### Company employee's
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Company employee's
### Company Employee's


You can control depth of subresources with the parameter `maxDepth`. For example, if the `Answer` entity also has a subresource
such as `comments` and you don't want the route `api/questions/{id}/answers/{id}/comments` to be generated. You can do this by adding the parameter maxDepth in the ApiSubresource annotation or YAML/XML file configuration.
Now lets add the Company class:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Now lets add the Company class:
Now let's add the Company class:

}
```

We did not define any Doctrine annotation here and if we want thinks to work properly with GraphQl, we need to map the `employees` field as a Link to the class `Employee` using the property `company`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We did not define any Doctrine annotation here and if we want thinks to work properly with GraphQl, we need to map the `employees` field as a Link to the class `Employee` using the property `company`.
We did not define any Doctrine annotation here and if we want thinks to work properly with GraphQL, we need to map the `employees` field as a Link to the class `Employee` using the property `company`.


We did not define any Doctrine annotation here and if we want thinks to work properly with GraphQl, we need to map the `employees` field as a Link to the class `Employee` using the property `company`.

As a general rule, if the property we want to crete a link from is in the `fromClass`, use `fromProperty`, if not, use `toProperty`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As a general rule, if the property we want to crete a link from is in the `fromClass`, use `fromProperty`, if not, use `toProperty`.
As a general rule, if the property we want to create a link from is in the `fromClass`, use `fromProperty`, if not, use `toProperty`.

@@ -0,0 +1,145 @@
# Upgrade guide
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Upgrade guide
# Upgrade Guide

@@ -0,0 +1,145 @@
# Upgrade guide

## What changed between 2.6 and 2.7?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## What changed between 2.6 and 2.7?
## What Has Changed Between 2.6 And 2.7?


You can use the `api:upgrade-resource` command to upgrade your resources automatically, [see instructions here](#the-upgrade-command).

### Removal of item/collection operations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Removal of item/collection operations
### Removal of Item/Collection Operations

@soyuka soyuka changed the title fix: API Platform 2.7|3.0 metadata system fix: 2.7 and 3.0 metadata system Mar 16, 2022

public function process($data, array $identifiers = [], ?string $operationName = null, array $context = [])
{
$result = $this->decorated->persist($data, $context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$result = $this->decorated->persist($data, $context);
$result = $this->decorated->process($data, $identifiers, $operationName, $context);

final class BlogPostStateProvider implements ProviderInterface
{
/**
* Provides data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inheritDoc?

$this->mailer = $mailer;
}

public function process($data, array $identifiers = [], ?string $operationName = null, array $context = [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uriVariables?

return $result;
}

public function supports($data, array $identifiers = [], ?string $operationName = null, array $context = []): bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uriVariables?

services:
# ...
'App\DataProvider\BlogPostStateProvider':
tags: [ { name: 'api_platform.state_provider', priority: 2 } ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

priority in comment since it's not the default configuration?

@soyuka soyuka merged commit 1e2fdab into api-platform:main Mar 29, 2022
@soyuka soyuka deleted the fix-metadata-3 branch March 29, 2022 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants