Laragraph developer guide
Laragraph is a code-first GraphQL server for Laravel: your types, queries and mutations are plain PHP classes, and everything else — validation, authorization, pagination, N+1 batching, subscriptions, caching — uses the Laravel features you already know.
This guide explains every feature, why it exists and how to use it safely. Almost every code sample comes from the example application, whose test suite runs against this repository — so the samples are known to work.
Contents
Start here
- Getting started — install, your first type, query and mutation, how requests flow, and scaffolding a type/queries/mutations (with relations and enum casts) from an Eloquent model
- Types — object, input, enum (including native PHP enums), interface and union types, scalars, and how types are registered
- Queries & mutations — fields, arguments, resolvers, the context, validation (including reusing an existing FormRequest), errors, deprecation
Building a real API
- Authentication & authorization — guards,
authorize(), policies, field-level privacy - Relations & DataLoaders — solving N+1 with
batchRelation()and custom loaders (generate one withlaragraph:make:loader) - Pagination — Relay cursor connections, simple pagination, and Node re-fetching
- Subscriptions — real-time updates over Laravel Broadcasting, or plain HTTP SSE
- The HTTP API — GraphQL over HTTP, file uploads, batching, persisted queries, error codes
- Multiple schemas — separate public and admin APIs
Running it in production
- Security — defaults, limits, and a hardening checklist
- Performance & caching — response cache, discovery cache, Octane
- Observability — events, response extensions, tracing, logging
- Testing — testing your GraphQL API with PHPUnit, shippable test helpers, and a first-party PHPStan rule for unregistered type names
- Deployment — artisan commands, CI schema-diff gate, queues, broadcasting, checklists
Reference
- Configuration reference — every option in
config/laragraph.php - Upgrading — behaviour changes between releases
- Error handling & localization —
GraphQLException, error codes, and translating messages per request
Conventions used in this guide
Laragraph::type('User')is the facadeAyimdomnic\Laragraph\Facades\Laragraph;app('laragraph')->type('User')is equivalent.Typein field definitions is webonyx'sGraphQL\Type\Definition\Type. Laragraph's own base class for object types is also calledType(Ayimdomnic\Laragraph\Support\Type), so type classes usually import webonyx's asGType.- "The example" means the application in
example/.