joetjen / graphql
A small, fluent query builder for hand-writing GraphQL query documents in PHP.
0.1.0
2026-07-29 09:41 UTC
Requires
- php: ^8.2
Requires (Dev)
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2026-08-03 13:16:02 UTC
README
A small, fluent query builder for hand-writing GraphQL query documents in PHP — no code generation, no schema introspection, just a lightweight object API for assembling query strings and their variables payload.
Documentation
- QUICKSTART.md — install the package and send your first query in a couple of minutes
- TUTORIAL.md — a guided, step-by-step walkthrough of every concept in the library
- CHEATSHEET.md — terse, skimmable reference of every class and method
- EXAMPLES.md — a gallery of self-contained, copy-pasteable recipes
- CONTRIBUTION.md — how to set up the project, run the tests, and submit changes
- CHANGELOG.md — a history of notable changes to the project
- LICENSE — MIT license
Requirements
- PHP 8.2 or later
Installation
composer require joetjen/graphql
Quick start
use JOetjen\GraphQL\GraphQL; use JOetjen\GraphQL\GraphQLVariable; $document = GraphQL::create()->query('GetUser', function ($query) { $query->select('user', function ($user) { $user->argument('id', new GraphQLVariable('id', 42, GraphQL::INT)); $user->select('name'); $user->select('email'); }); }); echo $document->toString(); // query GetUser($id:Int){user(id:$id){name,email}} print_r($document->variables()); // ['id' => 42]
The two return values map directly onto a standard GraphQL HTTP request body:
$payload = json_encode([ 'query' => $document->toString(), 'variables' => $document->variables(), ]);
See QUICKSTART.md for the full round trip (including sending the request), or TUTORIAL.md for a deeper introduction to aliases, arguments, and variables.
Development
composer install
composer test
See CONTRIBUTION.md for coding standards and how to submit changes.
License
Released under the MIT license.