1+ ![ Note]
2+ This fork was only created because the original library is no longer maintained and to add support for responses that contain both data & errors. See https://github.com/mghoneimy/php-graphql-client/pull/70 https://github.com/mghoneimy/php-graphql-client/pull/71
3+
14# PHP GraphQL Client
5+
26![ Build Status] ( https://github.com/mghoneimy/php-graphql-client/actions/workflows/php.yml/badge.svg )
37[ ![ Total
48Downloads] ( https://poser.pugx.org/gmostafa/php-graphql-client/downloads )] ( https://packagist.org/packages/gmostafa/php-graphql-client )
@@ -29,14 +33,13 @@ There are 3 primary ways to use this package to generate your GraphQL queries:
2933Run the following command to install the package using composer:
3034
3135```
32- $ composer require gmostafa /php-graphql-client
36+ $ composer require brandonbeeler /php-graphql-client
3337```
3438
3539# Object-to-Query-Mapper Extension
3640
3741To avoid the hassle of having to write _ any_ queries and just interact with PHP
38- objects generated from your API schema visit [ PHP GraphQL OQM repository] (
39- https://github.com/mghoneimy/php-graphql-oqm )
42+ objects generated from your API schema visit [ PHP GraphQL OQM repository] ( https://github.com/mghoneimy/php-graphql-oqm )
4043
4144# Query Examples
4245
@@ -84,8 +87,8 @@ The full form shouldn't be used unless the query can't be represented in the
8487shorthand form, which has only one case, when we want to run multiple queries
8588in the same object.
8689
87-
8890## Multiple Queries
91+
8992``` php
9093$gql = (new Query())
9194 ->setSelectionSet(
@@ -116,6 +119,7 @@ Writing multiple queries requires writing the query object in the full form
116119to represent each query as a subfield under the parent query object.
117120
118121## Nested Queries
122+
119123``` php
120124$gql = (new Query('companies'))
121125 ->setSelectionSet(
@@ -190,7 +194,7 @@ $gql = (new Query('companies'))
190194This query is another special case of the arguments query. In this example,
191195we're setting a custom input object "filter" with some values to limit the
192196companies being returned. We're setting the filter "name_starts_with" with
193- value "Face". This query will retrieve only the companies whose names
197+ value "Face". This query will retrieve only the companies whose names
194198start with the phrase "Face".
195199
196200The RawObject class being constructed is used for injecting the string into the
@@ -228,12 +232,13 @@ standards. Its constructor receives 4 arguments:
228232- name: Represents the variable name
229233- type: Represents the variable type according to the GraphQL server schema
230234- isRequired (Optional): Represents if the variable is required or not, it's
231- false by default
235+ false by default
232236- defaultValue (Optional): Represents the default value to be assigned to the
233- variable. The default value will only be considered
234- if the isRequired argument is set to false.
237+ variable. The default value will only be considered
238+ if the isRequired argument is set to false.
235239
236240## Using an alias
241+
237242``` php
238243$gql = (new Query())
239244 ->setSelectionSet(
@@ -366,7 +371,7 @@ companies starting with a name prefix and returns the company with the
366371# Constructing The Client
367372
368373A Client object can easily be instantiated by providing the GraphQL endpoint
369- URL.
374+ URL.
370375
371376The Client constructor also receives an optional "authorizationHeaders"
372377array, which can be used to add authorization headers to all requests being sent
@@ -381,7 +386,6 @@ $client = new Client(
381386);
382387```
383388
384-
385389The Client constructor also receives an optional "httpOptions" array, which
386390** overrides** the "authorizationHeaders" and can be used to add custom
387391[ Guzzle HTTP Client request options] ( https://guzzle.readthedocs.io/en/latest/request-options.html ) .
@@ -392,7 +396,7 @@ Example:
392396$client = new Client(
393397 'http://api.graphql.com',
394398 [],
395- [
399+ [
396400 'connect_timeout' => 5,
397401 'timeout' => 5,
398402 'headers' => [
@@ -410,7 +414,6 @@ $client = new Client(
410414);
411415```
412416
413-
414417It is possible to use your own preconfigured HTTP client that implements the [ PSR-18 interface] ( https://www.php-fig.org/psr/psr-18/ ) .
415418
416419Example:
@@ -435,6 +438,7 @@ structure:
435438$results = $client->runQuery($gql);
436439$results->getData()->companies[0]->branches;
437440```
441+
438442Or getting results in array structure:
439443
440444``` php
0 commit comments