softonic / graphql-client
Softonic GraphQL client
Installs: 726 902
Dependents: 2
Suggesters: 0
Security: 0
Stars: 98
Watchers: 8
Forks: 20
Open Issues: 1
Requires
- php: >=7.0
- guzzlehttp/guzzle: ^6.3 || ^7.0
- softonic/guzzle-oauth2-middleware: ^1.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.4
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2022-06-21 19:58:46 UTC
README
PHP Client for GraphQL
Installation
Via composer:
composer require softonic/graphql-client
Documentation
To instantiate a client with an OAuth2 provider:
<?php $options = [ 'clientId' => 'myclient', 'clientSecret' => 'mysecret', ]; $provider = new Softonic\OAuth2\Client\Provider\Softonic($options); $config = ['grant_type' => 'client_credentials', 'scope' => 'myscope']; $cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter(); $client = \Softonic\GraphQL\ClientBuilder::buildWithOAuth2Provider( 'https://catalog.swarm.pub.softonic.one/graphql', $provider, $config, $cache ); // Query Example $query = <<<'QUERY' query GetFooBar($idFoo: String, $idBar: String) { foo(id: $idFoo) { id_foo bar (id: $idBar) { id_bar } } } QUERY; $variables = ['idFoo' => 'foo', 'idBar' => 'bar']; $response = $client->query($query, $variables); // Mutation Example $mutation = <<<'MUTATION' mutation ($foo: ObjectInput!){ CreateObjectMutation (object: $foo) { status } } MUTATION; $variables = [ 'foo' => [ 'id_foo' => 'foo', 'bar' => [ 'id_bar' => 'bar' ] ] ]; $response = $client->query($mutation, $variables);
To instantiate a client without OAuth2:
<?php $client = \Softonic\GraphQL\ClientBuilder::build('https://catalog.swarm.pub.softonic.one/graphql'); $query = <<<'QUERY' query GetFooBar($idFoo: String, $idBar: String) { foo(id: $idFoo) { id_foo bar (id: $idBar) { id_bar } } } QUERY; $variables = [ 'idFoo' => 'foo', 'idBar' => 'bar', ]; $response = $client->query($query, $variables);
Testing
softonic/graphql-client
has a PHPUnit test suite and a coding style compliance test suite using PHP CS Fixer.
To run the tests, run the following command from the project folder.
$ docker-compose run test
To run interactively using PsySH:
$ docker-compose run psysh
License
The Apache 2.0 license. Please see LICENSE for more information.