Last active
December 21, 2016 08:32
-
-
Save fritz-gerneth/b9b9c2b3596fc6e4fac408037bda815c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
class SingleGroupQuery extends AbstractField | |
{ | |
use ServiceLocatorAwareTrait; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getType() | |
{ | |
return new GroupType(); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getName() | |
{ | |
return 'group'; | |
} | |
public function build(FieldConfig $config) | |
{ | |
parent::build($config); | |
$this->addArgument('id', [ | |
'type' => new NonNullType(new IdType()) | |
]); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function resolve($value, array $args, ResolveInfo $info) | |
{ | |
if (!array_key_exists('id', $args) || !is_string($args['id'])) { | |
throw new InvalidArgumentException('Argument ID must be a a string'); | |
} | |
/** @var GroupServiceInterface $groupService */ | |
$groupService = $this->getServiceLocator($info)->get(GroupServiceInterface::class); | |
return $groupService->find($args['id']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment