evilfreelancer/simplegqlient

The simplest GraphQL client written in PHP

1.0.0 2022-11-02 06:00 UTC

This package is auto-updated.

Last update: 2024-11-19 12:29:12 UTC


README

The simplest GraphQL client written in PHP. Inspired by the Lighthouse PHP project, in particular by embedded client that can be used for testing of Laravel-based GraphQL implementation of server.

composer require evilfreelancer/simplegqlient

Small example

require_once __DIR__ . '/../vendor/autoload.php';

$githubToken = 'xxx';

$client = new \SimpleGQLient\Client('https://api.github.com/graphql', [
    'Authorization' => 'Bearer ' . $githubToken,
    'Accept'        => 'application/vnd.github.hawkgirl-preview+json,',
]);

$response = $client->graphQL(/** @lang GraphQL */ '
{
  user(login: "evilfreelancer") {
    repositories(ownerAffiliations: OWNER, isFork: false, first: 100) {
      nodes {
        name
        languages(first: 10, orderBy: { field: SIZE, direction: DESC }) {
          edges {
            size
            node {
              color
              name
            }
          }
        }
      }
    }
  }
}
');

// \Psr\Http\Message\ResponseInterface in response
$output = $response->getBody()->getContents();
var_dump($output);

Roadmap

  • Basic client
  • Multipart support