1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Language\ASTBuilder; |
4
|
|
|
|
5
|
|
|
use Digia\GraphQL\Language\KeywordEnum; |
6
|
|
|
use Digia\GraphQL\Language\LexerInterface; |
7
|
|
|
use Digia\GraphQL\Language\Node\NodeKindEnum; |
8
|
|
|
use Digia\GraphQL\Language\TokenKindEnum; |
9
|
|
|
|
10
|
|
|
class ObjectTypeExtensionASTBuilder extends AbstractASTBuilder |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @inheritdoc |
14
|
|
|
*/ |
15
|
|
|
public function supportsBuilder(string $kind): bool |
16
|
|
|
{ |
17
|
|
|
return $kind === ASTKindEnum::OBJECT_TYPE_EXTENSION; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @inheritdoc |
22
|
|
|
*/ |
23
|
|
|
public function build(LexerInterface $lexer, array $params): ?array |
24
|
|
|
{ |
25
|
|
|
$start = $lexer->getToken(); |
26
|
|
|
|
27
|
|
|
$this->expectKeyword($lexer, KeywordEnum::EXTEND); |
28
|
|
|
$this->expectKeyword($lexer, KeywordEnum::TYPE); |
29
|
|
|
|
30
|
|
|
$name = $this->buildAST(ASTKindEnum::NAME, $lexer); |
31
|
|
|
$interfaces = $this->buildAST(ASTKindEnum::IMPLEMENTS_INTERFACES, $lexer); |
32
|
|
|
$directives = $this->buildAST(ASTKindEnum::DIRECTIVES, $lexer); |
33
|
|
|
$fields = $this->buildAST(ASTKindEnum::FIELDS_DEFINITION, $lexer);; |
34
|
|
|
|
35
|
|
|
if (count($interfaces) === 0 && count($directives) === 0 && count($fields) === 0) { |
36
|
|
|
throw $this->unexpected($lexer); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return [ |
40
|
|
|
'kind' => NodeKindEnum::OBJECT_TYPE_EXTENSION, |
41
|
|
|
'name' => $name, |
42
|
|
|
'interfaces' => $interfaces, |
43
|
|
|
'directives' => $directives, |
44
|
|
|
'fields' => $fields, |
45
|
|
|
'loc' => $this->buildLocation($lexer, $start), |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|