PHP code example of mathsgod / light-graphql

1. Go to this page and download the library: Download mathsgod/light-graphql 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/ */

    

mathsgod / light-graphql example snippets


namespace Controllers;

use TheCodingMachine\GraphQLite\Annotations\Query;

class UserController
{
    #[Query]
    public function hello(): string
    {
        return 'world';
    }
}



$server = new \Light\GraphQL\Server();
$server->getSchemaFactory()->addNamespace('Controllers');

$result = $server->executeQuery('{ hello }');
print_r($result->toArray());

$server = new \Light\GraphQL\Server();
$server->getSchemaFactory()->addNamespace('Controllers');

// $request is a PSR-7 ServerRequestInterface
$response = $server->handle($request);

$server = new \Light\GraphQL\Server(
    defaultLifetime: 15,   // Schema cache TTL in seconds (default: 15)
    debug: false,          // Enable debug mode (default: false)
    container: null        // Custom PSR-11 container (default: League\Container)
);