Skip to content

Instantly share code, notes, and snippets.

@florentdestremau
Last active September 17, 2017 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florentdestremau/0a3a023c2216f4e0b2b95611dbc80756 to your computer and use it in GitHub Desktop.
Save florentdestremau/0a3a023c2216f4e0b2b95611dbc80756 to your computer and use it in GitHub Desktop.
<?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