webonyx/graphql-php
A PHP implementation of the GraphQL specification, based on the JavaScript reference implementation. It's fully compliant with the October 2021 spec, with September 2025 compliance in progress, and supports schema building, query execution, and validation.
Printer::stripIgnoredCharacters() (v15.38.0) produces a canonical, minified document by removing characters that don't change meaning. This directly supports persisted-query keying, query-cache normalization, and on-the-wire payload reduction — the infrastructure behind CDN cache hit rates and APQ (automatic persisted queries) implementations.["x"], {"query":"{ a }","0":"x"}) raise a RequestError rather than a TypeError. Product impact: batched requests now fail as client errors with spec-shaped GraphQL error responses instead of surfacing as generic server faults. This matters if we expose batching (common with Apollo links / mobile clients) — it keeps error classification, HTTP status mapping, and client retry logic correct, and prevents malformed client payloads from polluting 5xx error budgets and alerting.SchemaPrinter). Correct RequestError types also mean frontend clients receive actionable, structured errors instead of opaque failures.stripIgnoredCharacters()).RequestError typing for malformed/batched requests) out of the box.graphql-php-laravel).stripIgnoredCharacters() is the natural primitive for stable document hashing and cache keys.graphql-php-subscriptions or WebSockets).*"This is the de facto standard for PHP GraphQL, used by teams at companies like Shopify, GitLab, and Segment. By adopting
graphql-php, we:
- Future-proof our APIs: Align with the GraphQL ecosystem (Apollo, Relay) to reduce frontend-backend friction.
- Cut development time: Leverage 4.7K+ stars, MIT license, and Laravel integration to ship faster.
- Improve scalability: Persisted queries, query normalization (
stripIgnoredCharacters()), and query planning optimize performance for high-traffic APIs and improve cache hit rates.- Reduce risk: Recent releases actively harden the parser (invalid UTF-8 rejection) and correct error typing for batched/malformed requests (v15.38.1) — a sign of a maintained, security-conscious dependency.
- Enable composable architectures: Support microservices and federation for modular growth. Investment: Low (open-source, maintained by a solo dev with sponsorships). ROI: Faster feature delivery, happier devs, and future-proof tech."*
*"This is the most stable, performant PHP GraphQL library, with:
- Full spec compliance (October 2021, partial 2025).
- Laravel-friendly: Works with Eloquent, middleware, and caching.
- Developer ergonomics:
- Introspection for tooling (GraphiQL, Postman).
- Validation to catch schema errors early.
- Persisted queries for security/performance.
Printer::stripIgnoredCharacters()(v15.38.0) for canonical, minified documents — use it to derive stable persisted-query hashes and shrink payloads.- Invalid UTF-8 rejection (v15.38.0) at the document boundary.
- Correct request error typing (v15.38.1): malformed scalar batch entries now raise
RequestErrorinstead ofTypeError, so batched clients get proper GraphQL error responses rather than 5xx-class faults.- Optimized for scale: Query planning, reduced recursion, native PHP types, and normalized documents. Trade-offs:
- No built-in subscriptions (add
graphql-php-subscriptions).- PHP 7.4+ required. Next steps:
- Spike: Benchmark against REST/gRPC for a sample query; verify
stripIgnoredCharacters()output is stable across our schema/printers before keying a cache on it.- Integrate: Use
graphql-php-laravelfor Laravel.- Adopt incrementally: Start with a single service or public API.
- Upgrade: v15.32.3 → v15.38.1 is a low-risk patch/minor line; no breaking changes. Watch one behavior shift: if we currently catch
TypeErroraround batched request coercion, update those handlers to catchRequestError(and confirm error formatters/HTTP mapping emit 4xx for batch coercion failures)."*
*"This backend uses the same GraphQL spec as Apollo Client/Relay, so:
- No API versioning headaches: Frontend defines the schema; backend adheres to it.
- Efficient data fetching: Query exactly what you need (no over-fetching), with persisted queries shrinking request payloads.
- Better batch error handling: Malformed batched entries now return structured GraphQL errors instead of opaque server errors — your
BatchLinkerror handling will behave predictably.- Tooling support: Works with GraphiQL, Apollo Studio, and VS Code GraphQL extensions. Ask backend:
- Can we get a GraphQL Playground endpoint for exploration?
- Will you support persisted queries to reduce payload size?
- Is request batching enabled, and are batch errors mapped to 4xx?"*
How can I help you explore Laravel packages today?