PHP code example of fragseb / graphql-client
1. Go to this page and download the library: Download fragseb/graphql-client 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/ */
fragseb / graphql-client example snippets
declare(strict_types = 1);
use FragSeb\GraphQL\Client;
use FragSeb\GraphQL\Transformer\DataTransformerInterface;
use GuzzleHttp\Client as GuzzleClient;
set_time_limit(0);
id
name
sub {
id
}
}
}
QUERY;
$variables = [
'id' => 'test',
];
$response = $client->query($query, $variables);
var_dump($response->getData());
$transformer = function (string $key) {
return new class ($key) implements DataTransformerInterface {
/**
* @var string
*/
private $key;
public function __construct(string $key)
{
$this->key = $key;
}
public function transform(array $data): array
{
return $data[$this->key];
}
};
};
var_dump($response->getData($transformer('data')));
var_dump($response->getData($transformer('extensions')));