Skip to content

Commit 58d3509

Browse files
committed
Can use type ID in API\Input
1 parent 9c1dee3 commit 58d3509

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

src/Factory/AbstractFactory.php

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ private function adjustNamespace(ReflectionClass $class, string $type): string
101101
*/
102102
final protected function getTypeFromRegistry(string $type, bool $isEntityId): NamedType
103103
{
104+
if ($type === 'ID') {
105+
return Type::id();
106+
}
107+
104108
if ($this->types->isEntity($type) && $isEntityId) {
105109
// @phpstan-ignore-next-line
106110
return $this->types->getId($type);
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace GraphQLTests\Doctrine\Blog\Model\Special;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
use GraphQL\Doctrine\Attribute as API;
9+
use GraphQLTests\Doctrine\Blog\Model\AbstractModel;
10+
11+
#[ORM\Entity]
12+
final class InputWithId extends AbstractModel
13+
{
14+
#[API\Input(type: 'ID[]')]
15+
public function setIds(array $ids): void
16+
{
17+
}
18+
}

tests/InputTypesTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public function testNamespaceSupportInput(): void
4747
$this->assertType('tests/data/NamespaceSupportInput.graphqls', $actual);
4848
}
4949

50+
public function testInputWithId(): void
51+
{
52+
$actual = $this->types->getInput(Blog\Model\Special\InputWithId::class);
53+
$this->assertType('tests/data/InputWithId.graphqls', $actual);
54+
}
55+
5056
public function testInputWithoutTypeMustThrow(): void
5157
{
5258
$type = $this->types->getInput(Blog\Model\Special\NoTypeInput::class);

tests/data/InputWithId.graphqls

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
input InputWithIdInput {
2+
ids: [ID!]!
3+
creationDate: DateTime!
4+
}

0 commit comments

Comments
 (0)