PHP code example of cis-bv / gql-builder

1. Go to this page and download the library: Download cis-bv/gql-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/ */

    

cis-bv / gql-builder example snippets


use Cis\GqlBuilder\Query;

$query = new Query('device_list');
$query->setSelectionSet(['id', 'name']);

// or in one line:
$query = (new Query('device_list'))->setSelectionSet(['id', 'name']);

// or as a static Call:
$query = Query::create(name: 'device_list', selectionSet: ['id', 'name']);

// This is not part of the library
$graphQlClient->sendRequest(['query' => (string)$query]);

use Cis\GqlBuilder\Query;
$query = Query::create('device_list', selectionSet: ['id', 'name'])->setOutputFlags(Query::QUERY_PRETTY_PRINT);

use Cis\GqlBuilder\Query;
use Cis\GqlBuilder\Parts\Argument;
use Cis\GqlBuilder\Parts\Variable;
use Cis\GqlBuilder\Enums\VariableTypes;

$query = (new Query())->setSelectionSet([
    (new Query('device_list'))
        ->setSelectionSet([
            'id',
            'name',
            (new Query('interfaces'))->setSelectionSet(['id', 'name']),    
        ])
        ->setArguments([
            new Argument('filters', [
                'name' => ['i_starts_with' => '$name'],
                'has_primary_ip' => true
            ], isQueryType: true),
        ]),
])->setVariables([
    new Variable('name', VariableTypes::String, true),
]);

use Cis\GqlBuilder\Query;

...
    (new Query('interfaces'))->setSelectionSet(['id', 'name'])
...

use Cis\GqlBuilder\Query;

...
    Query::query('interfaces', ['id', 'name'])
...

use Cis\GqlBuilder\Query;
use Cis\GqlBuilder\Enums\VariableTypes;

$query = Query::create(
    name: 'device_list',
    selectionSet: [
        'id',
        'name',
        'status',
        Query::query(
            name: 'interfaces',
            selectionSet: ['id', 'name'],
            arguments: [
                ['filters', ['name' => ['exact' => '$name']], true]
            ]
        )
    ],
    variables: [
        ['name', VariableTypes::String, true]
    ]
);