Skip to content

camuthig/php-graphql-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP GraphQL Client

A simple, dependency-free GraphQL client for PHP 7.1+

Install

composer require camuthig/graphql-client

Usage

<?php

use Camuthig\Graphql\Client\Client;

$headers = [
    'X-From' => 'The Test',
];

$client = new Client('https://9jv9z4w3kr.lp.gql.zone/graphql', $headers);

$graphql = <<<'GRAPHQL'
query($input: String!) {
  hello(input: $input)
}
GRAPHQL;

$result = $client->execute($graphql, ['input' => 'everyone']);

var_dump($result->hasErrors()); // false
var_dump($result->getErrors()); // []
var_dump($result->getData());
/*
array(1) {
  ["hello"]=>
  string(15) "Hello everyone! From The Test"
}
*/