darthsoup / php-graphql-client
GraphQL client and query builder.
Requires
- php: ^8.3
- ext-json: *
- guzzlehttp/guzzle: ^7.8 || ^8.0
- psr/http-client: ^1.0
- psr/http-message: ^1.1 || ^2.0
Requires (Dev)
- aws/aws-sdk-php: ^3.379
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
- symfony/var-dumper: ^7.4
Suggests
- aws/aws-sdk-php: Move this package to require section to use AWS IAM authorization
- gmostafa/php-graphql-oqm: To have object-to-query mapping support
Provides
None
Conflicts
- guzzlehttp/psr7: < 1.7.0
Replaces
None
README
A PHP 8.3+ GraphQL client with a fluent query builder. Interact with any GraphQL API without writing raw query strings — compose type-safe queries and mutations in pure PHP, then run them against any GraphQL endpoint.
Requirements
- PHP 8.3 or higher
ext-json
Installation
composer require darthsoup/php-graphql-client
Quick start
require __DIR__ . '/vendor/autoload.php'; use GraphQL\Client; use GraphQL\Query; $client = new Client('https://example.com/graphql'); $query = (new Query('companies'))->setSelectionSet(['name', 'serialNumber']); $data = $client->runQuery($query)->getData();
The client uses Guzzle by default. You can also pass a PSR-18 HTTP client. GraphQL
errors throw GraphQL\Exception\QueryError and expose the returned errors and
partial data.
Documentation
- Build queries: fields, arguments, variables, aliases, fragments, and directives
- Query builder: fluent and dynamic query construction
- Client and results: configuration, execution, variables, and raw queries
- Pagination: lazy iteration across Lighthouse and offset pages
- Mutations: constructing and running mutations
- Error reporting: exceptions and safe reporting fields
Examples
The examples/ directory contains runnable PHP examples:
Changelog
See CHANGELOG.md for release notes and compatibility changes.
Contributing
Run composer install, composer test, composer phpstan, and
composer style:check before opening a pull request. Integration tests use an
external API: composer test:integration.