camuthig/graphql-client

A GraphQL client for PHP

0.3.0 2017-11-30 05:22 UTC

This package is auto-updated.

Last update: 2024-10-29 05:10:39 UTC


README

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"
}
*/