graphql-php implements the GraphQL spec in PHP for building query APIs. It wraps your data and business logic without dictating storage or framework choices.
Overview
graphql-php is a PHP library that implements the GraphQL specification, based on the reference JavaScript implementation. It targets developers who expose HTTP APIs consumed by web and mobile clients and can serve as an option alongside REST and SOAP style APIs.
The library helps you define a type system, validate and introspect that schema, and parse, validate, and execute incoming GraphQL queries against it. It reports validation and execution errors and can parse schema definition language, batch backend requests, and work with async PHP platforms through promises. Standard HTTP server integration is among its capabilities.
It is a thin layer over existing application code: you keep your own data access and business rules. Complementary community tools can add framework integrations and Relay support. It complies with the October 2021 GraphQL specification, with work in progress toward a newer specification revision.
Install through Composer and use example projects in the distribution documentation as starting points. Public API surfaces marked in PHPDoc follow semantic versioning rules within major releases.
Key features
- GraphQL type system definition
- Schema validation and introspection
- Query parsing and execution
- Structured error reporting
- Schema definition language parsing
- Backend request batching tools
- Async promises integration
- Standard HTTP server support
Use cases
- Building GraphQL APIs in PHP
- Exposing typed queries over HTTP
- Replacing ad hoc REST endpoints
- Serving GraphiQL-compatible schemas
- Integrating GraphQL into existing apps