PHP code example of dpauli / graphql-request-builder

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

    

dpauli / graphql-request-builder example snippets



declare(strict_types=1);

use GraphQL\RequestBuilder\Argument;
use GraphQL\RequestBuilder\RootType;
use GraphQL\RequestBuilder\Type;

$searchType = (new Type('search'))
    ->addArgument(new Argument('criteria', new Argument('start', '2019-08-23')))
    ->addSubTypes([
        (new Type('errors'))->addSubTypes(['code', 'type', 'description']),
        'id'
    ]
);

echo (string) (new RootType('field'))->addSubType($searchType);


declare(strict_types=1);

use GraphQL\RequestBuilder\Argument;
use GraphQL\RequestBuilder\ArrayArgument;

$persons = new ArrayArgument(
    'persons',
    [new Argument('age', 30), new Argument('age', 20), new Argument('age', 12)]
);


declare(strict_types=1);

use GraphQL\RequestBuilder\Argument;
use GraphQL\RequestBuilder\ArrayArgument;

$person1 = new ArrayArgument('', [new Argument('name', 'Hans'), new Argument('age', 30)]);
$person2 = new ArrayArgument('', [new Argument('name', 'Max'), new Argument('age', 20)]);

$persons = new ArrayArgument('persons', [$person1, $person2]);


declare(strict_types=1);

use GraphQL\RequestBuilder\EnumArgument;

$person1 = new EnumArgument('EnumAttribute', 'EnumValue');