rebing/graphql-laravel
Code-first GraphQL integration for Laravel based on webonyx/graphql-php. Define schemas, types, queries and mutations in PHP. Supports multiple schemas, per-schema middleware, resolver middleware, and n+1 prevention via dataloaders or SelectFields eager loading.
/users/{id} endpoint to a user(id: ID!): User query with nested fields (e.g., user { id name posts { title } }).admin, public, partner) with schema-specific middleware (e.g., rate limiting, auth).partner schema could expose partnerOrders with custom validation for B2B clients.User::with('posts')->find($id) with a UserType using SelectFields to auto-optimize select() and with() calls.email: 'required|email'), reducing duplication with REST controllers.@private) enforce field-level access control (e.g., hide user.salary for non-admins).make:graphql:query) accelerate onboarding for backend teams unfamiliar with GraphQL.| Use Case | How This Package Helps |
|---|---|
| Headless CMS | Expose content models (e.g., Article, Category) with nested queries (e.g., article { title author { name } }). |
| Mobile Apps | Reduce payload size with client-controlled field selection (e.g., fetch only user.id and user.name for login). |
| Multi-Tenant SaaS | Use schema isolation to expose tenant-specific APIs (e.g., tenant1.graphql, tenant2.graphql). |
| Legacy System Integration | Wrap legacy REST APIs as GraphQL "wrappers" (e.g., a legacyUser(id: ID!): User query that proxies to a SOAP service). |
| Internal Tools | Build admin dashboards with complex queries (e.g., reports { metrics { users active } }) without bloating REST endpoints. |
✅ You’re using Laravel 12/13 and want a native PHP-based GraphQL solution (no .graphql files).
✅ Your team prefers code-first schema definitions (aligns with Laravel’s Eloquent/Service Container).
✅ You need multiple schemas with schema-specific middleware (e.g., auth, rate limiting).
✅ Performance is critical, and you want Dataloaders or SelectFields to optimize Eloquent queries.
✅ You want deep Laravel integration (e.g., validation, auth, testing helpers).
✅ Subscriptions are not required (use Lighthouse or Laravel Echo for real-time features).
❌ You need GraphQL subscriptions (this package does not support them; use Lighthouse instead).
❌ Your team prefers schema-first GraphQL (e.g., .graphql files) over PHP classes.
❌ You’re using Laravel <12 (requires PHP 8.2+).
❌ You need a managed GraphQL service (consider Hasura or AWS AppSync).
❌ You’re building a public API with strict query depth/complexity limits (this package requires manual configuration).
"We’re modernizing our API to give our clients and internal teams faster, more flexible data access—without overhauling our backend. This Laravel GraphQL package lets us:
- Reduce API complexity: Clients fetch only the data they need (e.g., a mobile app requests
user.idanduser.nameinstead of full user objects).- Accelerate development: Backend teams use familiar Laravel tools (Eloquent, validation) to define GraphQL schemas in PHP.
- Support multi-tenant SaaS: Isolate APIs for partners/admins with schema-specific permissions.
- Cut costs: Avoid over-fetching data (e.g., no more bloated REST responses with unused fields). It’s a low-risk upgrade—we can phase it in alongside REST APIs and see 20–30% faster payloads in testing."
Ask:
"This package gives us a production-ready GraphQL layer for Laravel with key advantages:
- Performance: Dataloaders and SelectFields optimize Eloquent queries automatically—no manual
with()or batching code.- Security: Field-level privacy, validation, and schema isolation reduce attack surface.
- Developer Velocity: Artisan generators (e.g.,
make:graphql:query) and Laravel validation integrate seamlessly with existing workflows.- Future-Proof: Supports multiple schemas, custom middleware, and observability (OpenTelemetry).
Compared to alternatives:
- Lighthouse: Better for subscriptions but heavier.
- REST: Can’t compete with client-driven data fetching.
- Hasura: Overkill for Laravel; this is native and lightweight."
Ask:
public) or multiple schemas (e.g., admin, partner)?""This package lets you build GraphQL APIs in Laravel—without learning a new language. Here’s how it works:
- Define schemas in PHP: Use
make:graphql:type,make:graphql:query, etc., to scaffold classes.// Example: app/GraphQL/Types/UserType.php class UserType extends GraphQLType { public function fields() { return [ 'id' => Type::nonNull(Type::id()), 'name' => Type::string(), 'posts' => [ 'type' => Type::listOf(PostType::class), 'resolve' => fn($user) => $user->posts, ], ]; } }- Leverage Laravel features:
- Validation: Add rules to query args (e.g.,
email: 'required|email').- Auth: Use middleware to restrict fields (e.g., hide
salaryfor non-admins).- Testing: Built-in helpers like
httpGraphql()for PHPUnit.- Optimize performance:
- SelectFields: Auto-generates
select()andwith()for Eloquent.- Dataloaders: Batch database calls to avoid N+1.
No
.graphqlfiles—just PHP classes you already know. Start with a single query and expand as needed."
Ask:
How can I help you explore Laravel packages today?