Skip to content

Commit c002f86

Browse files
authored
feat: add type to InterfaceBuilder.resolveType (#174)
1 parent dc08b73 commit c002f86

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Builder/InterfaceBuilder.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44

55
namespace SimPod\GraphQLUtils\Builder;
66

7+
use GraphQL\Type\Definition\AbstractType;
78
use GraphQL\Type\Definition\FieldDefinition;
89
use GraphQL\Type\Definition\InterfaceType;
910

1011
/**
11-
* @see InterfaceType
12-
*
1312
* @phpstan-import-type InterfaceConfig from InterfaceType
13+
* @phpstan-import-type ResolveType from AbstractType
1414
*/
1515
class InterfaceBuilder extends TypeBuilder
1616
{
1717
/** @var InterfaceType[] */
1818
private array $interfaces = [];
1919

20-
/** @var callable|null */
20+
/** @var ResolveType|null */
2121
private $resolveType;
2222

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

56-
/** @return $this */
56+
/**
57+
* @param ResolveType $resolveType
58+
*
59+
* @return $this
60+
*/
5761
public function setResolveType(callable $resolveType): self
5862
{
5963
$this->resolveType = $resolveType;

tests/Builder/InterfaceBuilderTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct()
3939
],
4040
)
4141
->setResolveType(
42-
static fn (bool $value): Type => $value ? Type::string() : Type::int(),
42+
static fn (mixed $value) => $value === true ? 'type' : null,
4343
)
4444
->build();
4545

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

6262
public function testInvalidValue(): void

0 commit comments

Comments
 (0)