Skip to content

feat: add type to InterfaceBuilder.resolveType #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
return $this;
}

/** @return $this */
/**
* @param ResolveType $resolveType
*
* @return $this
*/
public function setResolveType(callable $resolveType): self
{
$this->resolveType = $resolveType;
Expand All @@ -67,7 +71,7 @@
return [
'name' => $this->name,
'description' => $this->description,
'interfaces' => $this->interfaces,

Check warning on line 74 in src/Builder/InterfaceBuilder.php

View workflow job for this annotation

GitHub Actions / Infection

Escaped Mutant for Mutator "ArrayItem": @@ @@ /** @phpstan-return InterfaceConfig */ public function build(): array { - return ['name' => $this->name, 'description' => $this->description, 'interfaces' => $this->interfaces, 'fields' => $this->fields, 'resolveType' => $this->resolveType]; + return ['name' => $this->name, 'description' => $this->description, 'interfaces' > $this->interfaces, 'fields' => $this->fields, 'resolveType' => $this->resolveType]; } }
'fields' => $this->fields,
'resolveType' => $this->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
Loading