Skip to content

Commit

Permalink
feat: add type to InterfaceBuilder.resolveType (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod authored Jan 6, 2025
1 parent dc08b73 commit c002f86
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/Builder/InterfaceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

namespace SimPod\GraphQLUtils\Builder;

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

/**
* @see InterfaceType
*
* @phpstan-import-type InterfaceConfig from InterfaceType
* @phpstan-import-type ResolveType from AbstractType
*/
class InterfaceBuilder extends TypeBuilder
{
/** @var InterfaceType[] */
private array $interfaces = [];

/** @var callable|null */
/** @var ResolveType|null */
private $resolveType;

/** @var array<FieldDefinition|array<string, mixed>>|callable():array<FieldDefinition|array<string, mixed>> */
Expand Down Expand Up @@ -53,7 +53,11 @@ public function setFields(callable|array $fields): self
return $this;
}

/** @return $this */
/**
* @param ResolveType $resolveType
*
* @return $this
*/
public function setResolveType(callable $resolveType): self
{
$this->resolveType = $resolveType;
Expand Down
6 changes: 3 additions & 3 deletions tests/Builder/InterfaceBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct()
],
)
->setResolveType(
static fn (bool $value): Type => $value ? Type::string() : Type::int(),
static fn (mixed $value) => $value === true ? 'type' : null,
)
->build();

Expand All @@ -55,8 +55,8 @@ public function __construct()
self::assertCount(1, $interface['fields']);
self::assertArrayHasKey('resolveType', $interface);
self::assertIsCallable($interface['resolveType']);
self::assertSame(Type::string(), $interface['resolveType'](true, null, $resolveInfo));
self::assertSame(Type::int(), $interface['resolveType'](false, null, $resolveInfo));
self::assertSame('type', $interface['resolveType'](true, null, $resolveInfo));
self::assertNull($interface['resolveType'](false, null, $resolveInfo));
}

public function testInvalidValue(): void
Expand Down

0 comments on commit c002f86

Please sign in to comment.