Skip to content

Commit f34bcb2

Browse files
authored
Merge pull request #4 from moufmouf/output_type
Adding outputType to available methods of GraphQL options
2 parents 932af5a + d5eb68f commit f34bcb2

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/TdbmFluidColumnGraphqlOptions.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ class TdbmFluidColumnGraphqlOptions
1313
* @var TdbmFluidColumnOptions
1414
*/
1515
private $tdbmFluidColumnOptions;
16+
/**
17+
* @var string
18+
*/
19+
private $name;
20+
/**
21+
* @var string
22+
*/
23+
private $outputType;
1624

1725
public function __construct(TdbmFluidColumnOptions $tdbmFluidColumnOptions)
1826
{
@@ -21,10 +29,30 @@ public function __construct(TdbmFluidColumnOptions $tdbmFluidColumnOptions)
2129

2230
public function fieldName(string $name): self
2331
{
24-
$this->addAnnotation('TheCodingMachine\\GraphQLite\\Annotations\\Field', ['name'=>$name]);
32+
$this->name = $name;
33+
$this->generateFieldAnnotation();
34+
return $this;
35+
}
36+
37+
public function outputType(string $outputType): self
38+
{
39+
$this->outputType = $outputType;
40+
$this->generateFieldAnnotation();
2541
return $this;
2642
}
2743

44+
private function generateFieldAnnotation(): void
45+
{
46+
$parameters = array_filter([
47+
'name' => $this->name,
48+
'outputType' => $this->outputType
49+
]);
50+
if (empty($parameters)) {
51+
$parameters = null;
52+
}
53+
$this->addAnnotation('TheCodingMachine\\GraphQLite\\Annotations\\Field', $parameters);
54+
}
55+
2856
public function logged(bool $mustBeLogged = true): self
2957
{
3058
if ($mustBeLogged) {

tests/TdbmFluidColumnGraphqlOptionsTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ public function testGraphql()
3030
@TheCodingMachine\GraphQLite\Annotations\Right(name = \"CAN_EDIT\")
3131
@TheCodingMachine\GraphQLite\Annotations\FailWith(null)", $schema->getTable('posts')->getColumn('foo')->getComment());
3232

33-
$graphqlOptions->logged(false);
33+
$graphqlOptions->logged(false)
34+
->outputType('ID');
3435

35-
$this->assertSame("\n@TheCodingMachine\GraphQLite\Annotations\Field(name = \"bar\")
36-
@TheCodingMachine\GraphQLite\Annotations\Right(name = \"CAN_EDIT\")
37-
@TheCodingMachine\GraphQLite\Annotations\FailWith(null)", $schema->getTable('posts')->getColumn('foo')->getComment());
36+
37+
$this->assertSame("\n@TheCodingMachine\GraphQLite\Annotations\Right(name = \"CAN_EDIT\")
38+
@TheCodingMachine\GraphQLite\Annotations\FailWith(null)
39+
@TheCodingMachine\GraphQLite\Annotations\Field(name = \"bar\", outputType = \"ID\")", $schema->getTable('posts')->getColumn('foo')->getComment());
3840

3941
$this->assertSame($columnOptions, $graphqlOptions->endGraphql());
4042

0 commit comments

Comments
 (0)