graphql-php

A mature, spec-compliant PHP implementation of GraphQL for building schema-driven API servers.

Library
Composer
vv15.37.2
4,716stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
95/100Excellent
Development Activity96
Maintenance96
Community88
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
83/100Excellent
Architecture90
Code Quality92
Innovation80
Learning Curve68

graphql-php is a PHP port of the reference GraphQL implementation, fully compliant with the October 2021 GraphQL specification. It provides everything needed to define a type system, parse and validate queries, and execute them against your data, turning PHP into a first-class GraphQL backend.

Widely adopted as the foundation for GraphQL layers in PHP frameworks and CMSs, it offers a complete schema definition API, a query executor with support for async resolving (via ReactPHP or Amp), a standard PSR-7 server, and rich error handling and validation tooling.

What You Get

  • A complete type-system API for defining object, interface, union, enum, scalar, and input types
  • A spec-compliant lexer, parser, and printer for GraphQL query and schema-definition-language documents
  • A query executor with field resolvers, deferred/async resolving, and a promise adapter for ReactPHP and Amp
  • Built-in validation rules and structured error handling with configurable error formatting and masking
  • A standard PSR-7 GraphQL server plus utilities for schema building, printing, and introspection

Common Use Cases

  • Building a GraphQL API server on top of an existing PHP application or database
  • Adding a GraphQL layer to a CMS or framework (used under the hood by many PHP GraphQL integrations)
  • Programmatically constructing and validating schemas from PHP type definitions or SDL
  • Executing and validating GraphQL queries with custom resolvers and async data loading

Under The Hood

Architecture - The library is organized around the GraphQL execution lifecycle: the Language namespace holds the lexer, parser, AST, and printer; Type defines the schema/type system; Validator applies the spec’s validation rules; and Executor resolves operations against resolvers, with a promise adapter abstraction enabling synchronous or async (ReactPHP/Amp) execution. The Server namespace wraps this into a PSR-7 standard server, and GraphQL.php exposes the top-level executeQuery entry point.

Tech Stack - Pure PHP supporting ^7.4 || ^8, requiring only ext-json and ext-mbstring at runtime. Optional integrations (psr/http-message, react/promise, amphp/amp) are pulled in as needed for the server and async resolving. Dev tooling is extensive: PHPStan at strict levels, php-cs-fixer, Rector, PHPUnit, and phpbench benchmarks.

Code Quality - This is a large, battle-tested codebase (over 150 contributors, 2,800+ KB of PHP) held to a high bar: strict PHPStan static analysis with strict-rules, enforced code style, a comprehensive PHPUnit suite, and benchmark coverage. It closely tracks graphql-js behavior and the GraphQL specification.

API Design - The public API deliberately mirrors the JavaScript reference implementation, so schema construction, resolver signatures, and the executeQuery flow are familiar to anyone who has used graphql-js. Extensive hosted documentation, a clear namespace layout, and both programmatic and SDL-based schema construction keep the ergonomics strong, though the breadth of the GraphQL type system gives it a moderate learning curve.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search