PHP code example of player259 / graphql-bundle

1. Go to this page and download the library: Download player259/graphql-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

player259 / graphql-bundle example snippets


// config/bundles.php
return [
    // ...
    Player259\GraphQLBundle\Player259GraphQLBundle::class => ['all' => true],
];



namespace App\GraphQL;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use Symfony\Component\Security\Core\Security;

class QueryType extends ObjectType
{
    public function __construct()
    {
        $config = [
            'name' => 'Query',
            'fields' => [
                'username' => [
                    'type' => Type::string(),
                    'description' => 'Current User username',
                ],
            ],
        ];

        parent::__construct($config);
    }

    public function resolveUsername(Security $security): ?string
    {
        return $security->getUser() ? $security->getUser()->getUsername() : null;
    }
}