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.
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
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,47 @@ | ||
<?php | ||
|
||
namespace Chillu\GraphQL; | ||
|
||
use GraphQL\Type\Definition\InterfaceType as BaseInterfaceType; | ||
|
||
class InterfaceTypeCreator extends TypeCreator { | ||
|
||
protected function getTypeResolver() | ||
{ | ||
if(!method_exists($this, 'resolveType')) | ||
{ | ||
return null; | ||
} | ||
|
||
$resolver = array($this, 'resolveType'); | ||
return function() use ($resolver) | ||
{ | ||
$args = func_get_args(); | ||
return call_user_func_array($resolver, $args); | ||
}; | ||
} | ||
|
||
/** | ||
* Get the attributes from the container. | ||
* | ||
* @return array | ||
*/ | ||
public function getAttributes() | ||
{ | ||
$attributes = parent::getAttributes(); | ||
|
||
$resolver = $this->getTypeResolver(); | ||
if(isset($resolver)) | ||
{ | ||
$attributes['resolveType'] = $resolver; | ||
} | ||
|
||
return $attributes; | ||
} | ||
|
||
public function toType() | ||
{ | ||
return new BaseInterfaceType($this->toArray()); | ||
} | ||
|
||
} |
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