Last active
September 17, 2017 22:01
-
-
Save florentdestremau/0a3a023c2216f4e0b2b95611dbc80756 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 | |
namespace AppBundle\GraphQL\Type; | |
use AppBundle\Entity\User; | |
use Misd\PhoneNumberBundle\Templating\Helper\PhoneNumberFormatHelper; | |
use Youshido\GraphQL\Config\Object\ObjectTypeConfig; | |
use Youshido\GraphQL\Execution\ResolveInfo; | |
use Youshido\GraphQL\Field\Field; | |
use Youshido\GraphQL\Type\Object\AbstractObjectType; | |
use Youshido\GraphQL\Type\Scalar\IdType; | |
use Youshido\GraphQL\Type\Scalar\StringType; | |
class UserType extends AbstractObjectType | |
{ | |
/** | |
* @param ObjectTypeConfig $config | |
*/ | |
public function build($config) | |
{ | |
$config->addFields( | |
[ | |
'id' => new IdType(), | |
'firstName' => new StringType(), | |
'lastName' => new StringType(), | |
'phoneNumber' => new Field( | |
[ | |
'name' => 'phoneNumber', | |
'type' => new StringType(), | |
'resolve' => function (User $user, array $args, ResolveInfo $info) { | |
if (null === $user->getPhoneNumber()) return null; | |
/** @var PhoneNumberFormatHelper $phoneNumberTemplater */ | |
$phoneNumberTemplater = $info | |
->getContainer() | |
->get('misd_phone_number.templating.helper.format'); | |
return $phoneNumberTemplater->format($user->getPhoneNumber()); | |
}, | |
] | |
), | |
] | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment