Skip to content

Commit 1484962

Browse files
authored
Merge pull request #2237 from dunglas/fix-null-classname
GraphQL: fix a bug when the class name isn't provided
2 parents eed4ff7 + bd3261a commit 1484962

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/GraphQl/Type/SchemaBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ private function convertType(Type $type, bool $input = false, string $mutationNa
366366
}
367367

368368
$resourceClass = $this->isCollection($type) ? $type->getCollectionValueType()->getClassName() : $type->getClassName();
369+
if (null === $resourceClass) {
370+
return null;
371+
}
372+
369373
try {
370374
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
371375
if ([] === $resourceMetadata->getGraphql() ?? []) {

tests/GraphQl/Type/SchemaBuilderTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,37 @@ public function testGetSchema(bool $paginationEnabled)
209209
);
210210
}
211211

212+
/**
213+
* Tests that the GraphQL SchemaBuilder supports an edge case where a property is typed as an Type::BUILTIN_TYPE_OBJECT but has no class related.
214+
*/
215+
public function testObjectTypeWithoutClass()
216+
{
217+
$propertyMetadataMockBuilder = function ($builtinType, $resourceClassName) {
218+
return new PropertyMetadata(
219+
new Type(
220+
$builtinType
221+
),
222+
"{$builtinType}Description",
223+
true,
224+
true,
225+
null,
226+
null,
227+
null
228+
);
229+
};
230+
231+
$mockedSchemaBuilder = $this->createSchemaBuilder($propertyMetadataMockBuilder, false);
232+
$this->assertEquals([
233+
'node',
234+
'shortName1',
235+
'shortName1s',
236+
'shortName2',
237+
'shortName2s',
238+
'shortName3',
239+
'shortName3s',
240+
], array_keys($mockedSchemaBuilder->getSchema()->getConfig()->getQuery()->getFields()));
241+
}
242+
212243
public function paginationProvider(): array
213244
{
214245
return [

0 commit comments

Comments
 (0)