Skip to content

Commit

Permalink
Allow FieldDefinitions in ObjectBuilder::setFields() (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod authored Sep 14, 2021
1 parent 70b0aa3 commit 70bde76
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 18 deletions.
6 changes: 5 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
<file>src</file>
<file>tests</file>

<rule ref="Doctrine" />
<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
</rule>
</ruleset>
3 changes: 0 additions & 3 deletions src/Builder/EnumBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public function addValue(string $value, ?string $name = null, ?string $descripti
return $this;
}

/**
* @return mixed[]
*/
public function build(): array
{
$parameters = parent::build();
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/FieldBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function setDeprecationReason(string $reason): self
}

/**
* @return mixed[]
* @return array<string, mixed>
*/
public function build(): array
{
Expand Down
3 changes: 0 additions & 3 deletions src/Builder/InterfaceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public function setResolveType(callable $resolveType): self
return $this;
}

/**
* @return mixed[]
*/
public function build(): array
{
$parameters = parent::build();
Expand Down
8 changes: 3 additions & 5 deletions src/Builder/ObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SimPod\GraphQLUtils\Builder;

use GraphQL\Type\Definition\FieldDefinition;
use GraphQL\Type\Definition\InterfaceType;
use GraphQL\Type\Definition\ResolveInfo;

Expand All @@ -12,7 +13,7 @@ class ObjectBuilder extends TypeBuilder
/** @var InterfaceType[] */
private array $interfaces = [];

/** @var callable|mixed[][] */
/** @var callable():array<FieldDefinition|array<string, mixed>>|array<FieldDefinition|array<string, mixed>> */
private $fields = [];

/** @var callable(mixed, array<mixed>, mixed, ResolveInfo) : mixed|null */
Expand All @@ -37,7 +38,7 @@ public function addInterface(InterfaceType $interfaceType): self
}

/**
* @param callable|mixed[][] $fields
* @param callable():array<FieldDefinition|array<string, mixed>>|array<FieldDefinition|array<string, mixed>> $fields
*
* @return static
*/
Expand All @@ -60,9 +61,6 @@ public function setFieldResolver(callable $fieldResolver): self
return $this;
}

/**
* @return mixed[]
*/
public function build(): array
{
$parameters = parent::build();
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function setDescription(string $description): self
}

/**
* @return mixed[]
* @return array<string, mixed>
*/
public function build(): array
{
Expand Down
3 changes: 0 additions & 3 deletions src/Builder/UnionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public function setTypes(array $types): self
return $this;
}

/**
* @return mixed[]
*/
public function build(): array
{
$parameters = parent::build();
Expand Down
4 changes: 3 additions & 1 deletion tests/Builder/ObjectBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SimPod\GraphQLUtils\Tests\Builder;

use GraphQL\Type\Definition\FieldDefinition;
use GraphQL\Type\Definition\InterfaceType;
use GraphQL\Type\Definition\Type;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -35,6 +36,7 @@ public function __construct()
->setFields(
[
FieldBuilder::create('SomeField', Type::string())->build(),
FieldDefinition::create(FieldBuilder::create('Another', Type::string())->build()),
]
)
->setFieldResolver($fieldResolver)
Expand All @@ -45,7 +47,7 @@ public function __construct()
self::assertArrayHasKey('fields', $object);
self::assertIsArray($object['fields']);
self::assertSame($fieldResolver, $object['resolveField']);
self::assertCount(1, $object['fields']);
self::assertCount(2, $object['fields']);
}

public function testInvalidName(): void
Expand Down

0 comments on commit 70bde76

Please sign in to comment.