|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace TheCodingMachine\GraphQLite\Annotations; |
| 6 | + |
| 7 | +/** |
| 8 | + * Shared base for every attribute that declares an invokable GraphQL schema element with a |
| 9 | + * return type — {@see Query}, {@see Mutation}, {@see Subscription}, and {@see Field}. Each of |
| 10 | + * those attributes inherits a GraphQL-level name, an explicit return type override, and a |
| 11 | + * schema description from this class. |
| 12 | + */ |
| 13 | +abstract class AbstractGraphQLElement |
| 14 | +{ |
| 15 | + private string|null $outputType; |
| 16 | + |
| 17 | + private string|null $name; |
| 18 | + |
| 19 | + private string|null $description; |
| 20 | + |
| 21 | + /** @param mixed[] $attributes */ |
| 22 | + public function __construct( |
| 23 | + array $attributes = [], |
| 24 | + string|null $name = null, |
| 25 | + string|null $outputType = null, |
| 26 | + string|null $description = null, |
| 27 | + ) { |
| 28 | + $this->outputType = $outputType ?? $attributes['outputType'] ?? null; |
| 29 | + $this->name = $name ?? $attributes['name'] ?? null; |
| 30 | + $this->description = $description ?? $attributes['description'] ?? null; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Returns the GraphQL return type for this schema element (as a string). |
| 35 | + * The string can represent the FQCN of the type or an entry in the container resolving to the GraphQL type. |
| 36 | + */ |
| 37 | + public function getOutputType(): string|null |
| 38 | + { |
| 39 | + return $this->outputType; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Returns the GraphQL name of the query/mutation/subscription/field. |
| 44 | + * If not specified, the name of the PHP method is used instead. |
| 45 | + */ |
| 46 | + public function getName(): string|null |
| 47 | + { |
| 48 | + return $this->name; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Returns the explicit description for this schema element, or null if none was provided. |
| 53 | + * |
| 54 | + * A null return means "no explicit description" and the schema builder may fall back to the |
| 55 | + * docblock summary (if docblock descriptions are enabled on the SchemaFactory). An explicit |
| 56 | + * empty string blocks the docblock fallback and produces an empty description. |
| 57 | + */ |
| 58 | + public function getDescription(): string|null |
| 59 | + { |
| 60 | + return $this->description; |
| 61 | + } |
| 62 | +} |
0 commit comments