fragseb / graphql-client
v0.0.1
2019-07-12 06:00 UTC
Requires
- php: ^7.1
- fig/http-message-util: ^1.1
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- composer/composer: ^1.8
- dealerdirect/phpcodesniffer-composer-installer: ^0.5.0
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: ^0.11.12
- phpunit/phpunit: ^7.0
- slevomat/coding-standard: ^5.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2025-03-12 19:27:08 UTC
README
PHP Client for GraphQL
<?php declare(strict_types = 1); use FragSeb\GraphQL\Client; use FragSeb\GraphQL\Transformer\DataTransformerInterface; use GuzzleHttp\Client as GuzzleClient; set_time_limit(0); require __DIR__ . '/../vendor/autoload.php'; $client = new Client(new GuzzleClient([ 'base_uri' => 'https://example.com/api/v1/graphql' ])); $query = <<<'QUERY' query Foo($id: String!) { bar(id: $id) { 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')));