Skip to content

Commit

Permalink
Can use type ID in API\Input
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Jul 16, 2024
1 parent 9c1dee3 commit 58d3509
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Factory/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ private function adjustNamespace(ReflectionClass $class, string $type): string
*/
final protected function getTypeFromRegistry(string $type, bool $isEntityId): NamedType
{
if ($type === 'ID') {
return Type::id();
}

if ($this->types->isEntity($type) && $isEntityId) {
// @phpstan-ignore-next-line
return $this->types->getId($type);
Expand Down
18 changes: 18 additions & 0 deletions tests/Blog/Model/Special/InputWithId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace GraphQLTests\Doctrine\Blog\Model\Special;

use Doctrine\ORM\Mapping as ORM;
use GraphQL\Doctrine\Attribute as API;
use GraphQLTests\Doctrine\Blog\Model\AbstractModel;

#[ORM\Entity]
final class InputWithId extends AbstractModel
{
#[API\Input(type: 'ID[]')]
public function setIds(array $ids): void
{
}
}
6 changes: 6 additions & 0 deletions tests/InputTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public function testNamespaceSupportInput(): void
$this->assertType('tests/data/NamespaceSupportInput.graphqls', $actual);
}

public function testInputWithId(): void
{
$actual = $this->types->getInput(Blog\Model\Special\InputWithId::class);
$this->assertType('tests/data/InputWithId.graphqls', $actual);
}

public function testInputWithoutTypeMustThrow(): void
{
$type = $this->types->getInput(Blog\Model\Special\NoTypeInput::class);
Expand Down
4 changes: 4 additions & 0 deletions tests/data/InputWithId.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
input InputWithIdInput {
ids: [ID!]!
creationDate: DateTime!
}

0 comments on commit 58d3509

Please sign in to comment.