forked from silverstripe/silverstripe-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Useful if types want to implement more than one interface
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |