Skip to content

Commit 35f85c6

Browse files
alanpoulainsoyuka
authored andcommitted
Better handling of relations without Doctrine. (api-platform#3591)
1 parent 9ccf578 commit 35f85c6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/GraphQl/Type/TypeConverter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public function convertType(Type $type, bool $input, ?string $queryName, ?string
6262
return GraphQLType::string();
6363
case Type::BUILTIN_TYPE_ARRAY:
6464
case Type::BUILTIN_TYPE_ITERABLE:
65+
if ($resourceType = $this->getResourceType($type, $input, $queryName, $mutationName, $depth)) {
66+
return $resourceType;
67+
}
68+
6569
return 'Iterable';
6670
case Type::BUILTIN_TYPE_OBJECT:
6771
if ($input && $depth > 0) {

tests/GraphQl/Type/TypeConverterTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ public function testConvertTypeResourceClassNotFound(): void
120120
$this->assertNull($graphqlType);
121121
}
122122

123-
public function testConvertTypeResource(): void
123+
/**
124+
* @dataProvider convertTypeResourceProvider
125+
*/
126+
public function testConvertTypeResource(Type $type, ObjectType $expectedGraphqlType): void
124127
{
125128
$graphqlResourceMetadata = (new ResourceMetadata())->withGraphql(['test']);
126-
$type = new Type(Type::BUILTIN_TYPE_OBJECT, false, null, true, null, new Type(Type::BUILTIN_TYPE_OBJECT, false, 'dummyValue'));
127-
$expectedGraphqlType = new ObjectType(['name' => 'resourceObjectType']);
128129

129130
$this->typeBuilderProphecy->isCollection($type)->shouldBeCalled()->willReturn(true);
130131
$this->resourceMetadataFactoryProphecy->create('dummyValue')->shouldBeCalled()->willReturn($graphqlResourceMetadata);
@@ -134,6 +135,14 @@ public function testConvertTypeResource(): void
134135
$this->assertEquals($expectedGraphqlType, $graphqlType);
135136
}
136137

138+
public function convertTypeResourceProvider(): array
139+
{
140+
return [
141+
[new Type(Type::BUILTIN_TYPE_OBJECT, false, null, true, null, new Type(Type::BUILTIN_TYPE_OBJECT, false, 'dummyValue')), new ObjectType(['name' => 'resourceObjectType'])],
142+
[new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, null, new Type(Type::BUILTIN_TYPE_OBJECT, false, 'dummyValue')), new ObjectType(['name' => 'resourceObjectType'])],
143+
];
144+
}
145+
137146
/**
138147
* @dataProvider resolveTypeProvider
139148
*

0 commit comments

Comments
 (0)