Skip to content

Commit

Permalink
DataObjectInterfaceCreator
Browse files Browse the repository at this point in the history
Useful if types want to implement more than one interface
  • Loading branch information
chillu committed Oct 2, 2016
1 parent dfcca94 commit 96ca94c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/DataObjectInterfaceTypeCreator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Chillu\GraphQL;

use Chillu\GraphQL\Util\CaseInsensitiveFieldAccessor;
use GraphQL\Type\Definition\Type;

class DataObjectInterfaceTypeCreator extends InterfaceTypeCreator {

public function attributes()
{
return [
'name' => 'DataObject',
'description' => 'Base Interface',
];
}

public function fields() {
return [
'id' => [
'type' => Type::nonNull(Type::int()),
],
'created' => [
'type' => Type::string(),
],
'lastEdited' => [
'type' => Type::string(),
],

];
}

public function resolveType($object)
{
$type = null;

if($fqnType = $this->manager->getType(get_class($object))) {
$type = $fqnType;
}

if($baseType = $this->manager->getType(get_class($object))) {
$type = $baseType;
}

return $type;
}

}

0 comments on commit 96ca94c

Please sign in to comment.