Skip to content

Commit

Permalink
Revert short syntax for @annotation and better deprecation handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincz committed Jan 13, 2021
1 parent c7b8cab commit 7224b18
Show file tree
Hide file tree
Showing 37 changed files with 211 additions and 366 deletions.
37 changes: 12 additions & 25 deletions docs/annotations/annotations-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ class Coordinates {
}
```

## Annotations shortcuts

When using annotations or attributes, you can use a shortened version of the syntax.
Example without:
`@GQL\Field(name="MyField")`

Example with shortcut:
`@GQL\Field("MyField")`

When the short version is used (ie. the attribute name is not specified), the attribute describe as `default attribute` in the annotation's attributes list will be use.
In the above example, the attribute `name` on `@GQL\Field` is the default attribute.


## Index

[@Access](#access)
Expand Down Expand Up @@ -131,7 +118,7 @@ This annotation is used in conjunction with a `@Field`, a `@Query` or `@Mutation

Required attributes:

- **name** (default attribute): The GraphQL name of the field argument (default to class name).
- **name** : The GraphQL name of the field argument (default to class name).
- **type** : The GraphQL type of the field argument

Optional attributes:
Expand Down Expand Up @@ -169,7 +156,7 @@ It is used to set an arguments builder for a field (see [Args builders](../defin

Required attributes:

- **value** (default attribute): The name of the args builder
- **value** : The name of the args builder

Optional attributes:

Expand Down Expand Up @@ -249,7 +236,7 @@ In order to add more meta on the values (like description or deprecated reason),

Optional attributes:

- **name** (default attribute): The GraphQL name of the enum (default to the class name without namespace)
- **name** : The GraphQL name of the enum (default to the class name without namespace)

Deprecated attributes:
- **values** : An array of `@EnumValue`to define description or deprecated reason of enum values
Expand Down Expand Up @@ -288,7 +275,7 @@ The attribute `name` must match a constant name on the class.

Required attributes:

- **name** (default attribute): The name of the targeted enum value
- **name** : The name of the targeted enum value

Optional attributes:

Expand All @@ -311,7 +298,7 @@ If it is defined on a _method_ of the Root Query or the Root mutation :

Optional attributes:

- **name** (default attribute) : The GraphQL name of the field (default to the property name). If you don't specify a `resolve` attribute while changing the `name`, the default one will be '@=value.<property_name>'
- **name** : The GraphQL name of the field (default to the property name). If you don't specify a `resolve` attribute while changing the `name`, the default one will be '@=value.<property_name>'
- **type** : The GraphqL type of the field. This attribute can sometimes be guessed automatically from Doctrine ORM annotations
- **resolve** : A resolution expression

Expand Down Expand Up @@ -373,7 +360,7 @@ It is used to set a field builder for a field (see [Field builders](../definitio

Required attributes:

- **value** (default attribute): The name of the field builder
- **value** : The name of the field builder

Optional attributes:

Expand Down Expand Up @@ -404,7 +391,7 @@ It is used to add fields builder to types (see [Fields builders](../definitions/

Required attributes:

- **value** (default attribute) : The name of the fields builder
- **value** : The name of the fields builder

Optional attributes:

Expand Down Expand Up @@ -433,7 +420,7 @@ An Input type is pretty much the same as an input, except:

Optional attributes:

- **name** (default attribute) : The GraphQL name of the input field (default to classnameInput )
- **name** : The GraphQL name of the input field (default to classnameInput )
- **isRelay** : Set to true if you want your input to be relay compatible (ie. An extra field `clientMutationId` will be added to the input)

The corresponding class will also be used by the `Arguments Transformer` service. An instance of the corresponding class will be use as the `input` value if it is an argument of a query or mutation. (see [The Arguments Transformer documentation](arguments-transformer.md)).
Expand Down Expand Up @@ -563,7 +550,7 @@ This annotation is used on _class_ to define a GraphQL Type.

Optional attributes:

- **name** (default attribute) : The GraphQL name of the type (default to the class name without namespace)
- **name** : The GraphQL name of the type (default to the class name without namespace)
- **interfaces** : An array of GraphQL interface this type inherits from (can be auto-guessed. See interface documentation).
- **isRelay** : Set to true to have a Relay compatible type (ie. A `clientMutationId` will be added).
- **isTypeOf** : Is type of resolver for interface implementation
Expand Down Expand Up @@ -597,15 +584,15 @@ Required attributes:

Optional attributes:

- **name** (default attribute) : The GraphQL name of the interface (default to the class name without namespace)
- **name** : The GraphQL name of the interface (default to the class name without namespace)

## @Scalar

This annotation is used on a _class_ to define a custom scalar.

Optional attributes:

- **name** (default attribute) : The GraphQL name of the interface (default to the class name without namespace)
- **name** : The GraphQL name of the interface (default to the class name without namespace)
- **scalarType** : An expression to reuse an other scalar type

Example:
Expand Down Expand Up @@ -663,7 +650,7 @@ Required attributes:

Optional attributes:

- **name** (default attribute) : The GraphQL name of the union (default to the class name without namespace)
- **name** : The GraphQL name of the union (default to the class name without namespace)
- **resolveType** : Expression to resolve an object type. By default, it'll use a static method `resolveType` on the related class and call it with the `type resolver` as first argument and then the `value`.

Example:
Expand Down
4 changes: 0 additions & 4 deletions src/Annotation/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ final class Access extends Annotation implements NamedArgumentConstructorAnnotat
{
/**
* Field access.
*
* @Required
*
* @var string
*/
public string $value;

Expand Down
24 changes: 7 additions & 17 deletions src/Annotation/Arg.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Overblog\GraphQLBundle\Annotation;

use \Attribute;
use Attribute;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
Expand All @@ -18,26 +18,16 @@ final class Arg extends Annotation implements NamedArgumentConstructorAnnotation
{
/**
* Argument name.
*
* @Required
*
* @var string
*/
public string $name;

/**
* Argument description.
*
* @var string
*/
public ?string $description;

/**
* Argument type.
*
* @Required
*
* @var string
*/
public string $type;

Expand All @@ -49,14 +39,14 @@ final class Arg extends Annotation implements NamedArgumentConstructorAnnotation
public $default;

/**
* @param mixed|null $default
* @param string $name The name of the argument
* @param string $type The type of the argument
* @param string|null $description The description of the argument
* @param mixed|null $default Default value of the argument
*/
public function __construct(string $name, string $type, ?string $description = null, $default = null, ?string $value = null)
public function __construct(string $name, string $type, ?string $description = null, $default = null)
{
if ($value && $name) {
$this->cumulatedAttributesException('name', $value, $name);
}
$this->name = $value ?: $name;
$this->name = $name;
$this->description = $description;
$this->type = $type;
$this->default = $default;
Expand Down
18 changes: 8 additions & 10 deletions src/Annotation/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Overblog\GraphQLBundle\Annotation;

use \Attribute;
use Attribute;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
Expand All @@ -18,23 +18,21 @@ abstract class Builder extends Annotation implements NamedArgumentConstructorAnn
{
/**
* Builder name.
*
* @Required
*
* @var string
*/
public string $value;
public string $name;

/**
* The builder config.
*
* @var array
*/
public array $config = [];

public function __construct(string $value, array $config = [])
/**
* @param string|null $name The name of the builder
* @param array $config The builder configuration array
*/
public function __construct(string $name = null, array $config = [])
{
$this->value = $value;
$this->name = $name;
$this->config = $config;
}
}
6 changes: 1 addition & 5 deletions src/Annotation/Description.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Overblog\GraphQLBundle\Annotation;

use \Attribute;
use Attribute;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
Expand All @@ -18,10 +18,6 @@ final class Description extends Annotation implements NamedArgumentConstructorAn
{
/**
* The object description.
*
* @Required
*
* @var string
*/
public string $value;

Expand Down
21 changes: 11 additions & 10 deletions src/Annotation/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace Overblog\GraphQLBundle\Annotation;

use \Attribute;
use Doctrine\Common\Annotations\AnnotationException;
use Attribute;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
Expand All @@ -19,24 +18,26 @@ final class Enum extends Annotation implements NamedArgumentConstructorAnnotatio
{
/**
* Enum name.
*
* @var string
*/
public ?string $name;

/**
* @var array<\Overblog\GraphQLBundle\Annotation\EnumValue>
*
*
* @deprecated
*/
public array $values;

public function __construct(?string $name = null, array $values = [], ?string $value = null)
/**
* @param string|null $name The GraphQL name of the enum
* @param array<EnumValue> $values An array of @GQL\EnumValue @deprecated
*/
public function __construct(?string $name = null, array $values = [])
{
if ($name && $value) {
$this->cumulatedAttributesException('name', $value, $name);
}
$this->name = $value ?: $name;
$this->name = $name;
$this->values = $values;
if (!empty($values)) {
@trigger_error('The attributes "values" on annotation @GQL\Enum is deprecated as of 0.14 and will be removed in 1.0. Use the @GQL\EnumValue annotation on the class itself instead.', E_USER_DEPRECATED);
}
}
}
14 changes: 7 additions & 7 deletions src/Annotation/EnumValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Overblog\GraphQLBundle\Annotation;

use Attribute;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

/**
Expand All @@ -13,7 +12,6 @@
* @Annotation
* @Target({"ANNOTATION", "CLASS"})
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final class EnumValue extends Annotation implements NamedArgumentConstructorAnnotation
{
/**
Expand All @@ -31,12 +29,14 @@ final class EnumValue extends Annotation implements NamedArgumentConstructorAnno
*/
public ?string $deprecationReason;

public function __construct(?string $name = null, ?string $description = null, ?string $deprecationReason = null, ?string $value = null)
/**
* @param string|null $name The constant name to attach description or deprecation reason to
* @param string|null $description The description of the enum value
* @param string|null $deprecationReason The deprecation reason of the enum value
*/
public function __construct(?string $name = null, ?string $description = null, ?string $deprecationReason = null)
{
if ($name && $value) {
$this->cumulatedAttributesException('name', $value, $name);
}
$this->name = $value ?: $name;
$this->name = $name;
$this->description = $description;
$this->deprecationReason = $deprecationReason;
}
Expand Down
Loading

0 comments on commit 7224b18

Please sign in to comment.