Skip to content

[GraphQL] Deprecation support #1962

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 1 commit into from
May 23, 2018
Merged

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented May 22, 2018

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR todo

Allows to deprecate GraphQL fields and resources:

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;

/**
 * @ApiResource(deprecationReason="This resource is deprecated")
 */
class DeprecatedResource
{
    public $id;

    /**
     * @ApiProperty(deprecationReason="This field is deprecated")
     */
    public $deprecatedField;
}

I'll add support for the same attribute in both Swagger and Hydra (using OWL) in subsequent Pull Requests.

As you can see, @ApiProperty's doesn't support the simplified attributes syntax introduced in #1788 , it would be nice to support this too. (fixed in #1963)

ping @alanpoulain

@dunglas dunglas requested a review from meyerbaptiste May 22, 2018 12:51
public function theGraphQLFieldIsDeprecatedForTheReason(string $fieldName, string $reason)
{
foreach (json_decode($this->request->getContent(), true)['data']['__type']['fields'] as $field) {
if ($fieldName === $field['name'] && $field['isDeprecated'] & $reason === $field['deprecationReason']) {
Copy link
Member

Choose a reason for hiding this comment

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

& => &&

@dunglas dunglas merged commit bd114f5 into api-platform:master May 23, 2018
@dunglas dunglas deleted the deprecation branch May 23, 2018 15:01
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.

4 participants