Total Complexity | 6 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
9 | class OperationDefinitionWriter extends AbstractWriter |
||
10 | { |
||
11 | /** |
||
12 | * @param NodeInterface|OperationDefinitionNode $node |
||
13 | * @inheritdoc |
||
14 | */ |
||
15 | public function write(NodeInterface $node): string |
||
16 | { |
||
17 | $operation = $node->getOperation(); |
||
|
|||
18 | $name = $this->printNode($node->getName()); |
||
19 | $variablesDefinitions = $this->printNodes($node->getVariableDefinitions()); |
||
20 | $directives = $this->printNodes($node->getDirectives()); |
||
21 | $selectionSet = $this->printNode($node->getSelectionSet()); |
||
22 | |||
23 | // Anonymous queries with no directives or variable definitions can use |
||
24 | // the query short form. |
||
25 | return null === $name && empty($directives) && empty($variablesDefinitions) && $operation === 'query' |
||
26 | ? $selectionSet |
||
27 | : implode(' ', [ |
||
28 | $operation, |
||
29 | $name . wrap('(', implode(', ', $variablesDefinitions), ')'), |
||
30 | implode(' ', $directives), |
||
31 | $selectionSet, |
||
32 | ]); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @inheritdoc |
||
37 | */ |
||
38 | public function supportsWriter(NodeInterface $node): bool |
||
41 | } |
||
42 | } |
||
43 |