Skip to content

Instantly share code, notes, and snippets.

@fritz-gerneth
Last active December 21, 2016 08:32
Show Gist options
  • Save fritz-gerneth/b9b9c2b3596fc6e4fac408037bda815c to your computer and use it in GitHub Desktop.
Save fritz-gerneth/b9b9c2b3596fc6e4fac408037bda815c to your computer and use it in GitHub Desktop.
<?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