adeel3330 / graphql-helper-laravel
Lightweight GraphQL helper layer for Laravel with validation, resolver structure, and response formatting.
Package info
github.com/Adeel3330/graphql-helper-laravel
pkg:composer/adeel3330/graphql-helper-laravel
Requires
- php: ^8.3.27 | ^8.4 | ^8.5
- illuminate/support: ^11.0 | ^12.0 | ^13.0
- nuwave/lighthouse: ^6.0
README
A lightweight helper layer for GraphQL in Laravel — focused on validation, clean resolver structure, and consistent responses.
Not a GraphQL engine. Not a replacement for Lighthouse. Just clean, Laravel-style developer experience.
🚀 Why This Package?
Working with GraphQL in Laravel often leads to:
- ❌ No standard validation approach
- ❌ Messy resolver logic
- ❌ Inconsistent response formats
This package solves that by bringing Laravel-like structure to GraphQL.
🔥 Key Feature: @autoResolver
No more manual resolver mapping.
Instead of writing:
@field(resolver: "App\\GraphQL\\Resolvers\\CreateUserResolver@resolve")
Just use:
@autoResolver
✅ Automatically maps:
createUser → App\GraphQL\Resolvers\CreateUserResolver
✨ Features
- ✅
@autoResolverdirective (auto maps GraphQL fields → resolvers) - ✅ Artisan generator for resolvers
- ✅ Laravel-style validation inside resolvers
- ✅ Clean and consistent resolver structure
- ✅ Automatic directive namespace registration
- ✅ Standard response helpers
- ✅ Plug & play with Lighthouse
📦 Installation
composer require yourname/laravel-graphql-helper
⚙️ Requirements
- PHP ^8.3 | ^8.4
- Laravel ^11 | ^12 | ^13
- Lighthouse GraphQL package
⚙️ Usage
🔹 1. Create a Resolver
php artisan make:graphql-resolver CreateUser
🔹 2. Resolver Example
namespace App\GraphQL\Resolvers; use App\Models\User; use Adeel3330\GraphQLHelper\Base\Resolver; class CreateUserResolver extends Resolver { public function rules(): array { return [ 'email' => 'required|email', 'password' => 'required|min:6', ]; } public function handle($args) { return User::create($args); } }
🔹 3. Use in GraphQL Schema
type Mutation { createUser(email: String!, password: String!): User @autoResolver }
🔹 4. Run Mutation
mutation { createUser(email: "test@test.com", password: "123456") { id email } }
🔥 Validation (Automatic)
No need to manually validate — it's handled before execution:
public function rules(): array { return [ 'email' => 'required|email', ]; }
📊 Standard Responses
use Adeel3330\GraphQLHelper\Support\GraphQLResponse; return GraphQLResponse::success($data); return GraphQLResponse::error('Something went wrong');
🔥 Example Response
{
"data": {...},
"message": "Success",
"status": true
}
🧠 How It Works
- Reads GraphQL field name (
createUser) - Converts to class (
CreateUserResolver) - Resolves from:
App\GraphQL\Resolvers
- Executes automatically
⚙️ Configuration (Optional)
// config/graphql-helper.php return [ 'resolver_namespace' => 'App\\GraphQL\\Resolvers', ];
📁 Folder Structure
app/
└── GraphQL/
└── Resolvers/
└── CreateUserResolver.php
🔌 Works With
- Lighthouse GraphQL
- Custom GraphQL implementations
🎯 Philosophy
- Keep it minimal
- Follow Laravel conventions
- Improve developer experience
- Avoid unnecessary abstraction
🤝 Contributing
PRs are welcome! Keep it simple and aligned with Laravel philosophy & Xiaroo Team.
📄 License
MIT