Skip to content

Commit

Permalink
Fix QueryScaffolder not using inheritance types
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Carlino committed Aug 7, 2018
1 parent e84947b commit e9de436
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Scaffolding/Scaffolders/QueryScaffolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getTypeName()
protected function getType(Manager $manager)
{
// If an explicit type name has been provided, use it.
$typeName = $this->getTypeName();
$typeName = parent::getTypeName();
if ($typeName && $manager->hasType($typeName)) {
return $manager->getType($typeName);
}
Expand Down
45 changes: 45 additions & 0 deletions tests/Scaffolding/Scaffolders/QueryScaffolderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace SilverStripe\GraphQL\Tests\Scaffolders\Scaffolding;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\UnionType;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Manager;
use SilverStripe\GraphQL\Scaffolding\Scaffolders\ItemQueryScaffolder;
use SilverStripe\GraphQL\Scaffolding\Scaffolders\SchemaScaffolder;
use SilverStripe\GraphQL\Scaffolding\StaticSchema;
use SilverStripe\GraphQL\Tests\Fake\FakePage;
use SilverStripe\GraphQL\Tests\Fake\FakeRedirectorPage;

class QueryScaffolderTest extends SapphireTest
{
public function testInheritedTypes()
{
$scaffolder = new SchemaScaffolder();
$scaffolder
->type(FakeRedirectorPage::class);
$scaffolder->addToManager($manager = new Manager());
$manager->addType(new ObjectType([
'name' => 'CustomTypeName',
'fields' => [
'Test' => Type::string(),
]
]));
$query = new ItemQueryScaffolder(null, 'CustomTypeName', null, FakePage::class);
$result = $query->scaffold($manager);
$type = $result['type'];
$this->assertInstanceOf(ObjectType::class, $type);
$this->assertEquals('CustomTypeName', $type->config['name']);

$query = new ItemQueryScaffolder(null, null, null, FakePage::class);
$result = $query->scaffold($manager);
$type = $result['type'];
$this->assertInstanceOf(UnionType::class, $type);
$this->assertEquals(
StaticSchema::inst()->inheritanceTypeNameForDataObject(FakePage::class),
$type->config['name']
);
}
}

0 comments on commit e9de436

Please sign in to comment.